From 4db6319cd2edbfaf6f60be5a598a1ad95a03fe55 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Tue, 24 Oct 2023 04:59:33 +0000 Subject: [PATCH] Make setup-node faster and more reliable We have occasionally seen that setup-node actions failing due to intermittent connection failures between us and nodejs.org. To alleviate the issue, we could cache our "most-widely-used" Node.js version inside the container image, enabling setup-node to skip access to nodejs.org. This tries to implements that, in a way so that it becomes resilient to nodejs and tool-cache changes. Just keep updating NODE_VERSION defined in the dockerfile using dependabot or renovate- the rest of the change will just work regardless of the version you want. --- Dockerfile.ubuntu20 | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Dockerfile.ubuntu20 b/Dockerfile.ubuntu20 index 9d7a6445..83f863a6 100644 --- a/Dockerfile.ubuntu20 +++ b/Dockerfile.ubuntu20 @@ -65,9 +65,48 @@ RUN export RUNNER_ARCH=${TARGETARCH} \ && rm -rf docker # some setup actions store cache into /opt/hostedtoolcache +ENV RUNNER_TOOL_CACHE /opt/hostedtoolcache + RUN mkdir /opt/hostedtoolcache \ && chown runner:docker /opt/hostedtoolcache +# We pre-install nodejs to reduce time of setup-node and improve its reliability. +ENV NODE_VERSION 18.18.2 + +RUN mkdir -p /opt/hostedtoolcache/node/${NODE_VERSION}/${TARGETARCH} && \ + curl -s -L https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${TARGETARCH}.tar.gz \ + | tar xvzf - -C /opt/hostedtoolcache/node/${NODE_VERSION}/${TARGETARCH} \ + && touch /opt/hostedtoolcache/node/${NODE_VERSION}/${TARGETARCH}.complete \ + && chown -R runner:docker /opt/hostedtoolcache/node && \ + ${RUNNER_TOOL_CACHE}/node/${NODE_VERSION}/arm64/node-v${NODE_VERSION}-linux-${TARGETARCH}/bin/node --version + +RUN export PATH=$PATH:/home/runner/externals/node20/bin ; export NODE_PATH=/home/runner/externals/node20/lib/node_modules ; \ + npm install -g @actions/tool-cache && node <