-
Notifications
You must be signed in to change notification settings - Fork 1
216 lines (188 loc) · 7.1 KB
/
Copy pathupdate-current-image.yml
File metadata and controls
216 lines (188 loc) · 7.1 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: Update Image
on:
schedule:
- cron: '30 0 * * *'
workflow_dispatch:
inputs:
node_version:
description: 'Node.js version to build (e.g., 20.10.0). Leave empty to auto-detect latest.'
required: false
type: string
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
env:
IMAGE_NAME: node-minimal
GHCR_IMAGE: ghcr.io/chorrell/node-minimal
permissions:
contents: read
jobs:
check_version:
runs-on: ubuntu-latest
outputs:
NODE_VERSION: ${{ steps.get_version.outputs.NODE_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Validate and Get NODE_VERSION
id: get_version
env:
GITHUB_EVENT_INPUTS_NODE_VERSION: ${{ github.event.inputs.node_version }}
run: |
if [[ -n "${GITHUB_EVENT_INPUTS_NODE_VERSION}" ]]; then
INPUT_VERSION="${GITHUB_EVENT_INPUTS_NODE_VERSION}"
if ! [[ $INPUT_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid version format '$INPUT_VERSION'. Expected format: X.Y.Z (e.g., 20.10.0)" >&2
exit 1
fi
NODE_VERSION="$INPUT_VERSION"
else
NODE_VERSION=$(./check-missing-versions.sh | tail -1)
fi
echo "NODE_VERSION=$NODE_VERSION" >> "$GITHUB_OUTPUT"
if [[ -n "$NODE_VERSION" ]]; then
echo "Building Node.js version: $NODE_VERSION"
else
echo "No new Node.js versions to build"
fi
build:
strategy:
matrix:
os:
- ubuntu-24.04
- ubuntu-24.04-arm
platform:
- amd64
- arm64
exclude:
- os: ubuntu-24.04
platform: arm64
- os: ubuntu-24.04-arm
platform: amd64
needs: check_version
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
if: needs.check_version.outputs.NODE_VERSION
env:
NODE_VERSION: ${{needs.check_version.outputs.NODE_VERSION}}
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: ccache
uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23
with:
key: ${{ matrix.os }}-${{ matrix.platform }}
max-size: 10G
- name: Configure ccache
run: |
ccache --set-config=sloppiness=time_macros,locale,include_file_ctime,include_file_mtime
ccache --set-config=hash_dir=false
ccache -p
- name: Set and Display Versions
run: |
MAJOR_VERSION=$(echo "$NODE_VERSION" | cut -d'.' -f 1)
echo "MAJOR_VERSION=$MAJOR_VERSION" >> "$GITHUB_ENV"
echo "Building Node.js version: $NODE_VERSION (major: $MAJOR_VERSION)"
- name: Build Node
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
which gcc
./build.sh -n "$NODE_VERSION"
ccache -s
cp "node-v${NODE_VERSION}/out/Release/node" node
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
- name: Login to DockerHub
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build test image
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
env:
DOCKER_BUILD_SUMMARY: false
with:
context: .
platforms: linux/${{ matrix.platform }}
load: true
tags: ${{ env.IMAGE_NAME }}-${{ env.NODE_VERSION }}
cache-from: type=gha,scope=${{ matrix.platform }}
cache-to: type=gha,mode=max,scope=${{ matrix.platform }}
- name: Test Image
run: docker run --rm "${IMAGE_NAME}-${NODE_VERSION}" -e "console.log('Hello from Node.js ' + process.version)"
- name: Build and push per-platform image
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: .
platforms: linux/${{ matrix.platform }}
push: true
provenance: mode=max
sbom: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:build-${{ github.run_id }}-${{ matrix.platform }}
${{ env.GHCR_IMAGE }}:build-${{ github.run_id }}-${{ matrix.platform }}
cache-from: type=gha,scope=${{ matrix.platform }}
merge:
needs: [check_version, build]
runs-on: ubuntu-latest
permissions:
packages: write
env:
NODE_VERSION: ${{ needs.check_version.outputs.NODE_VERSION }}
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
- name: Login to DockerHub
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set major version
run: echo "MAJOR_VERSION=$(echo "$NODE_VERSION" | cut -d'.' -f 1)" >> "$GITHUB_ENV"
- name: Create DockerHub multi-arch manifests
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
RUN_ID: ${{ github.run_id }}
run: |
REPO="${DOCKERHUB_USERNAME}/${IMAGE_NAME}"
docker buildx imagetools create \
-t "${REPO}:${NODE_VERSION}" \
-t "${REPO}:${MAJOR_VERSION}" \
-t "${REPO}:current" \
-t "${REPO}:latest" \
"${REPO}:build-${RUN_ID}-amd64" \
"${REPO}:build-${RUN_ID}-arm64"
- name: Create GHCR multi-arch manifests
env:
RUN_ID: ${{ github.run_id }}
run: |
docker buildx imagetools create \
-t "${GHCR_IMAGE}:${NODE_VERSION}" \
-t "${GHCR_IMAGE}:${MAJOR_VERSION}" \
-t "${GHCR_IMAGE}:current" \
-t "${GHCR_IMAGE}:latest" \
"${GHCR_IMAGE}:build-${RUN_ID}-amd64" \
"${GHCR_IMAGE}:build-${RUN_ID}-arm64"
- name: Inspect manifest
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
run: |
docker buildx imagetools inspect "${DOCKERHUB_USERNAME}/${IMAGE_NAME}:${NODE_VERSION}"