Skip to content

Commit a32f5e7

Browse files
authored
Merge pull request #2659 from nschonni/full-js-build
feat: replace Bash update with full JS build
1 parent 84410ee commit a32f5e7

12 files changed

Lines changed: 219 additions & 783 deletions

‎.github/workflows/automatic-updates.yml‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,27 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1717

18-
- name: Run automation script
19-
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
20-
id: updt
18+
- name: Set up Node.js
19+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
2120
with:
22-
result-encoding: string
23-
script: |
24-
const { default: script } = await import(`${process.env.GITHUB_WORKSPACE}/build-automation.mjs`);
25-
return script(github);
21+
node-version-file: .node-version
22+
cache: npm
23+
- name: Install dependencies
24+
run: npm ci
25+
26+
- name: Run automation script
27+
run: npm run build
2628

2729
- name: Create update PR
28-
id: cpr
29-
if: steps.updt.outputs.result != ''
30+
if: env.NODE_PR_TITLE != ''
3031
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
3132
with:
3233
token: ${{ secrets.GH_API_TOKEN }}
3334
author: 'Node.js GitHub Bot <nodejs-github-bot@users.noreply.github.com>'
3435
branch: update-branch
3536
base: main
36-
commit-message: 'feat: Node.js ${{ steps.updt.outputs.result }}'
37-
title: 'feat: Node.js ${{ steps.updt.outputs.result }}'
37+
commit-message: '${{ env.NODE_PR_TITLE }}'
38+
title: '${{ env.NODE_PR_TITLE }}'
3839
delete-branch: true
3940
team-reviewers: |
4041
nodejs/docker

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ After the end of Debian LTS support, the corresponding Debian release is dropped
149149
### Image Creation Automation
150150

