feat: make use of Nix files to set up dev env (#22)
feat: make use of Nix files to set up dev env
Update Dockerfile
Use the same Nix version as the one tested by GHA
fix PATH
add
direnvandUSE_SHARED_LIBSargfixup! move ARG down to avoid needlesly invalidate cache
squash! also use vendored ICU
Add comments
Co-authored-by: Joyee Cheung joyeec9h3@gmail.com
fixup! Add comments
fix quoting in
install-nodeadd
IMAGE_VARIANTbuild varApply suggestions from code review
Co-authored-by: Joyee Cheung joyeec9h3@gmail.com
Co-authored-by: Joyee Cheung joyeec9h3@gmail.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802032778号
Node.js Developer Container (
devcontainer)Usage
Setup
Running with Docker Desktop
To run locally on your machine, you’ll want to install Docker Desktop and start it up.
It’s recommended to use Visual Studio Code with the Dev Containers extension installed, but you can also run the container directly with Docker CLI or the Dev Container CLI, or attach any editor that supports the concept of
devcontainersto this container.Once you’ve got Docker Desktop running, you can run the following command to pull and start the image:
To use it as a devcontainer, create a
.devcontainer/devcontainer.jsonfile in the project with the following content:For example, to use it with Visual Studio Code, use the “Dev Containers: Reopen in Container” command from the Command Palette (
Ctrl+Shift+PorCmd+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 atout/to speed up builds.Working in the Container
The project is located at
/home/developer/nodejs/node. After the container is started, you should be automatically placed in this directory.If you want to build the project in the container, run with
ninja(rather than justmake):To build the release build, run
ninja -C out/ReleaseThe 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.If you notice that the build is not picking up your changes after checking out a different branch, run
git restore-mtimein the container to sync the mtimes of the files in your checkout with the git commit timestamps.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:
Note that if you install this git hook to your mounted project, and you still wish to run
git checkoutfrom you local system, you will need to installgit-restore-mtimeon your local system as well.Personal Configuration
Do this from your local system, not in the container. The
gitconfiguration will be used in the container since the project is mounted from your local system.originto your own fork rather thannodejs/nodeUSERNAMEis your GitHub username:$ git remote set-url origin https://github.com/USERNAME/node.gitgit remote -vgit config --global user.name "YOUR NAME"git config --global user.email "YOUR@EMAIL.TLD"ghCLI and rungh auth loginto login and add a new key.Development
Some useful commands:
docker build .- build the current Dockerfiledocker image ls- list the images and IDsdocker run -it <image id>- run a container and shell into itdocker tag <image id> devcontainer:nightly- run to tag an image asnightlyTips and Tricks for Debugging Failed Builds and Otherwise Developing in This Repo
Some notes on what’s been helpful:
RUNstatement in the Dockerfile into multipleRUNstatements, each containing a single command. This provies more precise information about what exactly is failing if the Docker build fails and isn’t providing helpful output.RUNstatement in the Dockerfile and runningdocker build, running the built container, and individually running each command in the running container is a better development experience than working outside of the built container.