Skip to content

Commit 159f889

Browse files
committed
Update Dockerfile to use Node.js LTS and refactor push.js for platform handling
1 parent 8adf1a5 commit 159f889

File tree

2 files changed

+68
-44
lines changed

2 files changed

+68
-44
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:22-slim
1+
FROM node:lts-bookworm
22

33
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
44

push.js

+67-43
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,91 @@ import { $ } from 'bun';
33
const img = 'nozich/bunode'
44

55
async function main() {
6-
await $`docker pull ${img}:latest`
6+
await $`docker pull ${img}:latest`
77

8-
const inspect = await $`docker buildx inspect | grep 'Platforms:' | sed 's/Platforms: //'`.text();
8+
// linux/arm64, linux/amd64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/arm/v7, linux/arm/v6
9+
const inspect = await $`docker buildx inspect | grep 'Platforms:' | sed 's/Platforms: //'`.text();
910

10-
const platforms = inspect.split(',').map(e => e.trim()).map((p) => ({
11-
platform: p,
12-
os: p.split('/')[0],
13-
arch: p.split('/')[1],
14-
tag: p.replace(/[^a-zA-Z0-9]/g, '-').toLowerCase()
15-
}));
11+
// Manuelly set the platforms
12+
const inspects = [];
13+
if (inspect.includes('linux/arm64')) {
14+
inspects.push('linux/arm64');
15+
}
16+
if (inspect.includes('linux/amd64')) {
17+
inspects.push('linux/amd64');
18+
}
1619

17-
console.log(`platforms`, platforms.map((p) => p.tag).join(','));
20+
console.log(`inspects`, inspects);
1821

19-
const built = (await Promise.all(platforms.map(async ({ platform, tag }) => {
20-
const build = await $`docker buildx build --platform=${platform} -t ${img}:${tag} --push .`.text()
21-
.catch((e) => e);
22+
const platforms = inspects.split(',').map(e => e.trim()).map((p) => ({
23+
platform: p,
24+
os: p.split('/')[0],
25+
arch: p.split('/')[1],
26+
tag: p.replace(/[^a-zA-Z0-9]/g, '-').toLowerCase()
27+
}));
2228

23-
console.log(`[BUILD] [END] [${platform}] [${tag}] {exitCode: ${build.exitCode}}`);
29+
console.log(`platforms`, JSON.stringify(platforms));
30+
// console.log(`platforms`, platforms.map((p) => p.tag).join(','));
2431

25-
return (build.exitCode === 0) && tag
26-
}))).filter(Boolean);
32+
const built = (await Promise.all(platforms.map(async ({ platform, tag }) => {
33+
console.log({ platform, img, tag });
2734

28-
console.log(`built`, built);
35+
const build = await $`docker buildx build --platform=${platform} -t ${img}:${tag} --push .`.text()
36+
.catch((e) => e);
2937

30-
if (built.length === 0) {
31-
console.error('No images were built');
32-
return;
33-
}
38+
console.log({ platform, tag, build });
3439

35-
const currents = await fetch(`https://registry.hub.docker.com/v2/repositories/${img}/tags/`)
36-
.then((res) => res.json())
37-
.then((data) => data.results
38-
.find((r) => r.name === 'latest')
39-
.images.map((i) => ({
40-
...i,
41-
arch: i.architecture,
42-
tag: i.variant ? `${i.os}-${i.architecture}-${i.variant}` : `${i.os}-${i.architecture}`
43-
})));
40+
console.log(`[BUILD] [END] [${platform}] [${tag}] {exitCode: ${build.exitCode}}`);
4441

45-
const annotates = currents || []
42+
return (build.exitCode === 0) && tag
43+
}))).filter(Boolean);
4644

47-
const news = platforms.filter((p) => built.includes(p.tag))
45+
console.log(`built`, built);
4846

49-
news.forEach((p) => {
50-
if (annotates.find((a) => a.tag === p.tag)) return;
51-
annotates.push(p);
52-
});
47+
if (built.length === 0) {
48+
console.error('No images were built');
49+
return;
50+
}
5351

54-
console.log(`annotates`, annotates.map(({ tag, os, arch }) => ({ tag, os, arch })));
52+
const currentsFetch = await fetch(`https://registry.hub.docker.com/v2/repositories/${img}/tags/`)
53+
.then((res) => res.json())
54+
.then((data) => data.results);
5555

56-
const tags = annotates.map(({ tag }) => `${img}:${tag}`)
56+
console.log(`currentsFetch`, currentsFetch);
5757

58-
tags.unshift(`${img}:latest`)
58+
const currents = currentsFetch.find((r) => r.name === 'latest')
59+
.images.map((i) => ({
60+
...i,
61+
arch: i.architecture,
62+
tag: i.variant ? `${i.os}-${i.architecture}-${i.variant}` : `${i.os}-${i.architecture}`
63+
}));
5964

60-
await $`docker manifest create --amend ${tags}`;
65+
const annotates = currents || [];
6166

62-
await Promise.all(annotates.map(async ({ os, arch, tag }) => {
63-
return $`docker manifest annotate ${img}:latest ${img}:${tag} --os ${os} --arch ${arch}`;
64-
}));
67+
console.log(`annotates`, annotates);
6568

66-
await $`docker manifest push --purge ${img}:latest`
69+
const news = platforms.filter((p) => built.includes(p.tag));
70+
71+
console.log(`news`, news);
72+
73+
news.forEach((p) => {
74+
if (annotates.find((a) => a.tag === p.tag)) return;
75+
annotates.push(p);
76+
});
77+
78+
console.log(`annotates`, annotates.map(({ tag, os, arch }) => ({ tag, os, arch })));
79+
80+
const tags = annotates.map(({ tag }) => `${img}:${tag}`)
81+
82+
tags.unshift(`${img}:latest`)
83+
84+
await $`docker manifest create --amend ${tags}`;
85+
86+
await Promise.all(annotates.map(async ({ os, arch, tag }) => {
87+
return $`docker manifest annotate ${img}:latest ${img}:${tag} --os ${os} --arch ${arch}`;
88+
}));
89+
90+
await $`docker manifest push --purge ${img}:latest`
6791
}
6892

6993
main();

0 commit comments

Comments
 (0)