Repository navigation
285 lines (262 loc) · 12.8 KB
/
Copy pathbuild-image.yaml
File metadata and controls
285 lines (262 loc) · 12.8 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# Reusable workflow for building a single multi-arch image
name: "Build Image"
on:
workflow_call:
inputs:
image:
description: "Image name (e.g., nebari-data-science-pack-jupyterlab)"
required: true
type: string
target:
description: "Dockerfile target"
required: true
type: string
build_amd64:
description: "Build for linux/amd64"
required: false
default: true
type: boolean
build_arm64:
description: "Build for linux/arm64"
required: false
default: true
type: boolean
base_image:
description: "Base image"
required: false
default: "ubuntu:24.04"
type: string
gpu:
description: "GPU build"
required: false
default: false
type: boolean
nebi_image:
description: "Nebi Docker image to copy binary from (e.g., quay.io/nebari/nebi:sha-abc). Leave empty to use GitHub release."
required: false
default: ""
type: string
smoke_test_labextensions:
description: "After each arch build, run `jupyter labextension list` in the pushed image and assert the extensions pinned in images/jupyterlab/pixi.toml are enabled at their pinned versions. Enable for every image built from the jupyterlab Dockerfile target (including the GPU variant — it installs the same pixi.toml). Skipped on fork PRs (no pushed image to run)."
required: false
default: false
type: boolean
secrets:
QUAY_TOKEN:
required: false
env:
DOCKER_ORG: nebari
# Fork PRs skip docker login, push, and the merge job:
# - secrets.QUAY_TOKEN is never exposed to fork-event workflows
# (login-action errors with "Username and password required")
# - pushing fork-built images to our public registry is a
# supply-chain risk (see issue #86)
# Fork PRs still build (no push) so the Dockerfile/pixi config
# is validated. Same-repo PRs and non-PR events are unchanged.
#
# NOTE: this env var is referenced from step-level `if:` only.
# GitHub Actions does not expose the `env` context to job-level
# `if:` expressions, so the `merge` job inlines the same condition
# directly. Keep the two in sync.
IS_FORK_PR: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true }}
jobs:
build-amd64:
name: "Build (linux/amd64)"
if: inputs.build_amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
- uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
if: env.IS_FORK_PR != 'true'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
if: env.IS_FORK_PR != 'true'
with:
registry: quay.io
username: ${{ vars.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: "Build (and push by digest when not a fork PR)"
id: build
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
with:
context: ./images
file: images/Dockerfile
target: ${{ inputs.target }}
platforms: linux/amd64
outputs: ${{ env.IS_FORK_PR != 'true' && format('type=image,"name=ghcr.io/{0}/{1},quay.io/{2}/{1}",push-by-digest=true,name-canonical=true,push=true', github.repository_owner, inputs.image, env.DOCKER_ORG) || '' }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/${{ inputs.image }}:cache-linux-amd64
cache-to: ${{ github.event_name != 'pull_request' && format('type=registry,ref=ghcr.io/{0}/{1}:cache-linux-amd64,mode=max', github.repository_owner, inputs.image) || '' }}
build-args: |
BASE_IMAGE=${{ inputs.base_image }}
GPU=${{ inputs.gpu }}
NEBI_IMAGE=${{ inputs.nebi_image }}
- name: "Smoke test: labextensions enabled at pinned versions"
if: env.IS_FORK_PR != 'true' && inputs.smoke_test_labextensions
run: |
ref="ghcr.io/${{ github.repository_owner }}/${{ inputs.image }}@${{ steps.build.outputs.digest }}"
# `jupyter labextension list` writes to stderr and colorizes the status
# words unconditionally (jupyter_server.extension.serverextension
# GREEN_ENABLED / RED_DISABLED / RED_X — guarded only by os.name != "nt"),
# so merge stderr and strip SGR sequences before matching. Keep grep -F
# substring matching: the real line has a trailing "(python, <pkg>)" and
# may carry "*" or a lock emoji after OK.
if ! out=$(docker run --rm "$ref" jupyter labextension list 2>&1); then
printf '%s\n' "$out"
echo "::error::could not run 'jupyter labextension list' in $ref"
exit 1
fi
plain=$(printf '%s\n' "$out" | sed -E 's/\x1b\[[0-9;]*m//g')
printf '%s\n' "$plain"
# Extensions whose pixi.toml pin name matches their labextension name.
# The list is hardcoded rather than derived from pixi.toml because the
# mapping isn't mechanical (jupyterlab_nvdashboard ships the extension
# as jupyterlab-nvdashboard; jhub-apps isn't a labextension at all).
for ext in jupyterlab-launchpad jupyterlab-nebari-mode jupyterlab-gallery jupyterlab-jhub-apps; do
expected=$(sed -nE "s/^${ext} = \"==([^\"]+)\"\$/\\1/p" images/jupyterlab/pixi.toml)
test -n "$expected" || { echo "::error::could not read exact ${ext} pin from images/jupyterlab/pixi.toml"; exit 1; }
grep -Fq " ${ext} v${expected} enabled OK" <<< "$plain" || {
echo "::error::${ext} v${expected} is not 'enabled OK' in $ref"
exit 1
}
done
- name: "Export digest"
if: env.IS_FORK_PR != 'true'
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: "Upload digest"
if: env.IS_FORK_PR != 'true'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ${{ inputs.image }}-digest-linux-amd64
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
build-arm64:
name: "Build (linux/arm64)"
if: inputs.build_arm64
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
- uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
if: env.IS_FORK_PR != 'true'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
if: env.IS_FORK_PR != 'true'
with:
registry: quay.io
username: ${{ vars.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: "Build (and push by digest when not a fork PR)"
id: build
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
with:
context: ./images
file: images/Dockerfile
target: ${{ inputs.target }}
platforms: linux/arm64
outputs: ${{ env.IS_FORK_PR != 'true' && format('type=image,"name=ghcr.io/{0}/{1},quay.io/{2}/{1}",push-by-digest=true,name-canonical=true,push=true', github.repository_owner, inputs.image, env.DOCKER_ORG) || '' }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/${{ inputs.image }}:cache-linux-arm64
cache-to: ${{ github.event_name != 'pull_request' && format('type=registry,ref=ghcr.io/{0}/{1}:cache-linux-arm64,mode=max', github.repository_owner, inputs.image) || '' }}
build-args: |
BASE_IMAGE=${{ inputs.base_image }}
GPU=${{ inputs.gpu }}
NEBI_IMAGE=${{ inputs.nebi_image }}
- name: "Smoke test: labextensions enabled at pinned versions"
if: env.IS_FORK_PR != 'true' && inputs.smoke_test_labextensions
run: |
ref="ghcr.io/${{ github.repository_owner }}/${{ inputs.image }}@${{ steps.build.outputs.digest }}"
# `jupyter labextension list` writes to stderr and colorizes the status
# words unconditionally (jupyter_server.extension.serverextension
# GREEN_ENABLED / RED_DISABLED / RED_X — guarded only by os.name != "nt"),
# so merge stderr and strip SGR sequences before matching. Keep grep -F
# substring matching: the real line has a trailing "(python, <pkg>)" and
# may carry "*" or a lock emoji after OK.
if ! out=$(docker run --rm "$ref" jupyter labextension list 2>&1); then
printf '%s\n' "$out"
echo "::error::could not run 'jupyter labextension list' in $ref"
exit 1
fi
plain=$(printf '%s\n' "$out" | sed -E 's/\x1b\[[0-9;]*m//g')
printf '%s\n' "$plain"
# Extensions whose pixi.toml pin name matches their labextension name.
# The list is hardcoded rather than derived from pixi.toml because the
# mapping isn't mechanical (jupyterlab_nvdashboard ships the extension
# as jupyterlab-nvdashboard; jhub-apps isn't a labextension at all).
for ext in jupyterlab-launchpad jupyterlab-nebari-mode jupyterlab-gallery jupyterlab-jhub-apps; do
expected=$(sed -nE "s/^${ext} = \"==([^\"]+)\"\$/\\1/p" images/jupyterlab/pixi.toml)
test -n "$expected" || { echo "::error::could not read exact ${ext} pin from images/jupyterlab/pixi.toml"; exit 1; }
grep -Fq " ${ext} v${expected} enabled OK" <<< "$plain" || {
echo "::error::${ext} v${expected} is not 'enabled OK' in $ref"
exit 1
}
done
- name: "Export digest"
if: env.IS_FORK_PR != 'true'
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: "Upload digest"
if: env.IS_FORK_PR != 'true'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ${{ inputs.image }}-digest-linux-arm64
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: "Merge"
runs-on: ubuntu-latest
# Fork PRs have nothing to merge (no digests pushed); skip entirely.
# Inlined because job-level `if:` cannot read the `env` context —
# keep this expression in sync with workflow-level IS_FORK_PR.
if: "!cancelled() && !failure() && !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)"
needs: [build-amd64, build-arm64]
steps:
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: /tmp/digests
pattern: ${{ inputs.image }}-digest-*
merge-multiple: true
- uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
- uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: quay.io
username: ${{ vars.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: "Generate tags"
id: meta
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ inputs.image }}
quay.io/${{ env.DOCKER_ORG }}/${{ inputs.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=sha,prefix=sha-
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
- name: "Create manifest list and push"
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf 'ghcr.io/${{ github.repository_owner }}/${{ inputs.image }}@sha256:%s ' *)
- name: "Inspect"
run: docker buildx imagetools inspect 'ghcr.io/${{ github.repository_owner }}/${{ inputs.image }}:${{ steps.meta.outputs.version }}'