Unverified Commit 3e750d10 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

Devcontainer: Replace Dockerfile with prebuilt image+features (#82450)

Devcontainers support custom `Dockerfile`s, but it seems like it's more recommended to use a base image with "features" on top: https://containers.dev/implementors/features/

Features get applied after the `Dockerfile`, so e.g. if we're installing `rust` with a feature, then we can't install things that depend on `rust` (e.g. `cargo-nextest`: https://nexte.st/) in the `Dockerfile`. So you're forced to do things with features instead, which can specify dependencies and ordering requirements.

I removed a bunch of comments that were left over from the template. People wishing to update this file should refer to the https://aka.ms/devcontainer.json link at the top of the file.

Also added a lockfile for the features, generated with:

```
devcontainer upgrade --workspace-folder=.
```

**Note:** The `base.Dockerfile` here was entirely unused.


### Testing

```
podman stop --all && podman rm --all  # replace podman with docker if you're using docker
devcontainer up --workspace-folder=.
devcontainer exec --workspace-folder=. zsh
```
parent 6797a087
# syntax=docker.io/docker/dockerfile:1
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
ARG VARIANT=20-bullseye
FROM node:${VARIANT}
# [Option] Install zsh
ARG INSTALL_ZSH="true"
# [Option] Upgrade OS packages to their latest versions
ARG UPGRADE_PACKAGES="true"
# Install needed packages, yarn, nvm and setup non-root user. Use a separate RUN statement to add your own dependencies.
ARG USERNAME=node
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG NPM_GLOBAL=/usr/local/share/npm-global
ENV NVM_DIR=/usr/local/share/nvm
ENV NVM_SYMLINK_CURRENT=true \
PATH=${NPM_GLOBAL}/bin:${NVM_DIR}/current/bin:${PATH}
COPY library-scripts/*.sh library-scripts/*.env /tmp/library-scripts/
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
&& apt-get purge -y imagemagick imagemagick-6-common \
# Install common packages, non-root user, update yarn and install nvm
&& bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
# Install yarn, nvm
&& rm -rf /opt/yarn-* /usr/local/bin/yarn /usr/local/bin/yarnpkg \
&& bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "none" "${USERNAME}" \
# Configure global npm install location, use group to adapt to UID/GID changes
&& if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \
&& usermod -a -G npm ${USERNAME} \
&& umask 0002 \
&& mkdir -p ${NPM_GLOBAL} \
&& touch /usr/local/etc/npmrc \
&& chown ${USERNAME}:npm ${NPM_GLOBAL} /usr/local/etc/npmrc \
&& chmod g+s ${NPM_GLOBAL} \
&& npm config -g set prefix ${NPM_GLOBAL} \
&& sudo -u ${USERNAME} npm config -g set prefix ${NPM_GLOBAL} \
# Install eslint
&& su ${USERNAME} -c "umask 0002 && npm install -g eslint" \
&& npm cache clean --force > /dev/null 2>&1 \
# Install python-is-python3 on bullseye to prevent node-gyp regressions
&& . /etc/os-release \
&& if [ "${VERSION_CODENAME}" = "bullseye" ]; then apt-get -y install --no-install-recommends python-is-python3; fi \
# Clean up
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /root/.gnupg /tmp/library-scripts
# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>""
\ No newline at end of file
{
"features": {
"ghcr.io/devcontainers/features/git:1": {
"version": "1.3.4",
"resolved": "ghcr.io/devcontainers/features/git@sha256:f24645e64ad39a596131a50ec96f7d5cf7a2a87544cce772dd4b7182a233e98a",
"integrity": "sha256:f24645e64ad39a596131a50ec96f7d5cf7a2a87544cce772dd4b7182a233e98a"
},
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "1.0.14",
"resolved": "ghcr.io/devcontainers/features/github-cli@sha256:ca677566507c4118e4368cd76a4800807e911e5e350cc3525fb67ebc9132dfa1",
"integrity": "sha256:ca677566507c4118e4368cd76a4800807e911e5e350cc3525fb67ebc9132dfa1"
},
"ghcr.io/devcontainers/features/rust:1": {
"version": "1.5.0",
"resolved": "ghcr.io/devcontainers/features/rust@sha256:0c55e65f2e3df736e478f26ee4d5ed41bae6b54dac1318c443e31444c8ed283c",
"integrity": "sha256:0c55e65f2e3df736e478f26ee4d5ed41bae6b54dac1318c443e31444c8ed283c"
}
}
}
...@@ -2,35 +2,19 @@ ...@@ -2,35 +2,19 @@
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/javascript-node // https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/javascript-node
{ {
"name": "Next.js Dev Container", "name": "Next.js Dev Container",
"build": { "image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bookworm",
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 18, 16, 14.
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon.
"args": {
"VARIANT": "20-bullseye"
}
},
// Configure tool-specific properties.
"customizations": { "customizations": {
// Configure properties specific to VS Code.
"vscode": { "vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": ["dbaeumer.vscode-eslint"] "extensions": ["dbaeumer.vscode-eslint"]
} }
}, },
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node", "remoteUser": "node",
"features": { "features": {
// For some reason "git" or "rust" doesn't work "ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/git:1": "os-provided", "ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers/features/rust:1": "latest" "./rust": {},
// Github latest can't be installed due to GPG issues: https://github.com/cli/cli/discussions/6222 "./headless-browser": {},
// "github-cli": "latest", "./node-extras": {}
}, },
"remoteEnv": { "remoteEnv": {
"DISPLAY": ":0" "DISPLAY": ":0"
......
{
"id": "playwright",
"name": "next.js-playwright",
"version": "0.0.0",
"dependsOn": {}
}
# syntax=docker.io/docker/dockerfile:1 #!/bin/bash
set -euxo pipefail
export DEBIAN_FRONTEND=noninteractive
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster apt-get update
ARG VARIANT=20-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
# [Optional] Uncomment this section to install additional OS packages.
# These are required to run playwright properly # These are required to run playwright properly
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ apt-get -y install --no-install-recommends \
&& apt-get -y install --no-install-recommends \
gconf-service libxext6 libxfixes3 libxi6 libxrandr2 \ gconf-service libxext6 libxfixes3 libxi6 libxrandr2 \
libxrender1 libcairo2 libcups2 libdbus-1-3 libexpat1 \ libxrender1 libcairo2 libcups2 libdbus-1-3 libexpat1 \
libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 \ libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 \
...@@ -15,17 +12,6 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ ...@@ -15,17 +12,6 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 \ libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 \
libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 \ libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 \
libatk1.0-0 libc6 libdrm-dev libgbm-dev ca-certificates fonts-liberation lsb-release xdg-utils wget \ libatk1.0-0 libc6 libdrm-dev libgbm-dev ca-certificates fonts-liberation lsb-release xdg-utils wget \
# Chromium for running Turbopack benchmarks
chromium \
# Used for plotters graph visualizations in turbopack benchmarks
libfontconfig1-dev
# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>"
# Enable pnpm # Chromium is needed for Turbopack benchmarks
RUN corepack enable pnpm apt-get -y install --no-install-recommends chromium
\ No newline at end of file
{
"id": "node-extras",
"name": "next.js-node-extras",
"version": "0.0.0",
"dependsOn": {}
}
#!/bin/bash
set -euxo pipefail
corepack enable pnpm
{
"id": "rust",
"name": "next.js-rust",
"version": "0.0.0",
"dependsOn": {
"ghcr.io/devcontainers/features/rust:1": {
// this should match the `rust-toolchain.toml`
"version": "nightly-2025-06-04",
"profile": "minimal",
"components": "rustfmt,clippy,rust-analyzer"
}
}
}
#!/bin/bash
set -euxo pipefail
export DEBIAN_FRONTEND=noninteractive
curl -L --proto '=https' --tlsv1.2 -sSf \
https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh \
| bash
cargo binstall cargo-nextest --secure
apt-get update
apt-get -y install --no-install-recommends libfontconfig1-dev
# if you update this, also update `.devcontainer/rust/devcontainer-feature.json`
[toolchain] [toolchain]
channel = "nightly-2025-06-04" channel = "nightly-2025-06-04"
components = ["rustfmt", "clippy", "rust-analyzer"] components = ["rustfmt", "clippy", "rust-analyzer"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment