diff --git a/Dockerfile b/Dockerfile index dfb9717..9a48994 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,25 +9,50 @@ RUN useradd --uid $USER_UID --gid $USER_GID --shell /bin/bash --create-home deve # Install sudo first RUN apt-get update -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sudo +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates curl git git-restore-mtime sudo xz-utils # No Sudo Prompt - thanks Electron for this RUN echo 'developer ALL=NOPASSWD: ALL' >> /etc/sudoers.d/developer RUN echo 'Defaults env_keep += "DEBIAN_FRONTEND"' >> /etc/sudoers.d/env_keep ENV DEBIAN_FRONTEND=1 -ENV PATH=/usr/lib/ccache:$PATH # Copy scripts and make them executable by both root and developer COPY --chown=root:developer --chmod=0755 ./scripts/ /home/developer/scripts/ -RUN /home/developer/scripts/install.sh -RUN /home/developer/scripts/ccache.sh USER developer RUN /home/developer/scripts/clone.sh + +# Installing Nix and Cachix +RUN curl -L "https://github.com/$(sed -nE 's#.*(cachix/install-nix-action)@([a-f0-9]+).*#\1/raw/\2#p' /home/developer/nodejs/node/.github/workflows/test-shared.yml)/install-nix.sh" | \ + USER=developer \ + INPUT_SET_AS_TRUSTED_USER=true \ + INPUT_ENABLE_KVM=true \ + INPUT_EXTRA_NIX_CONFIG= \ + INPUT_INSTALL_OPTIONS= \ + RUNNER_TEMP=$(mktemp -d) GITHUB_ENV=/dev/null GITHUB_PATH=/dev/null bash +ENV NIX_PROFILES="/nix/var/nix/profiles/default /home/developer/.nix-profile" +ENV NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt +ENV PATH="/home/developer/.local/bin:/home/developer/.nix-profile/bin:${PATH}" +RUN nix-env -iA cachix -f https://cachix.org/api/v1/install +RUN USER=developer cachix use nodejs + +# Installing direnv +RUN nix profile add nixpkgs#nix-direnv nixpkgs#direnv -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix +RUN mkdir -p /home/developer/.config/direnv && \ + echo 'source $HOME/.nix-profile/share/nix-direnv/direnvrc' > /home/developer/.config/direnv/direnvrc +RUN echo 'eval "$(direnv hook bash)"' >> /home/developer/.bashrc + +# Setting up direnv for the local clone +ARG USE_SHARED_LIBS=false +RUN echo "use nix --impure -I nixpkgs=/home/developer/nodejs/node/tools/nix/pkgs.nix$([ "${USE_SHARED_LIBS}" = "true" ] || echo " --arg sharedLibDeps '{}' --argstr icu full")" > /home/developer/nodejs/node/.envrc +RUN direnv allow /home/developer/nodejs/node + RUN /home/developer/scripts/build.sh -ENV PATH=/home/developer/.local/bin:$PATH WORKDIR /home/developer/nodejs/node RUN /home/developer/scripts/install-node.sh RUN /home/developer/scripts/ncu.sh + +# direnv will automatically load the nix environment when entering the directory +ENTRYPOINT ["/bin/bash", "-l"] diff --git a/README.md b/README.md index c6f7316..993247c 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Do this from your local system, not in the container. The `git` configuration wi Some useful commands: - `docker build .` - build the current Dockerfile - `docker image ls` - list the images and IDs -- `docker run -it /bin/bash` - run a container and shell into it +- `docker run -it ` - run a container and shell into it - `docker tag devcontainer:nightly` - run to tag an image as `nightly` diff --git a/scripts/build.sh b/scripts/build.sh index 11e0a15..09a94b8 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash -set -e # Exit with nonzero exit code if anything fails +set -xe -/home/developer/nodejs/node/configure --ninja && make -C /home/developer/nodejs/node +cd /home/developer/nodejs/node +eval "$(direnv export bash)" + +make -C /home/developer/nodejs/node build-ci diff --git a/scripts/ccache.sh b/scripts/ccache.sh deleted file mode 100755 index c009c28..0000000 --- a/scripts/ccache.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -e # Exit with nonzero exit code if anything fails - -# create symlinks -/usr/sbin/update-ccache-symlinks diff --git a/scripts/clone.sh b/scripts/clone.sh index ea16c68..53d59dc 100755 --- a/scripts/clone.sh +++ b/scripts/clone.sh @@ -1,10 +1,11 @@ #!/usr/bin/env bash -set -e # Exit with nonzero exit code if anything fails +set -xe mkdir -p /home/developer/nodejs -cd /home/developer/nodejs -git clone https://github.com/nodejs/node.git --single-branch --branch main --depth 1 -cd /home/developer/nodejs/node -git remote add upstream https://github.com/nodejs/node.git -git restore-mtime # Restore file modification times to commit times for build cache to match. +git clone https://github.com/nodejs/node.git --depth 1 /home/developer/nodejs/node +( + cd /home/developer/nodejs/node + git remote add upstream https://github.com/nodejs/node.git + git restore-mtime # Restore file modification times to commit times for build cache to match. +) diff --git a/scripts/install-node.sh b/scripts/install-node.sh index 47f2d64..8042f8f 100755 --- a/scripts/install-node.sh +++ b/scripts/install-node.sh @@ -1,7 +1,13 @@ #!/usr/bin/env bash -set -e # Exit with nonzero exit code if anything fails +set -xe + +cd /home/developer/nodejs/node +eval "$(direnv export bash)" make install PREFIX=/home/developer/.local -C /home/developer/nodejs/node -echo '' >> /home/developer/.bashrc -echo 'export PATH=/home/developer/.local/bin:$PATH' >> /home/developer/.bashrc +{ + echo '' + # Expose the PATH generated by Nix + the recently built `node` installation + echo "export PATH=/home/developer/.local/bin:$PATH" + } >> /home/developer/.bashrc diff --git a/scripts/install.sh b/scripts/install.sh deleted file mode 100755 index 4f30dde..0000000 --- a/scripts/install.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -set -e # Exit with nonzero exit code if anything fails - -package_list=" - build-essential \ - ccache \ - curl \ - nano \ - python3 \ - python3-pip \ - python-is-python3 \ - ninja-build \ - g++ \ - gcc \ - g++-12 \ - gcc-12 \ - make \ - git \ - pkg-config \ - locales \ - gpg \ - wget \ - git-restore-mtime" - -# Install Packages -apt-get update -DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $package_list - -# set up GitHub CLI resistry stuff to get gh CLI -curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg -echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null -gh_package_list="gh" -apt-get update -DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $gh_package_list diff --git a/scripts/ncu.sh b/scripts/ncu.sh index 0612251..70c267f 100755 --- a/scripts/ncu.sh +++ b/scripts/ncu.sh @@ -1,8 +1,9 @@ #!/usr/bin/env bash -set -e # Exit with nonzero exit code if anything fails +set -xe -npm install -g @node-core/utils +cd /home/developer/nodejs/node +eval "$(direnv export bash)" ncu-config set upstream upstream ncu-config set branch main diff --git a/scripts/setup-origin.sh b/scripts/setup-origin.sh deleted file mode 100755 index c990016..0000000 --- a/scripts/setup-origin.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -e # Exit with nonzero exit code if anything fails - -if [[ -z "${ORIGIN_URL}" ]] -then - echo "ORIGIN_URL is not set" -else - git remote set-url origin ${ORIGIN_URL} -fi