Repository navigation
443 lines (411 loc) · 19.5 KB
/
Copy pathci.yaml
File metadata and controls
443 lines (411 loc) · 19.5 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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
name: ✅ CI
on:
pull_request:
branches: [main]
merge_group:
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
validate-retired-links:
name: Validate retired repository links
if: github.repository == 'devantler-tech/platform-template'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Check documentation
id: links
uses: devantler-tech/.github/actions/validate-retired-repo-links@cc156a3693019fdbe9817c46f1a91cd50a124695 # v21.7.3
with:
enabled: "true"
- name: Require a complete scan
env:
VALIDATED: ${{ steps.links.outputs.validated }}
run: test "$VALIDATED" = true
- name: Prepare an isolated retired-link fixture
id: fixture
shell: bash
run: |
set -euo pipefail
fixture=$(mktemp -d "$RUNNER_TEMP/retired-link-fixture.XXXXXX")
git archive HEAD | tar -x -C "$fixture"
printf '\n[Retired-link fixture](https://github.com/devantler-tech/reusable-workflows)\n' >> "$fixture/README.md"
echo "directory=$fixture" >> "$GITHUB_OUTPUT"
- name: Reject the seeded retired link
id: negative
continue-on-error: true
uses: devantler-tech/.github/actions/validate-retired-repo-links@cc156a3693019fdbe9817c46f1a91cd50a124695 # v21.7.3
with:
enabled: "true"
working-directory: ${{ steps.fixture.outputs.directory }}
- name: Require the negative control to fail without success output
if: always()
env:
OUTCOME: ${{ steps.negative.outcome }}
VALIDATED: ${{ steps.negative.outputs.validated }}
run: |
test "$OUTCOME" = failure
test -z "$VALIDATED"
- name: Checkout the exact validator source for diagnostic verification
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: devantler-tech/.github
ref: bd0035dd8f41fcf1459b878882b8897443f8dc59 # v4.9.4
path: .catalogue-fixture
sparse-checkout: actions/validate-retired-repo-links
persist-credentials: false
- name: Require the expected README finding
shell: bash
env:
FIXTURE: ${{ steps.fixture.outputs.directory }}
GOWORK: "off"
GOFLAGS: ""
GOTOOLCHAIN: local
run: |
set -euo pipefail
go -C .catalogue-fixture/actions/validate-retired-repo-links build -mod=readonly -trimpath -o "$RUNNER_TEMP/retired-link-validator" .
result=0
"$RUNNER_TEMP/retired-link-validator" --root "$FIXTURE" > "$RUNNER_TEMP/retired-link-finding.log" 2>&1 || result=$?
cat "$RUNNER_TEMP/retired-link-finding.log"
test "$result" -eq 1
grep -E '^README.md:[0-9]+: link targets retired repository devantler-tech/reusable-workflows$' "$RUNNER_TEMP/retired-link-finding.log"
changes:
name: 🔍 Detect Changes
runs-on: ubuntu-latest
permissions:
contents: read # checkout repository
pull-requests: read # detect changed files
outputs:
k8s: ${{ steps.filter.outputs.k8s }}
steps:
- name: 🛡️ Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- name: 📑 Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
- name: 🔍 Filter paths
uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
id: filter
with:
filters: |
k8s:
- 'k8s/**'
- 'ksail.yaml'
- 'ksail.prod.yaml'
- '.sops.yaml'
# talos*/ — the naming gate scans every root-level talos*/
# directory, and instances add environments as talos-<env>/.
- 'talos*/**'
- '.github/workflows/ci.yaml'
- '.github/manifest-naming*.yaml'
- '.github/workflows/validate-naming.yaml'
validate-naming:
name: 🏷️ Validate Naming Conventions
needs: [changes]
# Static folder/file naming gate: kebab-case dirs, one-resource-per-file,
# Kind-led filenames, CR-folder plurals, patch/talos intent naming, and
# flux-kustomization disambiguation — the reference platform's conventions
# (platform#2315), shared through devantler-tech/.github. No cluster or
# secrets; Go setup/build can download dependencies. Template-repo-only:
# instances run the gate via the template-synced validate-naming.yaml
# (their ci.yaml is instance-owned), so without this guard every instance
# k8s PR would run the same gate twice.
if: github.repository == 'devantler-tech/platform-template' && github.event_name == 'pull_request' && needs.changes.outputs.k8s == 'true'
runs-on: ubuntu-latest
permissions:
contents: read # checkout repository
steps:
- name: 🛡️ Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- name: 📑 Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: 🏷️ Validate naming conventions
id: naming
uses: devantler-tech/.github/actions/validate-naming@cc156a3693019fdbe9817c46f1a91cd50a124695 # v21.7.3
with:
config-file: .github/manifest-naming.yaml
- name: Require a complete naming scan
env:
VALIDATED: ${{ steps.naming.outputs.validated }}
run: |
if [ "$VALIDATED" != true ]; then
echo "::error::The naming scan did not complete; repair its configuration or finding."
exit 1
fi
system-test:
name: 🧪 System Test
needs: [changes]
# Cluster-touching job: runs only in instances of this template (it needs the
# instance's SOPS/cluster secrets). In the template repo itself it is skipped;
# validate-scaffold.yaml is the scaffold gate there instead.
if: github.repository != 'devantler-tech/platform-template' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && needs.changes.outputs.k8s == 'true'
runs-on: ubuntu-latest
environment: ci
permissions:
contents: read # checkout repository
steps:
- name: 🛡️ Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- name: 📑 Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: 🧹 Free disk space
uses: endersonmenezes/free-disk-space@8b8cd4e2277836962939a8f3b4ea0ee4bc006156 # v4.0.1
with:
remove_android: true
remove_dotnet: true
remove_haskell: true
remove_tool_cache: true
remove_swap: false
remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
remove_packages_one_command: true
remove_folders: "/usr/share/swift /usr/share/miniconda /usr/share/az* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/local/julia /usr/local/aws-cli /usr/local/aws-sam-cli /usr/share/gradle"
- name: 🧪 System Test
uses: devantler-tech/ksail/.github/actions/ksail-cluster@fda9be109a95d536a2ab91ef75f37d7c7c3063dd # v7.215.11
with:
distribution: Talos
provider: Docker
# Keep in step with KSAIL_VERSION in deploy-prod: Renovate tracks only
# that pin, so this input must be bumped alongside it.
ksail-version: "7.202.70"
init: "false"
validate: "true"
scan: "true"
scan-framework: "nsa"
sops-age-key: ${{ secrets.SOPS_AGE_KEY }}
hosts-file: ${{ vars.HOSTS_FILE }}
root-ca-cert-file: ${{ vars.ROOT_CA_CERT_FILE }}
push: "true"
reconcile: "true"
delete: "false"
- name: 🩺 Diagnose Flux on failure
if: failure()
# Shared composite — single source of truth for Flux failure diagnostics
# (devantler-tech/actions#367). Default kustomizations match this job's
# previous inline list (infrastructure-controllers infrastructure apps).
uses: devantler-tech/.github/actions/diagnose-flux@cc156a3693019fdbe9817c46f1a91cd50a124695 # v21.7.3
- name: 🔥 Delete cluster
if: always()
run: ksail cluster delete || echo "⚠️ Cluster may not have been created"
deploy-prod:
name: 🚀 Deploy to Prod
needs: [changes]
# Cluster-touching job: runs only in instances of this template (it needs the
# instance's prod cluster + GHCR secrets). Skipped in the template repo itself.
if: github.repository != 'devantler-tech/platform-template' && github.event_name == 'merge_group' && needs.changes.outputs.k8s == 'true'
runs-on: ubuntu-latest
environment: prod
# Shared with the CD tag-deploy workflow (cd.yaml) so a tag deploy and a
# merge-queue deploy can never run against the prod cluster at once. `queue: max`
# keeps up to 100 waiting deploys in order instead of cancelling the pending one.
concurrency:
group: prod-deploy
cancel-in-progress: false
queue: max
permissions:
contents: read # checkout repository
packages: write # push OCI artifacts to GHCR
id-token: write # mint OIDC token for cosign keyless signing (Fulcio + Rekor)
steps:
- name: 🛡️ Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- name: 📑 Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: ⚙️ Setup KSail
# Install the KSail CLI from the release tarball via curl. We use curl
# rather than brew/setup-ksail-cli because the v7.20.0 release shipped
# only desktop artifacts (linux CLI missing, 404 on the tarball).
# v7.23.4 ships complete linux artifacts again and carries the
# cluster-update fixes; renovate keeps this pin current.
env:
# renovate: datasource=github-releases depName=devantler-tech/ksail extractVersion=^v(?<version>.+)$
KSAIL_VERSION: "7.216.22"
run: |
curl -fsSL "https://github.com/devantler-tech/ksail/releases/download/v${KSAIL_VERSION}/ksail_${KSAIL_VERSION}_linux_amd64.tar.gz" -o /tmp/ksail.tar.gz
tar -xzf /tmp/ksail.tar.gz -C /tmp
sudo install /tmp/ksail /usr/local/bin/ksail
ksail --version
- name: 🔐 Create SOPS Age key
env:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
run: |
mkdir -p ~/.config/sops/age
umask 077
echo "${SOPS_AGE_KEY}" > ~/.config/sops/age/keys.txt
chmod 600 ~/.config/sops/age/keys.txt
- name: 🔑 Restore kubeconfig
# ksail cluster update needs a valid kubeconfig to detect the current
# cluster state. Without it, the component detector returns defaults and
# triggers spurious changes that all fail. The KUBE_CONFIG secret must be
# kept up-to-date from the homelab after any cluster recreation.
# See devantler-tech/ksail#4369 for the upstream design context.
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
run: |
mkdir -p ~/.kube
umask 077
printf '%s' "${KUBE_CONFIG}" > ~/.kube/config
chmod 600 ~/.kube/config
- name: 🔑 Restore talosconfig
env:
TALOS_CONFIG: ${{ secrets.TALOS_CONFIG }}
run: |
mkdir -p ~/.talos
umask 077
printf '%s' "${TALOS_CONFIG}" > ~/.talos/config
chmod 600 ~/.talos/config
- name: 🩺 Verify prod cluster is reachable
# Fail fast if the restored kubeconfig can't reach the prod API server.
# When the cluster is unreachable — most commonly because KUBE_CONFIG /
# TALOS_CONFIG are stale after a cluster rebuild — `ksail cluster update`
# otherwise only warns, falls back to a "nothing is installed" baseline,
# proposes a full reinstall, and then fails mid-apply against the live
# nodes (a confusing, potentially destructive failure mode). Catch it
# here with an actionable message instead.
# Upstream: devantler-tech/ksail#4868 (fail fast) and #4869 (baseline).
# Pin --context to admin@prod (ksail.prod.yaml's connection.context) so
# the check targets the same cluster `ksail cluster update` will use,
# regardless of the restored kubeconfig's current-context.
run: |
# A missing admin@prod context means a malformed/incomplete kubeconfig,
# not an unreachable cluster — surface that case distinctly.
if ! kubectl config get-contexts -o name | grep -qx 'admin@prod'; then
echo "::error::Restored kubeconfig has no 'admin@prod' context (ksail.prod.yaml's connection.context). KUBE_CONFIG looks malformed or incomplete — refresh it."
exit 1
fi
last_err=""
for attempt in 1 2 3; do
# Capture kubectl's own stderr so the failure message is accurate.
if out=$(kubectl --context admin@prod get --raw='/readyz' --request-timeout=30s 2>&1); then
echo "✅ Prod API server reachable."
exit 0
fi
last_err="$out"
echo "Attempt ${attempt}/3: prod API server (context admin@prod) not reachable: ${out}"
sleep 10
done
last_err=$(printf '%s' "$last_err" | tr '\n' ' ')
echo "::error::Prod cluster (context admin@prod) is unreachable with the restored kubeconfig (last kubectl error: ${last_err}). KUBE_CONFIG (and likely TALOS_CONFIG) are probably stale after a cluster rebuild — refresh both and update the 'prod' environment secrets."
exit 1
- name: 🔄 Update cluster
run: ksail --config ksail.prod.yaml cluster update
env:
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
- name: 📦 Push manifests to GHCR
run: ksail --config ksail.prod.yaml workload push
env:
GITHUB_ACTOR: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
# ----- Supply-chain signing (mirrors cd.yaml's deploy job) -----
# The merge queue publishes the SAME ghcr.io/.../manifests:latest artifact
# that tag deploys (cd.yaml) do. Without signing here, whether the instance's
# artifact is signed depends on which path last deployed it — and merges
# happen far more often than tags. These three steps are a faithful copy of
# cd.yaml's signing block; keep them in sync. SBOM (syft) + SLSA provenance
# attestation are intentionally NOT mirrored yet: the cosign signature is the
# integrity property a Flux-side verifier checks, and attestation parity is a
# follow-up (ideally by extracting cd.yaml's block into a shared composite
# action so the two paths can never drift again).
- name: ⚙️ Install cosign
env:
# renovate: datasource=github-releases depName=sigstore/cosign extractVersion=^v(?<version>.+)$
COSIGN_VERSION: "3.1.4"
uses: sigstore/cosign-installer@756fe2d284c7292c4e9b62c8a28f1e5629c59532 # v4.1.3
with:
cosign-release: 'v${{ env.COSIGN_VERSION }}'
- name: 🔐 Configure GHCR auth (cosign)
# Pre-create ~/.docker/config.json so cosign + buildx imagetools resolve
# GHCR creds via the OCI keychain (no `cosign login`/`docker login`
# "credentials stored unencrypted" warning). Byte-identical to cd.yaml.
env:
GITHUB_ACTOR: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
run: |
set -euo pipefail
umask 077
mkdir -p ~/.docker
AUTH=$(printf '%s:%s' "${GITHUB_ACTOR}" "${GHCR_TOKEN}" | base64 -w0)
echo "::add-mask::${AUTH}"
jq -n --arg auth "${AUTH}" \
'{auths: {"ghcr.io": {auth: $auth}}}' \
> ~/.docker/config.json
chmod 600 ~/.docker/config.json
- name: 🖋️ Sign OCI manifest with cosign (keyless)
# Resolve tag → digest, then sign by digest: no tag→digest TOCTOU under a
# concurrent deploy, and forward-compatible with cosign v3 (which removed
# tag-based signing). Fulcio binds the signature to THIS workflow's OIDC
# identity (…/.github/workflows/ci.yaml@…), so a Flux-side verifier's
# matchOIDCIdentity must allow both ci.yaml and cd.yaml identities.
id: cosign-sign
env:
COSIGN_YES: "true"
run: |
set -euo pipefail
REF_TAG="ghcr.io/${{ github.repository }}/manifests:latest"
DIGEST=$(docker buildx imagetools inspect "${REF_TAG}" --format '{{.Manifest.Digest}}')
REF="ghcr.io/${{ github.repository }}/manifests@${DIGEST}"
cosign sign --yes --recursive "${REF}"
echo "digest=${DIGEST}" >> "${GITHUB_OUTPUT}"
echo "ref=${REF_TAG}" >> "${GITHUB_OUTPUT}"
- name: 🔁 Trigger Flux reconciliation
id: reconcile
run: ksail --config ksail.prod.yaml workload reconcile
env:
GITHUB_ACTOR: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
- name: 🩺 Diagnose Flux on failure
if: failure() && steps.reconcile.outcome == 'failure'
# Shared composite — single source of truth for Flux failure diagnostics
# (devantler-tech/actions#367). This prod path now inherits the richer
# diagnostics (nodes, all-pods, failing/CrashLooping pod logs, failing
# Jobs) that previously only the system-test path emitted. kubectl uses
# the Talos cert-based admin@prod kubeconfig, so no HCLOUD_TOKEN is
# needed by the diagnostics themselves.
uses: devantler-tech/.github/actions/diagnose-flux@cc156a3693019fdbe9817c46f1a91cd50a124695 # v21.7.3
ci-required-checks:
name: CI - Required Checks
runs-on: ubuntu-latest
needs: [changes, validate-naming, system-test, deploy-prod, validate-retired-links]
if: always()
permissions:
actions: read
steps:
- name: 📊 Evaluate job results
uses: devantler-tech/.github/actions/aggregate-job-checks@cc156a3693019fdbe9817c46f1a91cd50a124695 # v21.7.3
with:
check-workflow-startup: "true"
job-results: >-
${{ needs.changes.result }}
${{ needs.validate-naming.result }}
${{ needs.system-test.result }}
${{ needs.deploy-prod.result }}
${{ needs.validate-retired-links.result }}