forked from NVIDIA/OpenShell
-
Notifications
You must be signed in to change notification settings - Fork 0
284 lines (260 loc) · 9.59 KB
/
docker-build.yml
File metadata and controls
284 lines (260 loc) · 9.59 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
name: Docker Build
on:
workflow_call:
inputs:
component:
description: "Component to build (gateway, supervisor, cluster)"
required: true
type: string
timeout-minutes:
description: "Per-arch Docker image job timeout in minutes"
required: false
type: number
default: 20
push:
description: "Push image to registry"
required: false
type: boolean
default: true
platform:
description: "Target platform(s) for Docker build"
required: false
type: string
default: "linux/amd64,linux/arm64"
runner:
description: "Deprecated; per-arch native runners are selected automatically"
required: false
type: string
default: "build-amd64"
cargo-version:
description: "Pre-computed cargo version (skips internal git-based computation)"
required: false
type: string
default: ""
image-tag:
description: "Image tag base to build/push (defaults to the GitHub SHA)"
required: false
type: string
default: ""
env:
MISE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: read
packages: write
defaults:
run:
shell: bash
jobs:
resolve:
name: Resolve build plan
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.resolve.outputs.matrix }}
platform_count: ${{ steps.resolve.outputs.platform_count }}
arches: ${{ steps.resolve.outputs.arches }}
binary_component: ${{ steps.resolve.outputs.binary_component }}
binary_name: ${{ steps.resolve.outputs.binary_name }}
artifact_prefix: ${{ steps.resolve.outputs.artifact_prefix }}
image_tag_base: ${{ steps.resolve.outputs.image_tag_base }}
steps:
- name: Resolve component and platform matrix
id: resolve
run: |
set -euo pipefail
component="${{ inputs.component }}"
case "$component" in
gateway)
binary_component=gateway
binary_name=openshell-gateway
;;
supervisor|cluster)
binary_component=sandbox
binary_name=openshell-sandbox
;;
*)
echo "unsupported component: $component" >&2
exit 1
;;
esac
image_tag_base="${{ inputs['image-tag'] }}"
if [[ -z "$image_tag_base" ]]; then
image_tag_base="$GITHUB_SHA"
fi
platform_input="${{ inputs.platform }}"
platform_input="${platform_input//[[:space:]]/}"
if [[ -z "$platform_input" ]]; then
echo "platform input must not be empty" >&2
exit 1
fi
IFS=',' read -r -a platforms <<< "$platform_input"
matrix='{"include":['
arches=()
count=0
for platform in "${platforms[@]}"; do
case "$platform" in
linux/amd64)
arch=amd64
runner=linux-amd64-cpu8
;;
linux/arm64)
arch=arm64
runner=linux-arm64-cpu8
;;
*)
echo "unsupported platform: $platform" >&2
echo "supported platforms: linux/amd64, linux/arm64" >&2
exit 1
;;
esac
if [[ $count -gt 0 ]]; then
matrix+=','
fi
matrix+='{"platform":"'"$platform"'","arch":"'"$arch"'","runner":"'"$runner"'"}'
arches+=("$arch")
count=$((count + 1))
done
matrix+=']}'
{
echo "matrix=$matrix"
echo "platform_count=$count"
echo "arches=${arches[*]}"
echo "binary_component=$binary_component"
echo "binary_name=$binary_name"
echo "artifact_prefix=rust-binary-${component}-${binary_component}"
echo "image_tag_base=$image_tag_base"
} >> "$GITHUB_OUTPUT"
rust-binary:
name: Rust ${{ needs.resolve.outputs.binary_component }} (${{ matrix.arch }})
needs: resolve
permissions:
contents: read
packages: read
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.resolve.outputs.matrix) }}
uses: ./.github/workflows/shadow-rust-native-build.yml
with:
component: ${{ needs.resolve.outputs.binary_component }}
arch: ${{ matrix.arch }}
cargo-version: ${{ inputs['cargo-version'] }}
features: openshell-core/dev-settings
artifact-name: ${{ needs.resolve.outputs.artifact_prefix }}-linux-${{ matrix.arch }}
secrets: inherit
build:
name: Build ${{ inputs.component }} (${{ matrix.arch }})
needs: [resolve, rust-binary]
runs-on: ${{ matrix.runner }}
timeout-minutes: ${{ inputs['timeout-minutes'] }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.resolve.outputs.matrix) }}
container:
image: ghcr.io/nvidia/openshell/ci:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
options: --privileged
volumes:
- /var/run/docker.sock:/var/run/docker.sock
# Expose the nv-gha-runners buildkitd.toml registry mirror config
# inside the container so setup-buildx can read it.
- /etc/buildkit:/etc/buildkit:ro
env:
IMAGE_TAG: ${{ needs.resolve.outputs.platform_count == '1' && needs.resolve.outputs.image_tag_base || format('{0}-{1}', needs.resolve.outputs.image_tag_base, matrix.arch) }}
IMAGE_REGISTRY: ghcr.io/nvidia/openshell
DOCKER_PUSH: ${{ inputs.push && '1' || '0' }}
DOCKER_PLATFORM: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Mark workspace safe for git
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Install tools
run: mise install --locked
- name: Log in to GHCR
if: ${{ inputs.push }}
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
- name: Set up buildx (local driver)
uses: ./.github/actions/setup-buildx
with:
driver: local
buildkitd-config: /etc/buildkit/buildkitd.toml
- name: Download Rust binary artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.resolve.outputs.artifact_prefix }}-linux-${{ matrix.arch }}
path: prebuilt-rust-binary
- name: Stage Rust binary in Docker build context
run: |
set -euo pipefail
binary="${{ needs.resolve.outputs.binary_name }}"
download_dir="prebuilt-rust-binary"
stage="deploy/docker/.build/prebuilt-binaries/${{ matrix.arch }}"
found="$(find "$download_dir" -type f -name "$binary" -print -quit)"
if [[ -z "$found" ]]; then
echo "missing downloaded artifact file: $binary" >&2
find "$download_dir" -maxdepth 4 -type f -print >&2 || true
exit 1
fi
mkdir -p "$stage"
install -m 0755 "$found" "$stage/$binary"
ls -lh "$stage/"
- name: Build ${{ inputs.component }} image
env:
DOCKER_BUILDER: openshell
run: |
set -euo pipefail
mise exec -- tasks/scripts/docker-build-image.sh "${{ inputs.component }}" \
--cache-from "type=gha,scope=${{ inputs.component }}-${{ matrix.arch }}" \
--cache-to "type=gha,mode=max,scope=${{ inputs.component }}-${{ matrix.arch }}"
- name: Smoke check ${{ inputs.component }} image
if: ${{ !inputs.push }}
run: |
set -euo pipefail
image="${IMAGE_REGISTRY}/${{ inputs.component }}:${IMAGE_TAG}"
case "${{ inputs.component }}" in
gateway)
output="$(docker run --rm --platform "${{ matrix.platform }}" "$image" --version)"
echo "$output"
grep -q '^openshell-gateway ' <<<"$output"
;;
supervisor)
output="$(docker run --rm --platform "${{ matrix.platform }}" "$image" --version)"
echo "$output"
grep -q '^openshell-sandbox ' <<<"$output"
;;
cluster)
output="$(docker run --rm --platform "${{ matrix.platform }}" --entrypoint /opt/openshell/bin/openshell-sandbox "$image" --version)"
echo "$output"
grep -q '^openshell-sandbox ' <<<"$output"
;;
esac
merge:
name: Merge ${{ inputs.component }} manifest
needs: [resolve, build]
if: ${{ inputs.push && needs.resolve.outputs.platform_count != '1' }}
runs-on: linux-amd64-cpu8
timeout-minutes: 10
container:
image: ghcr.io/nvidia/openshell/ci:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
steps:
- name: Log in to GHCR
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
- name: Create multi-arch manifest
run: |
set -euo pipefail
image="ghcr.io/nvidia/openshell/${{ inputs.component }}"
refs=()
for arch in ${{ needs.resolve.outputs.arches }}; do
refs+=("${image}:${{ needs.resolve.outputs.image_tag_base }}-${arch}")
done
docker buildx imagetools create \
--prefer-index=false \
-t "${image}:${{ needs.resolve.outputs.image_tag_base }}" \
"${refs[@]}"