Skip to content

Commit 3e750d1

Browse files
authored
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 ```
1 parent 6797a08 commit 3e750d1

File tree

11 files changed

+83
-110
lines changed

11 files changed

+83
-110
lines changed

.devcontainer/Dockerfile

Lines changed: 0 additions & 31 deletions
This file was deleted.

.devcontainer/base.Dockerfile

Lines changed: 0 additions & 57 deletions
This file was deleted.

.devcontainer/devcontainer-lock.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"features": {
3+
"ghcr.io/devcontainers/features/git:1": {
4+
"version": "1.3.4",
5+
"resolved": "ghcr.io/devcontainers/features/git@sha256:f24645e64ad39a596131a50ec96f7d5cf7a2a87544cce772dd4b7182a233e98a",
6+
"integrity": "sha256:f24645e64ad39a596131a50ec96f7d5cf7a2a87544cce772dd4b7182a233e98a"
7+
},
8+
"ghcr.io/devcontainers/features/github-cli:1": {
9+
"version": "1.0.14",
10+
"resolved": "ghcr.io/devcontainers/features/github-cli@sha256:ca677566507c4118e4368cd76a4800807e911e5e350cc3525fb67ebc9132dfa1",
11+
"integrity": "sha256:ca677566507c4118e4368cd76a4800807e911e5e350cc3525fb67ebc9132dfa1"
12+
},
13+
"ghcr.io/devcontainers/features/rust:1": {
14+
"version": "1.5.0",
15+
"resolved": "ghcr.io/devcontainers/features/rust@sha256:0c55e65f2e3df736e478f26ee4d5ed41bae6b54dac1318c443e31444c8ed283c",
16+
"integrity": "sha256:0c55e65f2e3df736e478f26ee4d5ed41bae6b54dac1318c443e31444c8ed283c"
17+
}
18+
}
19+
}

.devcontainer/devcontainer.json

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,19 @@
22
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/javascript-node
33
{
44
"name": "Next.js Dev Container",
5-
"build": {
6-
"dockerfile": "Dockerfile",
7-
// Update 'VARIANT' to pick a Node version: 18, 16, 14.
8-
// Append -bullseye or -buster to pin to an OS version.
9-
// Use -bullseye variants on local arm64/Apple Silicon.
10-
"args": {
11-
"VARIANT": "20-bullseye"
12-
}
13-
},
14-
// Configure tool-specific properties.
5+
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bookworm",
156
"customizations": {
16-
// Configure properties specific to VS Code.
177
"vscode": {
18-
// Add the IDs of extensions you want installed when the container is created.
198
"extensions": ["dbaeumer.vscode-eslint"]
209
}
2110
},
22-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
23-
// "forwardPorts": [],
24-
// Use 'postCreateCommand' to run commands after the container is created.
25-
// "postCreateCommand": "yarn install",
26-
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
2711
"remoteUser": "node",
2812
"features": {
29-
// For some reason "git" or "rust" doesn't work
30-
"ghcr.io/devcontainers/features/git:1": "os-provided",
31-
"ghcr.io/devcontainers/features/rust:1": "latest"
32-
// Github latest can't be installed due to GPG issues: https://github.com/cli/cli/discussions/6222
33-
// "github-cli": "latest",
13+
"ghcr.io/devcontainers/features/git:1": {},
14+
"ghcr.io/devcontainers/features/github-cli:1": {},
15+
"./rust": {},
16+
"./headless-browser": {},
17+
"./node-extras": {}
3418
},
3519
"remoteEnv": {
3620
"DISPLAY": ":0"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": "playwright",
3+
"name": "next.js-playwright",
4+
"version": "0.0.0",
5+
"dependsOn": {}
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
export DEBIAN_FRONTEND=noninteractive
4+
5+
apt-get update
6+
# These are required to run playwright properly
7+
apt-get -y install --no-install-recommends \
8+
gconf-service libxext6 libxfixes3 libxi6 libxrandr2 \
9+
libxrender1 libcairo2 libcups2 libdbus-1-3 libexpat1 \
10+
libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 \
11+
libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 \
12+
libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 \
13+
libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 \
14+
libatk1.0-0 libc6 libdrm-dev libgbm-dev ca-certificates fonts-liberation lsb-release xdg-utils wget \
15+
16+
# Chromium is needed for Turbopack benchmarks
17+
apt-get -y install --no-install-recommends chromium
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": "node-extras",
3+
"name": "next.js-node-extras",
4+
"version": "0.0.0",
5+
"dependsOn": {}
6+
}

.devcontainer/node-extras/install.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
corepack enable pnpm
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"id": "rust",
3+
"name": "next.js-rust",
4+
"version": "0.0.0",
5+
"dependsOn": {
6+
"ghcr.io/devcontainers/features/rust:1": {
7+
// this should match the `rust-toolchain.toml`
8+
"version": "nightly-2025-06-04",
9+
"profile": "minimal",
10+
"components": "rustfmt,clippy,rust-analyzer"
11+
}
12+
}
13+
}

.devcontainer/rust/install.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
export DEBIAN_FRONTEND=noninteractive
4+
5+
curl -L --proto '=https' --tlsv1.2 -sSf \
6+
https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh \
7+
| bash
8+
cargo binstall cargo-nextest --secure
9+
10+
apt-get update
11+
apt-get -y install --no-install-recommends libfontconfig1-dev

0 commit comments

Comments
 (0)