-
Notifications
You must be signed in to change notification settings - Fork 0
327 lines (284 loc) · 12.3 KB
/
build.yml
File metadata and controls
327 lines (284 loc) · 12.3 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
name: bluebuild
on:
schedule:
- cron:
"00 06 * * *"
push:
branches: [main]
paths-ignore:
- "**.md"
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true
jobs:
source-prep:
name: "Stage 1: Source Prep"
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Validate committed wheelhouse
run: |
echo "=== Validating vendor/wheels/SHA256SUMS ==="
if [ ! -f vendor/wheels/SHA256SUMS ]; then
echo "WARNING: vendor/wheels/SHA256SUMS not found"
echo "Wheelhouse not yet populated — hermetic build will fail."
else
echo "OK: vendor/wheels/SHA256SUMS exists"
fi
- name: Download and verify llama.cpp tarball
run: |
# Read pinned version + checksum from build-services.sh
LLAMA_CPP_VERSION=$(grep -oP 'LLAMA_CPP_VERSION:-\K[^}]+' files/scripts/build-services.sh | head -1)
LLAMA_CPP_SHA256=$(grep -oP 'LLAMA_CPP_SHA256:-\K[^}]+' files/scripts/build-services.sh | head -1)
echo "Downloading llama.cpp ${LLAMA_CPP_VERSION}..."
TARBALL="llama-cpp-${LLAMA_CPP_VERSION}.tar.gz"
curl -fsSL -o "/tmp/${TARBALL}" \
"https://github.com/ggml-org/llama.cpp/archive/refs/tags/${LLAMA_CPP_VERSION}.tar.gz"
echo "Verifying checksum..."
ACTUAL=$(sha256sum "/tmp/${TARBALL}" | awk '{print $1}')
if [ "$ACTUAL" != "$LLAMA_CPP_SHA256" ]; then
echo "::error::llama.cpp checksum mismatch: expected ${LLAMA_CPP_SHA256}, got ${ACTUAL}"
echo "Update LLAMA_CPP_SHA256 in build-services.sh if the version was bumped."
exit 1
fi
echo "OK: llama.cpp checksum verified"
echo "TARBALL_SHA256=${ACTUAL}" >> "$GITHUB_ENV"
echo "LLAMA_CPP_VERSION=${LLAMA_CPP_VERSION}" >> "$GITHUB_ENV"
mv "/tmp/${TARBALL}" "/tmp/llama-cpp-staged.tar.gz"
- name: Emit SOURCE_PREP_MANIFEST.json
run: |
python3 -c "
import json, hashlib, os
from datetime import datetime
manifest = {
'schema_version': 1,
'timestamp': datetime.utcnow().isoformat() + 'Z',
'commit_sha': os.environ.get('GITHUB_SHA', 'unknown'),
'llama_cpp_version': os.environ.get('LLAMA_CPP_VERSION', 'unknown'),
'llama_cpp_tarball_sha256': os.environ.get('TARBALL_SHA256', 'unknown'),
}
# Wheelhouse SHA256SUMS digest
try:
with open('vendor/wheels/SHA256SUMS', 'rb') as f:
manifest['wheelhouse_sha256sums_digest'] = hashlib.sha256(f.read()).hexdigest()
except FileNotFoundError:
manifest['wheelhouse_sha256sums_digest'] = 'not_populated'
# Upstreams lock manifest digest
try:
with open('.upstreams.lock.yaml', 'rb') as f:
manifest['upstreams_lock_digest'] = hashlib.sha256(f.read()).hexdigest()
except FileNotFoundError:
manifest['upstreams_lock_digest'] = 'not_found'
with open('SOURCE_PREP_MANIFEST.json', 'w') as f:
json.dump(manifest, f, indent=2)
f.write('\n')
print('--- SOURCE_PREP_MANIFEST.json ---')
print(json.dumps(manifest, indent=2))
"
- name: Upload staged artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: source-prep
path: |
SOURCE_PREP_MANIFEST.json
/tmp/llama-cpp-staged.tar.gz
bluebuild:
name: "Stage 2: Build Custom Image"
needs: [source-prep]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
strategy:
fail-fast: false
matrix:
recipe:
# BlueBuild resolves recipe paths relative to the recipes/ directory.
# "recipe.yml" maps to "recipes/recipe.yml" by convention.
- recipe.yml
steps:
- name: Build Custom Image
id: build
uses: blue-build/github-action@24d146df25adc2cf579e918efe2d9bff6adea408 # v1.11.1
with:
recipe: ${{ matrix.recipe }}
cosign_private_key: ${{ secrets.SIGNING_SECRET }}
registry_token: ${{ github.token }}
pr_event_number: ${{ github.event.number }}
maximize_build_space: true
# Retry once on transient failures (COPR CDN 504s, rpm-ostree mirror flakes)
- name: Retry build on transient failure
if: failure() && steps.build.outcome == 'failure'
uses: blue-build/github-action@24d146df25adc2cf579e918efe2d9bff6adea408 # v1.11.1
with:
recipe: ${{ matrix.recipe }}
cosign_private_key: ${{ secrets.SIGNING_SECRET }}
registry_token: ${{ github.token }}
pr_event_number: ${{ github.event.number }}
maximize_build_space: true
- name: Set lowercase image ref
if: github.event_name != 'pull_request'
run: echo "IMAGE_REF=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
# Scan the source tree rather than the full OS image.
# The OS image is a multi-GB Fedora Silverblue base with thousands of
# system packages — scanning it via `syft scan <image>` exceeds the
# runner's memory/time limits. Fedora provides its own SBOMs for base
# packages. This SBOM covers our custom services and configuration.
- name: Generate SBOM
if: github.event_name != 'pull_request'
uses: anchore/sbom-action@57aae528053a48a3f6235f2d9461b05fbcb7366d # v0.23.1
with:
path: .
format: cyclonedx-json
output-file: sbom.cdx.json
- name: Attest SBOM
if: github.event_name != 'pull_request'
run: |
cosign attest --type cyclonedx \
--predicate sbom.cdx.json \
--key env://COSIGN_PRIVATE_KEY \
"$IMAGE_REF"
env:
COSIGN_PRIVATE_KEY: ${{ secrets.SIGNING_SECRET }}
# Publish the image digest so users can pin installs to an exact build.
# The digest appears in the workflow summary and as an artifact.
- name: Extract and publish image digest
if: github.event_name != 'pull_request'
id: digest
run: |
DIGEST=$(skopeo inspect "docker://${IMAGE_REF}:latest" 2>/dev/null | jq -r '.Digest' || echo "")
if [ -z "$DIGEST" ] || [ "$DIGEST" = "null" ]; then
echo "WARNING: Could not extract image digest"
echo "digest=unknown" >> "$GITHUB_OUTPUT"
else
echo "digest=${DIGEST}" >> "$GITHUB_OUTPUT"
echo "${DIGEST}" > IMAGE_DIGEST
echo "## Image Digest" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "Pinned install reference:" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
echo "sudo bash secai-bootstrap.sh --digest ${DIGEST}" >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "Full image ref: \`${IMAGE_REF}@${DIGEST}\`" >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload image digest artifact
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: image-digest
path: IMAGE_DIGEST
if-no-files-found: warn
smoke-test:
name: Tier 1 Smoke Test (Artifact Verification)
needs: [bluebuild]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
- name: Install pyyaml
run: pip install pyyaml
- name: Validate recipe systemd units
run: |
python3 -c "
import yaml, sys
with open('recipes/recipe.yml') as f:
recipe = yaml.safe_load(f)
for module in recipe.get('modules', []):
if module.get('type') != 'systemd':
continue
enabled = set(module.get('system', {}).get('enabled', []))
disabled = set(module.get('system', {}).get('disabled', []))
overlap = enabled & disabled
if overlap:
print(f'FAIL: services in both enabled and disabled: {overlap}')
sys.exit(1)
# Diffusion must be disabled by default
if 'secure-ai-diffusion.service' in enabled:
print('FAIL: secure-ai-diffusion.service must be in disabled list')
sys.exit(1)
if 'secure-ai-diffusion.service' not in disabled:
print('FAIL: secure-ai-diffusion.service missing from disabled list')
sys.exit(1)
# Core services must be enabled
core = [
'secure-ai-registry.service',
'secure-ai-tool-firewall.service',
'secure-ai-ui.service',
'secure-ai-policy-engine.service',
'nftables.service',
]
for svc in core:
if svc not in enabled:
print(f'FAIL: core service {svc} not in enabled list')
sys.exit(1)
print(f'OK: {len(enabled)} enabled, {len(disabled)} disabled, no overlap')
"
- name: Validate YAML config files
run: |
python3 -c "
import yaml, sys, glob
errors = 0
for pattern in ['files/system/etc/secure-ai/**/*.yaml', 'recipes/*.yml']:
for f in glob.glob(pattern, recursive=True):
try:
with open(f) as fh:
yaml.safe_load(fh)
print(f'OK: {f}')
except Exception as e:
print(f'FAIL: {f}: {e}')
errors += 1
sys.exit(errors)
"
- name: Verify build script is hermetic-ready
run: |
echo "=== Checking build-services.sh for network fetch patterns ==="
SCRIPT="files/scripts/build-services.sh"
# Must have hermetic guard
grep -q "HERMETIC_BUILD" "$SCRIPT" || { echo "FAIL: no HERMETIC_BUILD guard"; exit 1; }
echo "OK: HERMETIC_BUILD guard present"
# Must have LLAMA_CPP_SHA256
grep -q "LLAMA_CPP_SHA256" "$SCRIPT" || { echo "FAIL: no LLAMA_CPP_SHA256"; exit 1; }
echo "OK: LLAMA_CPP_SHA256 checksum present"
# Must have GOPROXY=off in hermetic mode
grep -q "GOPROXY=off" "$SCRIPT" || { echo "FAIL: no GOPROXY=off"; exit 1; }
echo "OK: GOPROXY=off in hermetic mode"
# Must not have --clone in locate_source calls
if grep -n "locate_source.*--clone" "$SCRIPT"; then
echo "FAIL: locate_source still uses --clone"
exit 1
fi
echo "OK: no --clone in locate_source"
# Must not have dnf install
if grep -n "dnf install" "$SCRIPT" | grep -v "^#" | grep -v "dnf remove"; then
echo "FAIL: dnf install found in build script"
exit 1
fi
echo "OK: no dnf install"
echo "=== Build script hermetic checks passed ==="
- name: Verify systemd units use wrappers
run: |
echo "=== Checking systemd units ==="
UNITS_DIR="files/system/usr/lib/systemd/system"
# UI must use wrapper, not python3 directly
if grep -q "ExecStart=/usr/bin/python3" "${UNITS_DIR}/secure-ai-ui.service"; then
echo "FAIL: UI service still uses python3 directly"
exit 1
fi
echo "OK: UI uses wrapper"
# Diffusion must not use python3 directly
if grep -q "ExecStart=/usr/bin/python3" "${UNITS_DIR}/secure-ai-diffusion.service"; then
echo "FAIL: Diffusion service still uses python3 directly"
exit 1
fi
echo "OK: Diffusion uses wrapper/placeholder"
echo "=== Systemd unit checks passed ==="