151151
- Every 15 minutes, the [workflow](https://github.com/nodejs/docker-node/blob/main/.github/workflows/automatic-updates.yml) within the [nodejs/docker-node](https://github.com/nodejs/docker-node) repo [checks](https://github.com/nodejs/docker-node/blob/main/build-automation.mjs) for new versions of Node.js [published to the website's `index.json` file](https://nodejs.org/download/release/index.json).
152-
- If found, the [update script](https://github.com/nodejs/docker-node/blob/main/update.sh) runs
152+
- If found, the [update script](https://github.com/nodejs/docker-node/blob/main/build-automation.mjs) runs
153153
- The workflow opens a pull request either automatically via [nodejs-github-bot](https://github.com/nodejs-github-bot) or in some cases manually, such as when there is a new major release.
154154
- Another [workflow](https://github.com/nodejs/docker-node/blob/main/.github/workflows/official-pr.yml) detects the merger of these pull requests and opens a pull request to [docker-library/official-images](https://github.com/docker-library/official-images).
155155
- The official images are built and published according to [docker's process](https://github.com/docker-library/faq#an-images-source-changed-in-git-now-what), resulting in the new images being available on [Docker Hub](https://hub.docker.com/_/node).
@@ -167,7 +167,7 @@ and your suggestion to resolve it.
167167
To set up a version update pull request, see the [Pull Requests](#pull-requests) section above and follow these instructions:
168168

169169
1. Create a `version-update` branch
170-
1. Run `./update.sh`. You can see additional options by using the built-in help documentation with `./update.sh -h`. This script will automatically update the appropriate files with the latest versions and checksums.
170+
1. Run `npm run build`. This script will automatically update the appropriate files with the latest versions.
171171
1. Commit the modified files to the `version-update` branch and push the branch to your fork.
172172
1. Create a pull request.
173173

‎Dockerfile-alpine.template‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN addgroup -g 1000 node \
1212
curl \
1313
&& ARCH= OPENSSL_ARCH='linux*' && alpineArch="$(apk --print-arch)" \
1414
&& case "${alpineArch##*-}" in \
15-
"${ALPINE_ARCH[@]}"
15+
"${SUPPORTED_ARCH[@]}"
1616
esac \
1717
# use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150
1818
&& export GNUPGHOME="$(mktemp -d)" \

‎Dockerfile-debian.template‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ENV NODE_VERSION=0.0.0
77

88
RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
99
&& case "${dpkgArch##*-}" in \
10-
"${DEB_ARCH[@]}"
10+
"${SUPPORTED_ARCH[@]}"
1111
esac \
1212
# use pre-existing gpg directory, see https://github.com/nodejs/docker-node/pull/1895#issuecomment-1550389150
1313
&& export GNUPGHOME="$(mktemp -d)" \

‎Dockerfile-slim.template‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ENV NODE_VERSION=0.0.0
77

88
RUN ARCH= OPENSSL_ARCH= && dpkgArch="$(dpkg --print-architecture)" \
99
&& case "${dpkgArch##*-}" in \
10-
"${DEB_ARCH[@]}"
10+
"${SUPPORTED_ARCH[@]}"
1111
esac \
1212
&& set -ex \
1313
&& apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr xz-utils libatomic1 --no-install-recommends \

‎architectures‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎build-automation.mjs‎

Lines changed: 140 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,150 @@
1-
import { promisify } from 'util';
2-
3-
import child_process from 'child_process';
4-
5-
const exec = promisify(child_process.exec);
6-
7-
// a function that queries the Node.js release website for new versions,
8-
// compare the available ones with the ones we use in this repo
9-
// and returns whether we should update or not
10-
const checkIfThereAreNewVersions = async (github) => {
11-
try {
12-
const { stdout: versionsOutput } = await exec(
13-
'. ./functions.sh && get_versions',
14-
{ shell: 'bash' },
15-
);
16-
17-
const supportedVersions = versionsOutput.trim().split(' ');
18-
19-
let latestSupportedVersions = {};
20-
21-
for (let supportedVersion of supportedVersions) {
22-
const { stdout } = await exec(`ls ${supportedVersion}`);
23-
24-
const { stdout: fullVersionOutput } = await exec(
25-
`. ./functions.sh && get_full_version ./${supportedVersion}/${stdout.trim().split('\n')[0]}`,
26-
{ shell: 'bash' },
27-
);
28-
29-
console.log(fullVersionOutput);
30-
31-
latestSupportedVersions[supportedVersion] = {
32-
fullVersion: fullVersionOutput.trim(),
33-
};
34-
}
35-
36-
const { data: availableVersionsJson } = await github.request(
37-
'https://nodejs.org/download/release/index.json',
1+
import { readFileSync, writeFileSync } from 'node:fs';
2+
import { join, resolve } from 'node:path';
3+
import { exportVariable } from '@actions/core';
4+
5+
const supportedVersions = JSON.parse(readFileSync('versions.json'));
6+
7+
const nodeKeys = readFileSync(resolve(import.meta.dirname, 'keys', 'node.keys'))
8+
.toString()
9+
.trim()
10+
.split('\n');
11+
12+
const updatedVersions = [];
13+
14+
try {
15+
console.log(
16+
`Found major versions in versions.json: ${Object.keys(supportedVersions).join(', ')}`,
17+
);
18+
19+
console.log('Grabbing Index.json files');
20+
const availableVersions = await fetch(
21+
'https://nodejs.org/download/release/index.json',
22+
);
23+
const officialIndexJson = await availableVersions.json();
24+
25+
for (let supportedVersion in supportedVersions) {
26+
console.log(`Checking for updates for ${supportedVersion}`);
27+
let latestVersion = officialIndexJson.find((indexVersion) =>
28+
indexVersion.version.startsWith(`v${supportedVersion}`),
3829
);
3930

40-
// filter only more recent versions of availableVersionsJson for each major version in latestSupportedVersions' keys
41-
// e.g. if latestSupportedVersions = { "12": "12.22.10", "14": "14.19.0", "16": "16.14.0", "17": "17.5.0" }
42-
// and availableVersions = ["Node.js 12.22.10", "Node.js 12.24.0", "Node.js 14.19.0", "Node.js 14.22.0", "Node.js 16.14.0", "Node.js 16.16.0", "Node.js 17.5.0", "Node.js 17.8.0"]
43-
// return { "12": "12.24.0", "14": "14.22.0", "16": "16.16.0", "17": "17.8.0" }
44-
45-
let filteredNewerVersions = {};
31+
console.log(`\tLatest version: ${latestVersion.version}
32+
\tReleased: ${latestVersion.date}
33+
\tSecurity release: ${latestVersion.security}`);
34+
35+
for (let variant in supportedVersions[supportedVersion].variants) {
36+
const dockerfilePath = join('.', supportedVersion, variant, 'Dockerfile');
37+
const currentDockerfile = readFileSync(dockerfilePath, 'utf-8');
38+
39+
const localVersion =
40+
'v' +
41+
currentDockerfile.match(/NODE_VERSION=(?<version>\d*\.\d*\.\d)/).groups[
42+
'version'
43+
];
44+
45+
const arches = supportedVersions[supportedVersion].variants[variant];
46+
47+
let baseImage;
48+
let archString = '';
49+
let dockerfileTemplate;
50+
if (variant.startsWith('alpine')) {
51+
dockerfileTemplate = readFileSync(
52+
resolve(import.meta.dirname, 'Dockerfile-alpine.template'),
53+
).toString();
54+
55+
baseImage = `alpine:${variant.replace(/alpine/, '')}`;
56+
if (arches.includes('amd64'))
57+
archString += `x86_64) ARCH='x64' OPENSSL_ARCH=linux-x86_64;; \\\n `;
58+
if (arches.includes('arm64v8'))
59+
archString += `aarch64) OPENSSL_ARCH=linux-aarch64;; \\\n `;
60+
if (arches.includes('arm32v6') || arches.includes('arm32v7'))
61+
archString += `arm*) OPENSSL_ARCH=linux-armv4;; \\\n `;
62+
if (arches.includes('ppc64le'))
63+
archString += `ppc64le) OPENSSL_ARCH=linux-ppc64le;; \\\n `;
64+
if (arches.includes('s390x'))
65+
archString += `s390x) OPENSSL_ARCH=linux-s390x;; \\\n `;
66+
archString += '*) echo "unsupported architecture"; exit 1 ;; \\';
67+
} else if (variant.endsWith('-slim')) {
68+
dockerfileTemplate = readFileSync(
69+
resolve(import.meta.dirname, 'Dockerfile-slim.template'),
70+
).toString();
71+
baseImage = `debian:${variant}`;
72+
if (arches.includes('amd64'))
73+
archString += `amd64) ARCH='x64' OPENSSL_ARCH='linux-x86_64';; \\\n `;
74+
if (arches.includes('ppc64le'))
75+
archString += `ppc64el) ARCH='ppc64le' OPENSSL_ARCH='linux-ppc64le';; \\\n `;
76+
if (arches.includes('s390x'))
77+
archString += `s390x) ARCH='s390x' OPENSSL_ARCH='linux*-s390x';; \\\n `;
78+
if (arches.includes('arm64v8'))
79+
archString += `arm64) ARCH='arm64' OPENSSL_ARCH='linux-aarch64';; \\\n `;
80+
if (arches.includes('arm32v7'))
81+
archString += `armhf) ARCH='armv7l' OPENSSL_ARCH='linux-armv4';; \\\n `;
82+
archString += '*) echo "unsupported architecture"; exit 1 ;; \\';
83+
} else {
84+
dockerfileTemplate = readFileSync(
85+
resolve(import.meta.dirname, 'Dockerfile-debian.template'),
86+
).toString();
87+
baseImage = `buildpack-deps:${variant}`;
88+
if (arches.includes('amd64'))
89+
archString += `amd64) ARCH='x64';; \\\n `;
90+
if (arches.includes('ppc64le'))
91+
archString += `ppc64el) ARCH='ppc64le';; \\\n `;
92+
if (arches.includes('s390x'))
93+
archString += `s390x) ARCH='s390x';; \\\n `;
94+
if (arches.includes('arm64v8'))
95+
archString += `arm64) ARCH='arm64';; \\\n `;
96+
if (arches.includes('arm32v7'))
97+
archString += `armhf) ARCH='armv7l';; \\\n `;
98+
archString += '*) echo "unsupported architecture"; exit 1 ;; \\';
99+
}
46100

47-
for (let availableVersion of availableVersionsJson) {
48-
const [availableMajor, availableMinor, availablePatch] =
49-
availableVersion.version.split('v')[1].split('.');
50-
if (latestSupportedVersions[availableMajor] == null) {
51-
continue;
101+
let dockerfileOutput = dockerfileTemplate
102+
.replace(/^FROM.+$/m, `FROM ${baseImage}`)
103+
.replace(
104+
/^ENV NODE_VERSION=.+$/m,
105+
`ENV NODE_VERSION=${latestVersion.version.substring(1)}`,
106+
)
107+
.replace(
108+
/^(\s*)"\${NODE_KEYS\[@]}".*$/m,
109+
((keys) => keys.map((key) => `$1${key} \\`).join('\n'))(nodeKeys),
110+
)
111+
.replace(/"\$\{SUPPORTED_ARCH\[@\]\}"/s, archString);
112+
113+
if (parseInt(supportedVersion, 10) >= 26) {
114+
dockerfileOutput = dockerfileOutput.replace(
115+
/ENV YARN_VERSION.*\*\n/s,
116+
'',
117+
);
118+
} else {
119+
// Strip out rust and cargo packages for Node.js < 26
120+
dockerfileOutput = dockerfileOutput.replace(
121+
/\s{4}rust \\.*cargo \\\s*/s,
122+
'',
123+
);
52124
}
53-
// eslint-disable-next-line no-unused-vars
54-
const [_latestMajor, latestMinor, latestPatch] =
55-
latestSupportedVersions[availableMajor].fullVersion.split('.');
56-
if (
57-
latestSupportedVersions[availableMajor] &&
58-
(Number(availableMinor) > Number(latestMinor) ||
59-
(availableMinor === latestMinor &&
60-
Number(availablePatch) > Number(latestPatch)))
61-
) {
62-
filteredNewerVersions[availableMajor] = {
63-
fullVersion: `${availableMajor}.${availableMinor}.${availablePatch}`,
64-
};
125+
if (dockerfileOutput === currentDockerfile) {
126+
console.log(`\t${variant}: everything up to date!`);
127+
} else if (latestVersion.version !== localVersion) {
128+
console.log(`\t${variant}: updating to ${latestVersion.version}`);
129+
updatedVersions.push(latestVersion.version);
130+
writeFileSync(dockerfilePath, dockerfileOutput);
131+
} else {
132+
console.warn(
133+
`\t${variant}: non-version changes detected, but file not updated.`,
134+
);
65135
}
66136
}
67-
68-
return {
69-
shouldUpdate:
70-
Object.keys(filteredNewerVersions).length > 0 &&
71-
JSON.stringify(filteredNewerVersions) !==
72-
JSON.stringify(latestSupportedVersions),
73-
versions: filteredNewerVersions,
74-
};
75-
} catch (error) {
76-
console.error(error);
77-
process.exit(1);
78137
}
79-
};
80-
81-
export default async function (github) {
82-
// if there are no new versions, exit gracefully
83-
// if there are new versions, run update.sh
84-
const { shouldUpdate, versions } = await checkIfThereAreNewVersions(github);
85-
86-
if (!shouldUpdate) {
87-
console.log('No new versions found. No update required.');
88-
process.exit(0);
138+
if (updatedVersions.length !== 0) {
139+
// Let the GitHub Action library set the GITHUB_ENV file rather than manually handling it
140+
exportVariable(
141+
'NODE_PR_TITLE',
142+
`feat: Node.js ${[...new Set(updatedVersions)].join(', ')}`,
143+
);
89144
} else {
90-
let updatedVersions = [];
91-
for (const [version, newVersion] of Object.entries(versions)) {
92-
const { stdout } = await exec(`./update.sh ${version}`);
93-
console.log(stdout);
94-
updatedVersions.push(newVersion.fullVersion);
95-
}
96-
97-
if (updatedVersions.length === 0) {
98-
console.log('No versions with musl builds were updated.');
99-
process.exit(0);
100-
}
101-
102-
const { stdout } = await exec(`git diff`);
103-
console.log(stdout);
104-
105-
return updatedVersions.join(', ');
145+
console.log('No Pull Request will be created.');
106146
}
147+
} catch (error) {
148+
console.error(error);
149+
process.exit(1);
107150
}

‎config‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)