|
8 | 8 |
|
9 | 9 | To run locally on your machine, you'll want to install [Docker Desktop](https://www.docker.com/products/docker-desktop/) and start it up. |
10 | 10 |
|
11 | | -Once you've got Docker Destop running, you can run the following command to pull and start the image: |
| 11 | +It's recommended to use Visual Studio Code with the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) |
| 12 | +installed, but you can also run the container directly with Docker CLI or the [Dev Container CLI](https://github.com/devcontainers/cli), or attach any editor that supports the concept of [`devcontainers`](https://containers.dev/) to this container. |
| 13 | + |
| 14 | +Once you've got Docker Desktop running, you can run the following command to pull and start the image: |
12 | 15 |
|
13 | 16 | ```sh |
14 | 17 | docker pull nodejs/devcontainer:nightly |
15 | 18 | docker run -it nodejs/devcontainer:nightly /bin/bash |
16 | 19 | ``` |
17 | 20 |
|
18 | | -Once you've run those commands, you'll be in a shell inside the running container. If you need to escape, type `exit`. You should be good to jump to [Working in the Container](#working-in-the-container). |
| 21 | +To use it as a devcontainer, create a `.devcontainer/devcontainer.json` file in the project with the following content: |
| 22 | + |
| 23 | +```json |
| 24 | +{ |
| 25 | + "name": "Node.js Dev Container", |
| 26 | + "image": "nodejs/devcontainer:nightly", |
| 27 | + "workspaceMount": "source=${localWorkspaceFolder},target=/home/developer/nodejs/node,type=bind,consistency=cached", |
| 28 | + "workspaceFolder": "/home/developer/nodejs/node", |
| 29 | + "remoteUser": "developer", |
| 30 | + "mounts": [ |
| 31 | + "source=build-cache,target=/home/developer/nodejs/node/out,type=volume" |
| 32 | + ], |
| 33 | + "postCreateCommand": "git restore-mtime" |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +For example, to use it with Visual Studio Code, use the "Dev Containers: Reopen in Container" command from the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P`). After the container is built and started, you should be inside the container with the project mounted in the working directory, while the build cache volume mounted at `out/` to speed up builds. |
19 | 38 |
|
20 | 39 | ### Working in the Container |
21 | 40 |
|
22 | | -- The project is located at `/home/developer/nodejs/node`. |
23 | | - - Once this directory is your active directory, you should be good to go. |
24 | | - - If you want to build the project in the container, run with ninja (rather than just make): |
25 | | - - `/home/developer/nodejs/node/configure --ninja && make -C /home/developer/nodejs/node` |
26 | | -- You should be able to attach any editor that supports the concept of [`devcontainers`](https://containers.dev/) to this |
| 41 | +- The project is located at `/home/developer/nodejs/node`. After the container is started, you should be automatically placed in this directory. |
| 42 | +- If you want to build the project in the container, run with `ninja` (rather than just `make`): |
| 43 | + - To build the release build, run `ninja -C out/Release` |
| 44 | + - The container comes with a release build that can be picked up by `ninja`. As long as your mounted local checkout is not too far behind the checkout in the container, incremental builds should be fast. |
| 45 | + - If you notice that the build is not picking up your changes after checking out a different branch, run `git restore-mtime` in the container to sync the mtimes of the files in your checkout with the git commit timestamps. |
| 46 | + - You can also set up a git hook to sync the mtime automatically on checkout to keep the build cache effective. From the container, run: |
| 47 | + |
| 48 | + ```bash |
| 49 | + mkdir -p /home/developer/nodejs/node/.git/hooks |
| 50 | + cp /home/developer/scripts/post-checkout /home/developer/nodejs/node/.git/hooks/post-checkout |
| 51 | + ``` |
| 52 | + |
| 53 | + Note that if you install this git hook to your mounted project, and you still wish to run `git checkout` from you local system, you will need to install [`git-restore-mtime`](https://github.com/MestreLion/git-tools) on your local system as well. |
27 | 54 |
|
28 | 55 | ### Personal Configuration |
29 | 56 |
|
30 | | -Assuming you've already got the Docker container running: |
| 57 | +Do this from your local system, not in the container. The `git` configuration will be used in the container since the project is mounted from your local system. |
31 | 58 |
|
32 | 59 | - Set the git `origin` to your own fork rather than `nodejs/node` |
33 | 60 | - Example, where `USERNAME` is your GitHub username: `$ git remote set-url origin https://github.com/USERNAME/node.git` |
|
0 commit comments