Repository navigation
Expand file tree
/
Copy pathbuild.ts
More file actions
112 lines (95 loc) · 4.17 KB
/
Copy pathbuild.ts
File metadata and controls
112 lines (95 loc) · 4.17 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
import { $ } from 'bun'
// constants
const pnpmFile = './configuration/pnpm.json';
const tagsFile = './configuration/tags.json';
const [, , distribution] = Bun.argv;
// utilities
const getPnpmVersion = async () => {
const json = await Bun.file(pnpmFile).json();
const version = json[distribution] as string;
if (typeof version !== 'string' || !version?.length) {
throw new Error(`Invalid pnpm version found: '${version}' in '${JSON.stringify(json)}\n'`);
}
return version;
}
const getImageTags = async () => {
const json = await Bun.file(tagsFile).json();
const node = json[distribution] as string;
if (typeof node !== 'string' || !node?.length || !node.endsWith('-alpine')) {
throw new Error(`Invalid node tag found: '${node}' in '${JSON.stringify(json)}\n'`);
}
return { node };
}
// business logic
const [pnpm, tag] = await Promise.all([getPnpmVersion(), getImageTags()]);
const [patch] = tag.node.split('-');
const [major, min] = patch.split('.')
const minor = `${major}.${min}`
if (Bun.env.GITHUB_ACTIONS === 'true') {
const {
CONTAINER_REGISTRY_TOKEN,
CONTAINER_REGISTRY_USERNAME,
DOCKER_REGISTRY_TOKEN,
DOCKER_REGISTRY_USERNAME,
QUAY_REGISTRY_TOKEN,
QUAY_REGISTRY_USERNAME,
} = Bun.env;
// hack to pull first without authentication to avoid even more rate limits
await $`docker buildx build \
--build-arg BUILD_DATE=${await $`date -u +"%Y-%m-%dT%H:%M:%SZ"`.text()} \
--build-arg NODE_VERSION=${patch} \
--build-arg PNPM_VERSION=${pnpm} \
--build-arg VCS_REF=${await $`git rev-parse --short HEAD`.text()} \
--platform linux/amd64,linux/arm64 \
--progress=plain \
./${distribution}`;
await $`echo ${CONTAINER_REGISTRY_TOKEN} | docker login ghcr.io -u ${CONTAINER_REGISTRY_USERNAME} --password-stdin`;
await $`echo ${DOCKER_REGISTRY_TOKEN} | docker login -u ${DOCKER_REGISTRY_USERNAME} --password-stdin`;
await $`echo ${QUAY_REGISTRY_TOKEN} | docker login quay.io -u ${QUAY_REGISTRY_USERNAME} --password-stdin`;
await $`docker buildx build \
--build-arg BUILD_DATE=${await $`date -u +"%Y-%m-%dT%H:%M:%SZ"`.text()} \
--build-arg NODE_VERSION=${patch} \
--build-arg PNPM_VERSION=${pnpm} \
--build-arg VCS_REF=${await $`git rev-parse --short HEAD`.text()} \
--push \
--platform linux/amd64,linux/arm64 \
--progress=plain \
-t ghcr.io/panascais-docker/node/node:${distribution} \
-t ghcr.io/panascais-docker/node/node:${major} \
-t ghcr.io/panascais-docker/node/node:${minor} \
-t ghcr.io/panascais-docker/node/node:${patch} \
-t panascais/node:${distribution} \
-t panascais/node:${major} \
-t panascais/node:${minor} \
-t panascais/node:${patch} \
-t quay.io/panascais/node:${distribution} \
-t quay.io/panascais/node:${major} \
-t quay.io/panascais/node:${minor} \
-t quay.io/panascais/node:${patch} \
./${distribution}`;
} else {
await $`docker buildx create --name orb --use &> /dev/null || docker buildx use orb`;
await $`docker buildx inspect --bootstrap &> /dev/null`;
await $`docker buildx install &> /dev/null || true`;
await $`docker buildx build \
--build-arg BUILD_DATE=${await $`date -u +"%Y-%m-%dT%H:%M:%SZ"`.text()} \
--build-arg NODE_VERSION=${patch} \
--build-arg PNPM_VERSION=${pnpm} \
--build-arg VCS_REF=${await $`git rev-parse --short HEAD`.text()} \
--load \
--platform linux/arm64 \
--progress=plain \
-t ghcr.io/panascais-docker/node/node:${distribution} \
-t ghcr.io/panascais-docker/node/node:${major} \
-t ghcr.io/panascais-docker/node/node:${minor} \
-t ghcr.io/panascais-docker/node/node:${patch} \
-t panascais/node:${distribution} \
-t panascais/node:${major} \
-t panascais/node:${minor} \
-t panascais/node:${patch} \
-t quay.io/panascais/node:${distribution} \
-t quay.io/panascais/node:${major} \
-t quay.io/panascais/node:${minor} \
-t quay.io/panascais/node:${patch} \
./${distribution}`;
}