Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Pull git checkout and build artifacts from previous build
FROM cspotcode/node-devcontainer:prior as prior

# Configure an Ubuntu-based dev environment
FROM cspotcode/node-devcontainer:ubuntu-base

# Copy worktree
COPY --chown=build:build --from=prior /workspaces/node-prior /workspaces/node

# Rebuild with the latest origin/master
RUN git reset
RUN git fetch
RUN git rebase
RUN ./configure && make -j4

WORKDIR /workspaces
RUN mv /workspaces/node /workspaces/node-prior
WORKDIR /workspaces/node-prior
11 changes: 11 additions & 0 deletions .devcontainer/Dockerfile.from-scratch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Configure an Ubuntu-based dev environment
FROM cspotcode/node-devcontainer:ubuntu-base

WORKDIR /workspaces/node
# Rebuild (should be fast since prior build already did this)
RUN git clone https://github.com/nodejs/node /workspaces/node
RUN ./configure && make -j4

WORKDIR /workspaces
RUN mv /workspaces/node /workspaces/node-prior
WORKDIR /workspaces/node-prior
19 changes: 19 additions & 0 deletions .devcontainer/Dockerfile.ubuntu-base
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Configure an Ubuntu-based dev environment
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get install -y build-essential python3 curl git less vim sudo
RUN curl -L https://github.com/__raw/tj/n/master/bin/n -o n
RUN bash n lts
ARG UID=1000
ARG GID=1000
RUN adduser --home /home/build --shell /bin/bash --uid $UID build
# allow build user to sudo without password
RUN adduser build sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# Create workdir
RUN mkdir -p /workspaces/node
RUN chown build:build /workspaces /workspaces/node
WORKDIR /workspaces/node

USER build
36 changes: 36 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
VSCode lets you describe how to run within a dockerized dev environment.

This configuration leverages that feature to quickly give you:

- a fully-functional node dev environment
- a pre-populated build cache. `make -j4` should take about 2mins the first time, not an hour

## How to use

1. Clone `node` to `<node checkout directory>`
2. Clone this branch somewhere, perhaps `<node checkout directory>/.node-code-ide-configs`
3. Symlink or copy these configs into your `<node checkout directory>`
4. Launch VSCode into this devcontainer. The buttons to click are beyond the scope of this README. VSCode's docs explain this. The command is named "Open folder in container..."
5. Within VSCode's integrated terminal (which is running inside the devcontainer) run `./.devcontainer/copy-build-artifacts.sh`
6. Try it out:

```shell
# delete node binary
rm node out/Release/node
# rebuild
make -j4
# run it
./node
```

## How to build the image from scratch (slow)

```
./.devcontainer/build-from-scratch.sh
```

## How to build the image from a previously-built image (fast)

```
./.devcontainer/build-from-prior.sh
```
14 changes: 14 additions & 0 deletions .devcontainer/build-from-prior.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

#
# Build the docker devcontainer by pulling build artifacts from a prior devcontainer. This should be much faster
#

set -euo pipefail
shopt -s inherit_errexit

__dirname="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$__dirname"

docker build -t cspotcode/node-devcontainer:ubuntu-base --file ./Dockerfile.ubuntu-base .
docker build -t cspotcode/node-devcontainer:prior .
16 changes: 16 additions & 0 deletions .devcontainer/build-from-scratch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

#
# Rebuild the docker devcontainer from a clean git checkout. This will take a long time
#

set -euo pipefail
shopt -s inherit_errexit

__dirname="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$__dirname"
cd ..

docker build -t cspotcode/node-devcontainer:ubuntu-base --file ./.devcontainer/Dockerfile.ubuntu-base .
# TODO must manually re-tag this image as cspotcode/node-devcontainer:prior to use it in the build-from-prior script
docker build -t cspotcode/node-devcontainer:from-scratch --file ./.devcontainer/Dockerfile.from-scratch .
54 changes: 54 additions & 0 deletions .devcontainer/copy-build-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

shopt -s nullglob

# This list generated by deleting .gitignore and running `git status` after a build
artifacts=(
.eslintcache
__pycache__
#*/__pycache__
#*/*/__pycache__
#*/*/*/__pycache__
config.gypi
config.mk
config.status
deps/icu-tmp
deps/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__
deps/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__pycache__
icu_config.gypi
node
node_trace.1.log
out
test/*/__pycache__
test/addons/01_worker_support
test/addons/02_function_arguments
test/addons/03_callbacks
test/addons/04_object_factory
test/addons/05_function_factory
test/addons/06_wrapping_c_objects
test/addons/07_factory_of_wrapped_objects
test/addons/08_passing_wrapped_objects_around
tools/.cpplintstamp
tools/.doclintstamp
tools/.mdlintstamp
tools/__pycache__
tools/configure.d/__pycache__
tools/doc/node_modules
tools/inspector_protocol/__pycache__
tools/inspector_protocol/jinja2/__pycache__
tools/inspector_protocol/markupsafe/__pycache__
tools/v8_gypfiles/__pycache__
)
shopt -u nullglob

from="/workspaces/node-prior"
to="/workspaces/node"
for artifact in "${artifacts[@]}" ; do
echo "Copy build artifact from $from to $to: $artifact"
cp -rp "$from/$artifact" "$to/$artifact"
echo "Changing ownership of build artifact to match UID: $artifact"
# VSCode updates the `build` user ID in the container to match host's user ID
# This avoids volume mounting issues.
# We must manually update owner of copied files
sudo chown -R build "$to/$artifact"
done
12 changes: 12 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "node-devcontainer",
"image": "cspotcode/node-devcontainer:prior",
"workspaceFolder": "/workspaces/node",

// VSCode extensions to automatically install within the dev environment
"extensions": [
"ms-azuretools.vscode-docker",
"dbaeumer.vscode-eslint",
"ms-vscode.cpptools"
]
}