-
Notifications
You must be signed in to change notification settings - Fork 8
214 lines (192 loc) · 8.75 KB
/
Copy pathruntime-image.yaml
File metadata and controls
214 lines (192 loc) · 8.75 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
# Copyright 2026 FlagOS Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Builid Runtime Image (manual)
# The run title self-labels each dispatch so v1 (build, no flag_gems) and v2
# (full, with flag_gems) are told apart at a glance in the Actions run list —
# the two produce identical job names, so without this they are indistinguishable.
# Shows: layer (v1/v2) · backend · push/no-push · no-cache · pinned flaggems ver.
run-name: >-
${{ inputs.no_flaggems && 'v1 build' || 'v2 flag_gems' }}
· ${{ inputs.backend }}
· ${{ inputs.push && 'push' || 'no-push' }}${{ inputs.no_cache && ' · no-cache' || '' }}${{ inputs.flaggems != '' && format(' · fg={0}', inputs.flaggems) || '' }}
# Runtime images are built on demand, not on every push/PR. They layer
# FlagGems (pure Python + optional C++ extension) on top of a base image
# via wheel install. Trigger this manually to build a backend (or all).
on:
workflow_dispatch:
inputs:
backend:
description: 'Backend to build (e.g. nvidia-cuda12.8), or "all"'
type: string
default: all
push:
description: 'Push image(s) to the registry'
type: boolean
default: false
flaggems:
description: 'FlagGems wheel version to install (e.g. 5.3.2)'
type: string
default: ''
no_flaggems:
description: 'Skip flag_gems install — produce -build image'
type: boolean
default: false
skip_cpp:
description: 'Skip flag_gems C++ extension install (Python wheel only)'
type: boolean
default: false
no_cache:
description: 'Disable Docker build cache (use for rebuild wheels with same version)'
type: boolean
default: false
jobs:
authorize:
# Only accounts listed in .github/builders.txt may trigger this workflow
# manually; see .github/actions/check-trigger-author for the check.
# actions/checkout is required: local composite actions are resolved from
# the workspace, so the repo must exist before the action step runs.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/check-trigger-author
set-matrix:
needs: authorize
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
harbor_host: ${{ steps.harbor-host.outputs.host }}
runtime_prereqs: ${{ steps.runtime-prereqs.outputs.prereqs }}
steps:
- name: Checkout Code
uses: actions/checkout@v7
- name: Install PyYAML
run: python3 -m pip install --user pyyaml
- id: set-matrix
shell: bash
run: |
if [[ "${{ inputs.backend }}" == "all" ]]; then
python3 scripts/generate_matrix.py --runtime > matrix.json
else
python3 scripts/generate_matrix.py --runtime ${{ inputs.backend }} > matrix.json
fi
cat matrix.json
echo "matrix=$(jq -c . matrix.json)" >> "$GITHUB_OUTPUT"
- id: runtime-prereqs
shell: bash
run: |
prereqs=$(python3 -c "import yaml; print(' '.join(yaml.safe_load(open('configs.yaml'))['runtime_prereqs']))")
echo "prereqs=$prereqs" >> "$GITHUB_OUTPUT"
- id: harbor-host
shell: bash
run: |
host=$(python3 -c "import yaml;print(yaml.safe_load(open('.github/build-config.yml'))['registry']['host'])")
echo "host=$host" >> "$GITHUB_OUTPUT"
build-matrix:
needs: set-matrix
if: ${{ fromJSON(needs.set-matrix.outputs.matrix).include[0] != null }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.set-matrix.outputs.matrix) }}
name: runtime-${{ matrix.name }}
runs-on: ${{ fromJSON(matrix.runson) }}
steps:
- name: Checkout build-infra
uses: actions/checkout@v7
- name: Harbor login (push only)
if: ${{ inputs.push }}
env:
HARBOR_USER: ${{ secrets.HARBOR_USER }}
HARBOR_PW: ${{ secrets.HARBOR_PASSWORD }}
run: |
host="${{ needs.set-matrix.outputs.harbor_host }}"
for i in 1 2 3; do
if printf '%s' "$HARBOR_PW" | docker login "$host" -u "$HARBOR_USER" --password-stdin; then
exit 0
fi
echo "Harbor login attempt $i failed, retrying..."
sleep 30
done
echo "::error::Harbor login failed after 3 attempts"
exit 1
- name: Env + parameters
run: |
flaggems_ver="${{ inputs.flaggems }}"
[[ -z "$flaggems_ver" ]] && flaggems_ver="${{ matrix.flaggems_version }}"
echo "hostname: $(hostname)"
echo "arch: $(uname -m)"
docker version --format 'docker: {{.Server.Version}}' 2>/dev/null || echo "docker: unavailable"
echo "base_image: ${{ matrix.base_image }}"
echo "image_tag: ${{ matrix.image_tag }}"
echo "flaggems_version: ${flaggems_ver}"
echo "no_flaggems: ${{ inputs.no_flaggems }}"
echo "python_version: ${{ matrix.python_version }}"
echo "deps: ${{ matrix.deps }}"
echo "cpp_extra: ${{ matrix.cpp_extra }}"
echo "flagtree_pkg: ${{ matrix.flagtree_pkg }}"
echo "triton_pkg: ${{ matrix.triton_pkg }}"
- name: Pull base image
run: |
docker pull "${{ matrix.base_image }}" || {
echo "::error::Failed to pull base image ${{ matrix.base_image }}"
exit 1
}
- name: Build runtime image
run: |
flaggems_ver="${{ inputs.flaggems }}"
[[ -z "$flaggems_ver" ]] && flaggems_ver="${{ matrix.flaggems_version }}"
no_flaggems_arg=""
image_tag="${{ matrix.image_tag }}"
[[ "${{ inputs.no_flaggems }}" == "true" ]] && no_flaggems_arg='--build-arg NO_FLAGGEMS=1' && image_tag="${image_tag}-build"
cpp_extra="${{ matrix.cpp_extra }}"
[[ "${{ inputs.skip_cpp }}" == "true" ]] && cpp_extra=""
no_cache_arg=""
[[ "${{ inputs.no_cache }}" == "true" ]] && no_cache_arg="--no-cache"
# OCI provenance labels (mirrors scripts/build_base.py). revision is
# the runtime build commit — stamped via CLI --label because the
# multi-stage runtime/Containerfile inherits the base image's labels.
git_revision="${{ github.sha }}"
git_created="$(git show -s --format=%cI HEAD)"
label_args="--label org.opencontainers.image.version=${{ matrix.version }} \
--label org.opencontainers.image.revision=${git_revision} \
--label org.opencontainers.image.created=${git_created} \
--label last-updated=${git_created} \
--label org.opencontainers.image.source=https://github.com/flagos-ai/build-infra \
--label flagos.base=${{ matrix.base_image }}"
[[ "${{ inputs.no_flaggems }}" != "true" ]] && label_args="${label_args} --label flagos.flaggems=${flaggems_ver}"
docker build \
${no_cache_arg} \
${label_args} \
--build-arg "BASE_IMAGE=${{ matrix.base_image }}" \
--build-arg "PYTHON_VERSION=${{ matrix.python_version }}" \
--build-arg "FLAGOS_PYPI=${{ matrix.flagos_pypi }}" \
--build-arg "DAILY_PYPI=${{ matrix.daily_pypi }}" \
--build-arg "EXTRA_PYPI=${{ matrix.extra_pypi }}" \
--build-arg "DEPS=${{ matrix.deps }}" \
--build-arg "RUNTIME_PREREQS=${{ needs.set-matrix.outputs.runtime_prereqs }}" \
--build-arg "CPP_EXTRA=${cpp_extra}" \
--build-arg "FLAGTREE_PKG=${{ matrix.flagtree_pkg }}" \
--build-arg "TRITON_PKG=${{ matrix.triton_pkg }}" \
--build-arg "TRITON_EXTRA_PKGS=${{ matrix.triton_extra_pkgs }}" \
--build-arg "INCLUDE_TESTS=false" \
--build-arg "FLAGGEMS_VERSION=${flaggems_ver}" \
--build-arg "RUNTIME_ENV=${{ matrix.runtime_env }}" \
${no_flaggems_arg} \
-t "${image_tag}" \
-f runtime/Containerfile runtime/
- name: Push runtime image
if: ${{ inputs.push }}
run: |
image_tag="${{ matrix.image_tag }}"
[[ "${{ inputs.no_flaggems }}" == "true" ]] && image_tag="${image_tag}-build"
docker push "${image_tag}"