Repository navigation
Expand file tree
/
Copy pathstackbrew.mjs
More file actions
executable file
·184 lines (156 loc) · 5.69 KB
/
Copy pathstackbrew.mjs
File metadata and controls
executable file
·184 lines (156 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env node
import { readFileSync, writeFileSync } from 'node:fs';
import { basename, resolve } from 'node:path';
import { execSync } from 'node:child_process';
// Grab last git commit
function getCommitHasForPath(path) {
return execSync(`git log -1 --format=%H HEAD -- ${path}`).toString().trim();
}
// Grab nodejs/Release values as the authoritative start/maintenance/end dates
const releaseTimes = await fetch(
'https://raw.githubusercontent.com/nodejs/Release/refs/heads/main/schedule.json',
);
const releaseJson = await releaseTimes.json();
// Grab the nodejs.org index.json as the authoritative Codename values, since that can lag the Release repo JSON
const availableVersions = await fetch(
'https://nodejs.org/download/release/index.json',
);
const officialIndexJson = await availableVersions.json();
const stackbrewPath = basename(import.meta.filename);
// Header
let stackbrew = `# this file is generated via https://github.com/nodejs/docker-node/blob/${getCommitHasForPath(stackbrewPath)}/${stackbrewPath}
Maintainers: The Node.js Docker Team <https://github.com/nodejs/docker-node> (@nodejs)
GitRepo: https://github.com/nodejs/docker-node.git
GitFetch: refs/heads/main\n`;
const config = JSON.parse(readFileSync('versions.json'));
const localVersions = Object.keys(config).reverse();
let midnight = new Date();
midnight.setHours(0, 0, 0, 0);
const now = midnight.getTime();
let foundLTS = false;
let foundCurrent = false;
for (const majorVersion of localVersions) {
let releaseRepoInfo = releaseJson[`v${majorVersion}`];
let nodejsOrgReleaseInfo = officialIndexJson.find((indexVersion) =>
indexVersion.version.startsWith(`v${majorVersion}`),
);
let currentStart = new Date(`${releaseRepoInfo.start}T00:00:00.00`).getTime();
// First Alpha build is the only active one, and when the "start" of the release hasn't cut over
let isAlpha = nodejsOrgReleaseInfo.version.includes('alpha');
// The Current/Latest release is the first non-Alpha major that has hit it's "start" date
let isCurrent = foundCurrent
? false
: !isAlpha && (isNaN(currentStart) || now >= currentStart);
foundCurrent |= isCurrent;
let codename = nodejsOrgReleaseInfo.lts
? nodejsOrgReleaseInfo.lts.toLowerCase()
: '';
// The LTS tag is only set on the most recent LTS release
let isLTS = foundLTS ? false : codename !== '';
foundLTS |= isLTS;
let defaultAlpine = config[majorVersion]['alpine-default'];
let defaultDebian = config[majorVersion]['debian-default'];
let defaultSlim = `${config[majorVersion]['debian-default']}-slim`;
let variants = config[majorVersion].variants;
for (const variant in variants) {
let tags;
if (isAlpha) {
// Only push explicit variants during the Alpha phase
tags = [`${nodejsOrgReleaseInfo.version.substring(1)}-${variant}`];
} else {
let fullVersion = nodejsOrgReleaseInfo.version.match(
/v(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/,
);
tags = [
`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-${variant}`,
`${fullVersion.groups.major}.${fullVersion.groups.minor}-${variant}`,
`${fullVersion.groups.major}-${variant}`,
];
if (codename) {
tags.push(`${codename}-${variant}`);
}
if (variant === defaultAlpine) {
tags.push(
`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-alpine`,
);
tags.push(
`${fullVersion.groups.major}.${fullVersion.groups.minor}-alpine`,
);
tags.push(`${fullVersion.groups.major}-alpine`);
if (codename) {
tags.push(`${codename}-alpine`);
}
if (isCurrent) {
tags.push('alpine');
tags.push('current-alpine');
}
if (isLTS) {
tags.push(`lts-alpine`);
}
} else if (variant === defaultDebian) {
tags.push(
`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}`,
);
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}`);
tags.push(`${fullVersion.groups.major}`);
if (codename) {
tags.push(`${codename}`);
}
if (isCurrent) {
tags.push(variant);
tags.push('latest');
tags.push('current');
}
if (isLTS) {
tags.push('lts');
if (codename) {
tags.push(`lts-${codename}`);
}
}
} else if (variant === defaultSlim) {
tags.push(
`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-slim`,
);
tags.push(
`${fullVersion.groups.major}.${fullVersion.groups.minor}-slim`,
);
tags.push(`${fullVersion.groups.major}-slim`);
if (codename) {
tags.push(`${codename}-slim`);
}
if (isCurrent) {
tags.push('slim');
tags.push('current-slim');
}
if (isLTS) {
tags.push(`lts-slim`);
}
}
if (isCurrent) {
tags.push(`${variant}`);
tags.push(`current-${variant}`);
}
if (isLTS) {
tags.push(`lts-${variant}`);
}
}
stackbrew += `
Tags: ${tags
.filter((x, i, a) => a.indexOf(x) == i)
.sort()
.join(', ')}
Architectures: ${config[majorVersion].variants[variant].join(', ')}
GitCommit: ${getCommitHasForPath(`${majorVersion}/${variant}`)}
Directory: ${`${majorVersion}/${variant}`}\n`;
}
}
try {
const outputFile = process.argv[2];
if (outputFile) {
writeFileSync(resolve(outputFile), stackbrew);
} else {
console.log(stackbrew);
}
} catch (ex) {
console.error("Couldn't handle output", ex);
}