Skip to content

Commit

Permalink
chore: update devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Dec 7, 2024
1 parent 57d4097 commit 1a6b585
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 78 deletions.
69 changes: 14 additions & 55 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,90 +1,49 @@
# Based of https://github.com/microsoft/vscode-dev-containers/blob/main/containers/javascript-node/.devcontainer/base.Dockerfile
# Based of https://github.com/devcontainers/images/blob/main/src/javascript-node/.devcontainer/Dockerfile

# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster
ARG VARIANT=20-bullseye
ARG VARIANT=22-bookworm
FROM node:${VARIANT}

ENV DEBIAN_FRONTEND=noninteractive
ARG USERNAME=node
ARG NPM_GLOBAL=/usr/local/share/npm-global

# Copy library scripts to execute
ADD https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/containers/javascript-node/.devcontainer/library-scripts/common-debian.sh /tmp/library-scripts/
ADD https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/containers/javascript-node/.devcontainer/library-scripts/node-debian.sh /tmp/library-scripts/
ADD https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/containers/javascript-node/.devcontainer/library-scripts/meta.env /tmp/library-scripts/
ENV DEBIAN_FRONTEND=noninteractive

# [Option] Install zsh
ARG INSTALL_ZSH="true"
# [Option] Upgrade OS packages to their latest versions
ARG UPGRADE_PACKAGES="true"
# Add NPM global to PATH.
ENV PATH=${NPM_GLOBAL}/bin:${PATH}

# 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}
RUN apt-get update \
# 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}" \
RUN \
# 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 \
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} \
&& su ${USERNAME} -c "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
&& npm cache clean --force > /dev/null 2>&1

# Enable PNPM
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
RUN sudo corepack enable \
RUN corepack enable \
&& corepack prepare pnpm@latest --activate

EXPOSE 3000

# Add Docker Source
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

# Add cloudflared Source
RUN curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null && \
echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflared.list

# Add Localazy Source
RUN curl -sS https://dist.localazy.com/debian/pubkey.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/localazy.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/localazy.gpg] https://maven.localazy.com/repository/apt/ stable main" | sudo tee /etc/apt/sources.list.d/localazy.list

# Install the packages we need
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && apt-get install -qy \
RUN apt-get update && apt-get install -qy \
bash \
build-essential \
cloudflared \
curl \
docker-ce-cli \
jq \
less \
git \
gnupg2 \
localazy \
nano \
netcat \
netcat-openbsd \
pandoc \
unzip \
wget
Expand Down
31 changes: 11 additions & 20 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,7 @@
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"sqltools.connections": [
// Default connection to dev DB container
{
"name": "Local Dev",
"server": "db",
"port": 5432,
"database": "postgres",
"username": "postgres",
"password": "postgres",
"driver": "PostgreSQL",
"askForPassword": false,
"connectionTimeout": 60
}
]
"terminal.integrated.defaultProfile.linux": "zsh"
},
"extensions": [
"arcanis.vscode-zipfs",
Expand Down Expand Up @@ -66,11 +52,16 @@
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node",
"features": {
"common": {
"installZsh": true,
"installOhMyZsh": true,
"upgradePackages": true
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "true",
"installOhMyZsh": "true",
"username": "node",
"upgradePackages": "true"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "none"
},
"github-cli": "latest"
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/joedmck/devcontainer-features/cloudflared:1": {}
}
}
4 changes: 1 addition & 3 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
app:
build:
Expand All @@ -9,7 +7,7 @@ services:
# Update 'VARIANT' to pick an LTS version of Node.js: 18, 16, 14, 12.
# Append -bullseye or -buster to pin to an OS version.
# Use -bullseye variants on local arm64/Apple Silicon.
VARIANT: 20-bullseye
VARIANT: 22-bookworm

volumes:
- ..:/workspace
Expand Down

0 comments on commit 1a6b585

Please sign in to comment.