Skip to content

Base image to build Node.js app in a VS Code dev container

License

Notifications You must be signed in to change notification settings

gp-devenv/gp-node-devenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Daily build

License

Ubuntu ARM64 ARMV7 AMD64

NODE 16.X NODE 18.X NODE 20.X

gp-node-devenv: Build Node.js dev containers for VSCode

Copyright (c) 2023, Greg PFISTER. MIT License

About

This is a simple Ubuntu container to use as development environment for node projects using Node, Typescript and Angular, which I use with Visual Studio Code Remote Container feature.

This is image is provided with Ubuntu 22.04.

See version mapping to find out which version Ubuntu and node and java.

This image is built from ghcr.io/gp-devenv/gp-base-devenv and adds:

  • a node environment to build node

The image can be found here.

Volumes

In order to persist user data, a volume for the /home folder is set. The root user will not be persisted.

Volume Description
/home  Persist the user data stored in their home folder

Build, scan and push

Versioning

Image version contains the Ubuntu version and the build version, using the format <Ubuntu version>-<Node version>-<Build version>. The build version refers to the latest Dockerfile script, when modification consists of fixing (patch change), or adding or removing something significant (minor change) or breaking (major).

For example:

Image Description
ghcr.io/gp-devenv/gp-node-devenv:22.04-18 The latest build using Ubuntu 22.04 and Node v18
ghcr.io/gp-devenv/gp-node-devenv:22.04-18-1 The latest build 1.x using Ubuntu 22.04 and Node v18
ghcr.io/gp-devenv/gp-node-devenv:22.04-18-1.1 The latest build 1.1.x using Ubuntu 22.04 and Node v18
ghcr.io/gp-devenv/gp-node-devenv:22.04-18-1.1.0 The latest build 1.1.0 using Ubuntu 22.04 and Node v18
ghcr.io/gp-devenv/gp-node-devenv:22.04-18-1.0 The latest build 1.0.x using Ubuntu 22.04 and Node v18
ghcr.io/gp-devenv/gp-node-devenv:22.04-18-1.0.0 The latest build 1.0.0 using Ubuntu 22.04 and Node v18

For CI/CD, the build version is store in .version file. The build version is in the format SemVer.

Only the latest version (MAJOR, MAJOR.MINOR and MAJOR.MINOR.PATCH) is been built daily.

Testing locally using -dev images

When you are making change to the image, use :develop at the end of the build, run and scan commands. The *-dev tag should never be pushed...

Cross-platform building

Setup

In order to build x-platform, docker buildx must be enabled (more info here). Then, instead of build command, buildx command should be used (for example: npm run buildx:develop will create a cross-platform image tagged develop).

You will need to create a multiarch builder:

./src/scripts/buildx/setup.sh

On successful completion, it should at least have platforms linux/arm64, linux/arm/v7 and linux/amd64:

[+] Building 5.8s (1/1) FINISHED
 => [internal] booting buildkit                                             5.8s
 => => pulling image moby/buildkit:buildx-stable-1                            7s
 => => creating container buildx_buildkit_multiarch0                          1s
Name:   multiarch
Driver: docker-container

Nodes:
Name:      multiarch0
Endpoint:  unix:https:///var/run/docker.sock
Status:    running
Platforms: linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64,
           linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64,
           linux/arm/v7, linux/arm/v6

Build commands

Once the previous step is completed, simpy run to build the current version:

(cd src && ./scripts/buildx/build.sh)

Build using local architecture (for local testing)

Build the development image

To build using a specific Ubuntu version, use:

(cd scr && ./scripts/dev/image/build.sh <UBUNTU_VERSION> <NODE_VERSION>)

With:

  • UBUNTU_VERSION can be 22.04 or 24.04.
  • NODE_VERSION can be 18, 20 or 20.

It will create and image ghcr.io/gp-devenv/gp-node-devenv tagged with the current version (see src/.version file) and -dev suffix.

You may alter the .src/.version file should you want to have different tags or names, however if you PR your change, it will be rejected. The ideal solution is to run the docker build command instead.

To remove the created image (named: ghcr.io/gp-devenv/gp-node-devenv:<UBUNTU_VERIONS>-<NODE_VERSION>-<VERSION>-dev), simply use:

