Skip to content

Commit

Permalink
Make setup-node faster and more reliable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mumoshu committed Oct 24, 2023
1 parent 6bccd2a commit 4db6319
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Dockerfile.ubuntu20
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF && npm uninstall -g @actions/tool-cache
const tc = require('@actions/tool-cache');
const allNodeVersions = tc.findAllVersions('node');
const expected = ['${NODE_VERSION}'];
if (expected[0] == '') {
console.log('Invalid NODE_VERSION: ' + expected[0]);
process.on("exit", function() {
process.exit(1);
});
} else if (allNodeVersions.length != expected.length) {
console.log('Expected versions of node available: ' + expected);
console.log('Actual versions of node available: ' + allNodeVersions);
process.on("exit", function() {
process.exit(1);
});
} else if (allNodeVersions[0] != expected[0]) {
console.log('Expected versions of node available: ' + expected);
console.log('Actual versions of node available: ' + allNodeVersions);
process.on("exit", function() {
process.exit(1);
});
} else {
console.log('Versions of node available: ' + allNodeVersions);
}
EOF

COPY entrypoint.sh /

VOLUME /var/lib/docker
Expand Down

0 comments on commit 4db6319

Please sign in to comment.