Skip to content

Commit fb0e664

Browse files
authored
Prototype configuration of a devcontainer to speed up dev-env configuration (#8)
1 parent bcd84f1 commit fb0e664

8 files changed

Lines changed: 180 additions & 0 deletions

.devcontainer/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Pull git checkout and build artifacts from previous build
2+
FROM cspotcode/node-devcontainer:prior as prior
3+
4+
# Configure an Ubuntu-based dev environment
5+
FROM cspotcode/node-devcontainer:ubuntu-base
6+
7+
# Copy worktree
8+
COPY --chown=build:build --from=prior /workspaces/node-prior /workspaces/node
9+
10+
# Rebuild with the latest origin/master
11+
RUN git reset
12+
RUN git fetch
13+
RUN git rebase
14+
RUN ./configure && make -j4
15+
16+
WORKDIR /workspaces
17+
RUN mv /workspaces/node /workspaces/node-prior
18+
WORKDIR /workspaces/node-prior
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Configure an Ubuntu-based dev environment
2+
FROM cspotcode/node-devcontainer:ubuntu-base
3+
4+
WORKDIR /workspaces/node
5+
# Rebuild (should be fast since prior build already did this)
6+
RUN git clone https://github.com/nodejs/node /workspaces/node
7+
RUN ./configure && make -j4
8+
9+
WORKDIR /workspaces
10+
RUN mv /workspaces/node /workspaces/node-prior
11+
WORKDIR /workspaces/node-prior
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Configure an Ubuntu-based dev environment
2+
FROM ubuntu:20.04
3+
RUN apt-get update
4+
RUN apt-get install -y build-essential python3 curl git less vim sudo
5+
RUN curl -L https://github.com/__raw/tj/n/master/bin/n -o n
6+
RUN bash n lts
7+
ARG UID=1000
8+
ARG GID=1000
9+
RUN adduser --home /home/build --shell /bin/bash --uid $UID build
10+
# allow build user to sudo without password
11+
RUN adduser build sudo
12+
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
13+
14+
# Create workdir
15+
RUN mkdir -p /workspaces/node
16+
RUN chown build:build /workspaces /workspaces/node
17+
WORKDIR /workspaces/node
18+
19+
USER build

.devcontainer/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
VSCode lets you describe how to run within a dockerized dev environment.
2+
3+
This configuration leverages that feature to quickly give you:
4+
5+
- a fully-functional node dev environment
6+
- a pre-populated build cache. `make -j4` should take about 2mins the first time, not an hour
7+
8+
## How to use
9+
10+
1. Clone `node` to `<node checkout directory>`
11+
2. Clone this branch somewhere, perhaps `<node checkout directory>/.node-code-ide-configs`
12+
3. Symlink or copy these configs into your `<node checkout directory>`
13+
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..."
14+
5. Within VSCode's integrated terminal (which is running inside the devcontainer) run `./.devcontainer/copy-build-artifacts.sh`
15+
6. Try it out:
16+
17+
```shell
18+
# delete node binary
19+
rm node out/Release/node
20+
# rebuild
21+
make -j4
22+
# run it
23+
./node
24+
```
25+
26+
## How to build the image from scratch (slow)
27+
28+
```
29+
./.devcontainer/build-from-scratch.sh
30+
```
31+
32+
## How to build the image from a previously-built image (fast)
33+
34+
```
35+
./.devcontainer/build-from-prior.sh
36+
```

.devcontainer/build-from-prior.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Build the docker devcontainer by pulling build artifacts from a prior devcontainer. This should be much faster
5+
#
6+
7+
set -euo pipefail
8+
shopt -s inherit_errexit
9+
10+
__dirname="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11+
cd "$__dirname"
12+
13+
docker build -t cspotcode/node-devcontainer:ubuntu-base --file ./Dockerfile.ubuntu-base .
14+
docker build -t cspotcode/node-devcontainer:prior .
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Rebuild the docker devcontainer from a clean git checkout. This will take a long time
5+
#
6+
7+
set -euo pipefail
8+
shopt -s inherit_errexit
9+
10+
__dirname="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11+
cd "$__dirname"
12+
cd ..
13+
14+
docker build -t cspotcode/node-devcontainer:ubuntu-base --file ./.devcontainer/Dockerfile.ubuntu-base .
15+
# TODO must manually re-tag this image as cspotcode/node-devcontainer:prior to use it in the build-from-prior script
16+
docker build -t cspotcode/node-devcontainer:from-scratch --file ./.devcontainer/Dockerfile.from-scratch .
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
shopt -s nullglob
4+
5+
# This list generated by deleting .gitignore and running `git status` after a build
6+
artifacts=(
7+
.eslintcache
8+
__pycache__
9+
#*/__pycache__
10+
#*/*/__pycache__
11+
#*/*/*/__pycache__
12+
config.gypi
13+
config.mk
14+
config.status
15+
deps/icu-tmp
16+
deps/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__
17+
deps/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__pycache__
18+
icu_config.gypi
19+
node
20+
node_trace.1.log
21+
out
22+
test/*/__pycache__
23+
test/addons/01_worker_support
24+
test/addons/02_function_arguments
25+
test/addons/03_callbacks
26+
test/addons/04_object_factory
27+
test/addons/05_function_factory
28+
test/addons/06_wrapping_c_objects
29+
test/addons/07_factory_of_wrapped_objects
30+
test/addons/08_passing_wrapped_objects_around
31+
tools/.cpplintstamp
32+
tools/.doclintstamp
33+
tools/.mdlintstamp
34+
tools/__pycache__
35+
tools/configure.d/__pycache__
36+
tools/doc/node_modules
37+
tools/inspector_protocol/__pycache__
38+
tools/inspector_protocol/jinja2/__pycache__
39+
tools/inspector_protocol/markupsafe/__pycache__
40+
tools/v8_gypfiles/__pycache__
41+
)
42+
shopt -u nullglob
43+
44+
from="/workspaces/node-prior"
45+
to="/workspaces/node"
46+
for artifact in "${artifacts[@]}" ; do
47+
echo "Copy build artifact from $from to $to: $artifact"
48+
cp -rp "$from/$artifact" "$to/$artifact"
49+
echo "Changing ownership of build artifact to match UID: $artifact"
50+
# VSCode updates the `build` user ID in the container to match host's user ID
51+
# This avoids volume mounting issues.
52+
# We must manually update owner of copied files
53+
sudo chown -R build "$to/$artifact"
54+
done

.devcontainer/devcontainer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "node-devcontainer",
3+
"image": "cspotcode/node-devcontainer:prior",
4+
"workspaceFolder": "/workspaces/node",
5+
6+
// VSCode extensions to automatically install within the dev environment
7+
"extensions": [
8+
"ms-azuretools.vscode-docker",
9+
"dbaeumer.vscode-eslint",
10+
"ms-vscode.cpptools"
11+
]
12+
}

0 commit comments

Comments
 (0)