Skip to content

Commit ba4814d

Browse files
authored
Merge pull request #1470 from nschonni/js-stackbrew
chore: Convert to JS stackbrew and update 16 defaults
2 parents 49bb27b + 106a81b commit ba4814d

File tree

9 files changed

+459
-153
lines changed

9 files changed

+459
-153
lines changed

.github/workflows/official-pr.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ on:
1010
- "**/Dockerfile"
1111
- "**/architectures"
1212
- "**/docker-entrypoint.sh"
13-
- "generate-stackbrew-library.sh"
14-
- "functions.sh"
13+
- "stackbrew.js"
1514
- "config"
1615

1716
jobs:
@@ -36,7 +35,7 @@ jobs:
3635
- name: Generate Stackbrew for diff
3736
run: |
3837
cd docker-node
39-
./generate-stackbrew-library.sh > ../official-images/library/node
38+
./stackbrew.js > ../official-images/library/node
4039
4140
- name: Create PR in official-images
4241
id: create-pr

10/architectures

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

12/architectures

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

14/architectures

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

15/architectures

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

16/architectures

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

generate-stackbrew-library.sh

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

stackbrew.js

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
// Grab last git commit
7+
function getCommitHasForPath(path) {
8+
return require('child_process')
9+
.execSync(`git log -1 --format=%H HEAD -- ${path}`)
10+
.toString().trim()
11+
}
12+
13+
const stackbrewPath = path.basename(__filename);
14+
15+
// Header
16+
let stackbrew = `# this file is generated via https://github.com/nodejs/docker-node/blob/${getCommitHasForPath(stackbrewPath)}/${stackbrewPath}
17+
18+
Maintainers: The Node.js Docker Team <https://github.com/nodejs/docker-node> (@nodejs)
19+
GitRepo: https://github.com/nodejs/docker-node.git
20+
GitFetch: refs/heads/main\n`;
21+
22+
// Loop versions
23+
24+
const config = require('./versions.json');
25+
26+
const versions = Object.keys(config).reverse()
27+
28+
const now = new Date().getTime()
29+
const aplineRE = new RegExp(/alpine*/);
30+
const slimRE = new RegExp(/\*-slim/);
31+
32+
for(version of versions) {
33+
let lts = new Date(config[version].lts).getTime();
34+
let maintenance = new Date(config[version].maintenance).getTime();
35+
let isCurrent = lts > now;
36+
let isLTS = (maintenance > now) && (now > lts);
37+
let codename = config[version].codename
38+
let defaultAlpine = config[version]['alpine-default']
39+
let defaultDebian = config[version]['debian-default']
40+
let variants = config[version].variants
41+
let fullversion;
42+
for(variant in variants) {
43+
let dockerfilePath = path.join(version, variant, 'Dockerfile');
44+
let isAlpine = aplineRE.test(variant)
45+
let isSlim = slimRE.test(variant)
46+
let isDefaultSlim = new RegExp(`${defaultDebian}-slim`).test(variant)
47+
48+
// Get full version from the first Dockerfile
49+
if (!fullversion) {
50+
let dockerfile = fs.readFileSync(dockerfilePath, 'utf-8')
51+
fullversion = dockerfile.match(/ENV NODE_VERSION (?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/)
52+
}
53+
let tags = [
54+
`${fullversion.groups.major}.${fullversion.groups.minor}.${fullversion.groups.patch}-${variant}`,
55+
`${fullversion.groups.major}.${fullversion.groups.minor}-${variant}`,
56+
`${fullversion.groups.major}-${variant}`,
57+
]
58+
59+
if (codename) {
60+
tags.push(`${codename}-${variant}`)
61+
}
62+
63+
if (variant === defaultAlpine) {
64+
tags.push(`${fullversion.groups.major}.${fullversion.groups.minor}.${fullversion.groups.patch}-alpine`)
65+
tags.push(`${fullversion.groups.major}.${fullversion.groups.minor}-alpine`)
66+
tags.push(`${fullversion.groups.major}-alpine`)
67+
if (codename) {
68+
tags.push(`${codename}-alpine`)
69+
}
70+
}
71+
72+
if (variant === defaultDebian) {
73+
tags.push(`${fullversion.groups.major}.${fullversion.groups.minor}.${fullversion.groups.patch}`)
74+
tags.push(`${fullversion.groups.major}.${fullversion.groups.minor}`)
75+
tags.push(`${fullversion.groups.major}`)
76+
if (isSlim) {
77+
tags.push(`${fullversion.groups.major}.${fullversion.groups.minor}.${fullversion.groups.patch}-slim`)
78+
tags.push(`${fullversion.groups.major}.${fullversion.groups.minor}-slim`)
79+
tags.push(`${fullversion.groups.major}-slim`)
80+
}
81+
if (codename) {
82+
tags.push(`${codename}`)
83+
}
84+
}
85+
if (isDefaultSlim) {
86+
tags.push(`${fullversion.groups.major}.${fullversion.groups.minor}.${fullversion.groups.patch}-slim`)
87+
tags.push(`${fullversion.groups.major}.${fullversion.groups.minor}-slim`)
88+
tags.push(`${fullversion.groups.major}-slim`)
89+
if (codename) {
90+
tags.push(`${codename}-slim`)
91+
}
92+
}
93+
94+
if (isCurrent) {
95+
if (variant === defaultAlpine) {
96+
tags.push(variant)
97+
tags.push(`${fullversion.groups.major}.${fullversion.groups.minor}.${fullversion.groups.patch}-alpine`)
98+
tags.push(`${fullversion.groups.major}.${fullversion.groups.minor}-alpine`)
99+
tags.push(`${fullversion.groups.major}-alpine`)
100+
tags.push('alpine')
101+
tags.push('current-alpine')
102+
}
103+
if (variant === defaultDebian) {
104+
tags.push(variant)
105+
tags.push('latest')
106+
tags.push('current')
107+
}
108+
if (isAlpine) {
109+
tags.push(`${variant}`)
110+
tags.push(`current-${variant}`)
111+
}
112+
if (!isAlpine) {
113+
tags.push(`${variant}`)
114+
tags.push(`current-${variant}`)
115+
}
116+
if (isDefaultSlim) {
117+
tags.push('slim')
118+
tags.push('current-slim')
119+
}
120+
}
121+
122+
if (isLTS) {
123+
tags.push(`lts-${variant}`)
124+
if (variant === defaultAlpine) {
125+
}
126+
if (variant === defaultDebian) {
127+
tags.push('lts')
128+
if (codename) {
129+
tags.push(`lts-${codename}`)
130+
}
131+
}
132+
if (isDefaultSlim) {
133+
tags.push(`lts-slim`)
134+
}
135+
if (variant === defaultAlpine) {
136+
tags.push(`lts-alpine`)
137+
}
138+
}
139+
140+
// remove duplicates
141+
tags = tags.filter((x, i, a) => a.indexOf(x) == i)
142+
tags = tags.sort()
143+
144+
stackbrew += `\nTags: ${tags.join(', ')}\n`
145+
stackbrew += `Architectures: ${config[version].variants[variant].join(', ')}\n`
146+
stackbrew += `GitCommit: ${getCommitHasForPath(dockerfilePath)}\n`
147+
stackbrew += `Directory: ${version}/${variant}\n`
148+
}
149+
}
150+
151+
// output
152+
console.log(stackbrew)

0 commit comments

Comments
 (0)