Skip to content

Commit ee97481

Browse files
Add support for next.js development in docker (vercel#43138)
Co-authored-by: Tim Neutkens <[email protected]>
1 parent 9fe5317 commit ee97481

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# [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
2+
ARG VARIANT=16-bullseye
3+
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
4+
5+
# [Optional] Uncomment this section to install additional OS packages.
6+
# These are required to run playwright properly
7+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
8+
&& apt-get -y install --no-install-recommends \
9+
gconf-service libxext6 libxfixes3 libxi6 libxrandr2 \
10+
libxrender1 libcairo2 libcups2 libdbus-1-3 libexpat1 \
11+
libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 \
12+
libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 \
13+
libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 \
14+
libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 \
15+
libatk1.0-0 libc6 libdrm-dev libgbm-dev ca-certificates fonts-liberation lsb-release xdg-utils wget
16+
17+
# [Optional] Uncomment if you want to install an additional version of node using nvm
18+
# ARG EXTRA_NODE_VERSION=10
19+
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
20+
21+
# [Optional] Uncomment if you want to install more global node modules
22+
# RUN su node -c "npm install -g <your-package-list-here>"
23+
24+
# Enable pnpm
25+
RUN corepack enable pnpm

.devcontainer/base.Dockerfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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
2+
ARG VARIANT=16-bullseye
3+
FROM node:${VARIANT}
4+
5+
# [Option] Install zsh
6+
ARG INSTALL_ZSH="true"
7+
# [Option] Upgrade OS packages to their latest versions
8+
ARG UPGRADE_PACKAGES="true"
9+
10+
# Install needed packages, yarn, nvm and setup non-root user. Use a separate RUN statement to add your own dependencies.
11+
ARG USERNAME=node
12+
ARG USER_UID=1000
13+
ARG USER_GID=$USER_UID
14+
ARG NPM_GLOBAL=/usr/local/share/npm-global
15+
ENV NVM_DIR=/usr/local/share/nvm
16+
ENV NVM_SYMLINK_CURRENT=true \
17+
PATH=${NPM_GLOBAL}/bin:${NVM_DIR}/current/bin:${PATH}
18+
COPY library-scripts/*.sh library-scripts/*.env /tmp/library-scripts/
19+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
20+
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
21+
&& apt-get purge -y imagemagick imagemagick-6-common \
22+
# Install common packages, non-root user, update yarn and install nvm
23+
&& bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
24+
# Install yarn, nvm
25+
&& rm -rf /opt/yarn-* /usr/local/bin/yarn /usr/local/bin/yarnpkg \
26+
&& bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "none" "${USERNAME}" \
27+
# Configure global npm install location, use group to adapt to UID/GID changes
28+
&& if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \
29+
&& usermod -a -G npm ${USERNAME} \
30+
&& umask 0002 \
31+
&& mkdir -p ${NPM_GLOBAL} \
32+
&& touch /usr/local/etc/npmrc \
33+
&& chown ${USERNAME}:npm ${NPM_GLOBAL} /usr/local/etc/npmrc \
34+
&& chmod g+s ${NPM_GLOBAL} \
35+
&& npm config -g set prefix ${NPM_GLOBAL} \
36+
&& sudo -u ${USERNAME} npm config -g set prefix ${NPM_GLOBAL} \
37+
# Install eslint
38+
&& su ${USERNAME} -c "umask 0002 && npm install -g eslint" \
39+
&& npm cache clean --force > /dev/null 2>&1 \
40+
# Install python-is-python3 on bullseye to prevent node-gyp regressions
41+
&& . /etc/os-release \
42+
&& if [ "${VERSION_CODENAME}" = "bullseye" ]; then apt-get -y install --no-install-recommends python-is-python3; fi \
43+
# Clean up
44+
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /root/.gnupg /tmp/library-scripts
45+
46+
# [Optional] Uncomment this section to install additional OS packages.
47+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
48+
# && apt-get -y install --no-install-recommends <your-package-list-here>
49+
50+
# [Optional] Uncomment if you want to install an additional version of node using nvm
51+
# ARG EXTRA_NODE_VERSION=10
52+
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
53+
54+
# [Optional] Uncomment if you want to install more global node modules
55+
# RUN su node -c "npm install -g <your-package-list-here>""

.devcontainer/devcontainer.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/javascript-node
3+
{
4+
"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": "16-bullseye"
12+
}
13+
},
14+
// Configure tool-specific properties.
15+
"customizations": {
16+
// Configure properties specific to VS Code.
17+
"vscode": {
18+
// Add the IDs of extensions you want installed when the container is created.
19+
"extensions": ["dbaeumer.vscode-eslint"]
20+
}
21+
},
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.
27+
"remoteUser": "node",
28+
"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",
34+
},
35+
// This is needed for forwarding X11: https://github.com/microsoft/vscode-remote-release/issues/3841
36+
"runArgs": ["--net=host"],
37+
"remoteEnv": {
38+
"DISPLAY": ":0"
39+
}
40+
}

0 commit comments

Comments
 (0)