Repository navigation
214 lines (202 loc) · 8.96 KB
/
Copy pathdeploy.yml
File metadata and controls
214 lines (202 loc) · 8.96 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
name: Deploy to Production
on:
schedule:
- cron: '22 0 * * *'
timezone: America/Detroit
workflow_dispatch: {}
workflow_run:
workflows: ["CI Pipeline"]
types: [completed]
branches: [main]
permissions:
contents: read
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
DOCKER_BUILD_RECORD_UPLOAD: "false"
jobs:
build-and-push:
name: Build and Push Docker Image
if: >-
(github.event_name == 'schedule' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_sha != '' &&
github.event.workflow_run.head_branch == 'main' &&
github.event.workflow_run.head_repository.full_name == github.repository)
concurrency:
group: website-production-deploy
cancel-in-progress: false
runs-on: truenas-website-storage-16g
timeout-minutes: 40
env:
TESTED_SHA: ${{ github.event.workflow_run.head_sha || github.sha }}
permissions:
contents: read
packages: write
actions: read
steps:
- name: Start BuildKit storage collection
run: ci-storage-efficiency start
- name: Checkout tested main commit
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
ref: ${{ env.TESTED_SHA }}
persist-credentials: false
fetch-depth: 1
- name: Require successful matching CI before publication
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const { waitForDailyCI } = require('./.github/scripts/wait-for-daily-ci.cjs');
await waitForDailyCI({ github, context, core });
- name: Confirm tested commit is current main
run: |
set -euo pipefail
[[ "$TESTED_SHA" =~ ^[0-9a-f]{40}$ ]]
test "$(git rev-parse HEAD)" = "$TESTED_SHA"
git fetch --no-tags origin refs/heads/main:refs/remotes/origin/main
test "$(git rev-parse refs/remotes/origin/main)" = "$TESTED_SHA"
- name: Log in to Docker Hub
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up authenticated remote BuildKit
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
cache-binary: false
driver: remote
endpoint: tcp://buildkit:1234
driver-opts: |
cacert=/run/buildkit/tls/ca.pem
cert=/run/buildkit/tls/client.pem
key=/run/buildkit/tls/client.key
- name: Log in to Container Registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
context: git
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=sha,prefix=main-
- name: Prepare disk build cache
id: ci_disk_cache_1
run: ci-cache "truenas-15ed4a3293d99fba"
- name: Prepare immutable image and release tags
id: container_security_1
shell: bash
env:
SECURITY_PUBLISH: "true"
SECURITY_RELEASE_TAGS: |
${{ steps.meta.outputs.tags }}
SECURITY_REPORT_DIRECTORY: ${{ runner.temp }}/container-security/build-1
run: bash .github/actions/container-security/container-security.sh prepare
- name: Build and push Docker image
id: container_build_1
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
env:
DOCKER_BUILD_RECORD_RETENTION_DAYS: "1"
with:
outputs: ${{ steps.container_security_1.outputs.exporter }}
cache-from: |
type=local,src=${{ steps.ci_disk_cache_1.outputs.from }}
cache-to: ${{ steps.ci_disk_cache_1.outputs.to && format('type=local,dest={0},mode=max,ignore-error=true', steps.ci_disk_cache_1.outputs.to) || '' }}
context: .
file: ./Dockerfile
target: runtime
no-cache-filters: runtime-base,smoke-test,security-scan
build-args: |
QB_SOURCE_COMMIT=${{ env.TESTED_SHA }}
push: false # Push-by-digest is configured in the exporter; tags follow the scan.
tags: ${{ steps.container_security_1.outputs.repository }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
- name: Generate SBOM and enforce High/Critical vulnerability gate
id: container_scan_1
uses: ./.github/actions/container-security
with:
image: registry:${{ steps.container_security_1.outputs.repository }}@${{ steps.container_build_1.outputs.digest }}
platforms: "linux/amd64"
report-directory: ${{ runner.temp }}/container-security/build-1
artifact-name: container-security-${{ github.job }}-${{ strategy.job-index || 0 }}-build-1
- name: Finish and enforce BuildKit storage usage
if: always()
# Keep failure reports; enforce sizing only after the complete build and scan.
continue-on-error: ${{ steps.container_build_1.outcome != 'success' || steps.container_scan_1.outcome != 'success' }}
run: ci-storage-efficiency finish
- name: Format bounded plaintext storage diagnostics
id: storage_log
if: always()
run: |
python3 .github/scripts/format-storage-evidence.py \
--output "$RUNNER_TEMP/ci-storage-evidence.log" \
--repository "$GITHUB_REPOSITORY" --revision "$GITHUB_SHA" \
--usage-input "$RUNNER_TEMP/ci-storage-usage-start.json" \
--usage-input "$RUNNER_TEMP/ci-storage-usage.json"
- name: Upload bounded storage diagnostics
if: ${{ always() && steps.storage_log.outputs.available == 'true' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ci-log-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}-${{ strategy.job-index || 0 }}
path: ${{ runner.temp }}/ci-storage-evidence.log
if-no-files-found: error
retention-days: 1
- name: Confirm tested commit is current main before publication
run: |
set -euo pipefail
test "$(git rev-parse HEAD)" = "$TESTED_SHA"
git fetch --no-tags origin refs/heads/main:refs/remotes/origin/main
test "$(git rev-parse refs/remotes/origin/main)" = "$TESTED_SHA"
- name: Publish release tags only after the vulnerability gate passes
shell: bash
env:
SECURITY_IMAGE: ${{ steps.container_security_1.outputs.repository }}@${{ steps.container_build_1.outputs.digest }}
SECURITY_REPORT_DIRECTORY: ${{ runner.temp }}/container-security/build-1
run: bash .github/actions/container-security/container-security.sh publish
- name: Emit portable build receipt marker
shell: bash
env:
SOURCE_SHA: ${{ env.TESTED_SHA }}
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
IMAGE_DIGEST: ${{ steps.container_build_1.outputs.digest }}
run: |
set -euo pipefail
[[ "$SOURCE_SHA" =~ ^[0-9a-f]{40}$ ]]
[[ "$IMAGE_DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]]
printf 'QB_BUILD_RECEIPT_V1 source_sha=%s run_id=%s run_attempt=%s digest=%s\n' \
"$SOURCE_SHA" "$RUN_ID" "$RUN_ATTEMPT" "$IMAGE_DIGEST"
cleanup-artifacts:
name: Remove transient build artifacts
needs: ["build-and-push"]
if: ${{ always() && (github.event_name != 'workflow_run' || github.event.workflow_run.event == 'push') }}
runs-on: truenas-website-storage-8g
timeout-minutes: 10
permissions:
actions: write
contents: read
steps:
- name: Check out trusted default branch cleanup code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.repository.default_branch }}
persist-credentials: false
- name: Set up Python for bounded cleanup
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: '3.13'
- name: Delete non-retained current-run artifacts
env:
GH_TOKEN: ${{ github.token }}
run: python3 .github/scripts/cleanup-actions-artifacts.py --current