(cd scr && ./scripts/dev/image/rm.sh <UBUNTU_VERSION> <NODE_VERSION>)

Run or create/start/stop/exec a container

To run an interactive container of a give Ubuntu version, simple use:

(cd src && ./scripts/dev/container/run.sh <UBUNTU_VERSION> <NODE_VERSION>)

With:

  • UBUNTU_VERSION can be 22.04 or 24.04.
  • NODE_VERSION can be 18, 20 or 20.

Alternatively, you can create and start a container to run in background, and execute scripts on this container, using the following scripts:

Action Script
create (cd src && ./scripts/dev/container/create.sh <UBUNTU_VERSION> <NODE_VERSION>)
start (cd src && ./scripts/dev/container/start.sh <UBUNTU_VERSION> <NODE_VERSION>)
stop (cd src && ./scripts/dev/container/stop.sh <UBUNTU_VERSION> <NODE_VERSION>)
exec (cd src && ./scripts/dev/container/exec.sh <UBUNTU_VERSION> <NODE_VERSION>)

To remove the created container (named: gp-node-devenv:<UBUNTU_VERIONS>-<NODE_VERSION>-<VERSION>-dev), simply use:

(cd src && ./scripts/dev/container/rm.sh <UBUNTU_VERSION> <NODE_VERSION>)

Scan the development image

To scan the image of a give Ubuntu version, simple use:

(cd src && ./scripts/dev/scan.sh <UBUNTU_VERSION>)

where UBUNTU_VERSION can be 22.04 or 24.04.

Build from this image

Should you want to make other changes, the ideal solution is to build from this image. For example, here's the way to set the image to a different timezone than "Europe/Paris" (the default one):

FROM ghcr.io/gp-devenv/gp-node-devenv:22.04

ENV TZ="America/New_York"

# Switch to root
USER root

# Reconfigure tzdata
RUN dpkg-reconfigure -f noninteractive tzdata

# Switch back to vscode
USER vscode

Important: unless you really want to use the root user, you should always make sure the vscode is the last one activate.

Version

Base image version correspond to the underlying base image that can be found here

Image  Base image version Ubuntu Supported Node version amd64 arm64 arm/v7 Daily build
22:04-<NODE_VERSION> ghcr.io/gp-devenv/gp-base-devenv:22.04-1 22.04 (LTS) 18.x, 20.x, 22.x X X X Yes
22:04-<NODE_VERSION>-1.x ghcr.io/gp-devenv/gp-base-devenv:22.04-1 22.04 (LTS) 18.x, 20.x, 22.x X X X Yes
24:04-<NODE_VERSION> ghcr.io/gp-devenv/gp-base-devenv:24.04-1 24.04 (LTS) 18.x, 20.x, 22.x X X X Yes
24:04-<NODE_VERSION>-1.x ghcr.io/gp-devenv/gp-base-devenv:24.04-1 24.04 (LTS) 18.x, 20.x, 22.x X X X Yes

FAQ

  1. How to require password for sudo command ?
  2. Is there an example to use it with Visual Studio Code ?

1. How to require password for sudo command ?

You will have to build from this image to disable the the password less sudo command. Typically create a Dockerfile like:

FROM ghcr.io/gp-devenv/gp-node-devenv:22.04

ARG VSCODE_PASSWORD="dummy"

# Switch to root to make changes
USER root

# Remove the specific config for sudo and add to sudo group
RUN rm /etc/sudoers.d/vscode && \
    usermod -aG sudo vscode

# Change the password.
RUN usermod -p $VSCODE_PASSWORD vscode

# Switch back to vscode
USER vscode

If you simply want to get rid of sudo:

FROM ghcr.io/gp-devenv/gp-node-devenv:22.04

# Switch to root to make changes
USER root

# Remove the specific config for sudo and add to sudo group
RUN rm /etc/sudoers.d/vscode && \
    apt-get purge -y sudo

# Switch back to vscode
USER vscode

2. Is there an example to use it with Visual Studio Code ?

There will be one soon !!! Add notification to this project so that when the update on this file is done you can check.

Known issues

See known issues here.

Contributions

See instructions here.

License

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

See license here.