-
Notifications
You must be signed in to change notification settings - Fork 3
333 lines (297 loc) · 13.5 KB
/
Copy pathdocker-validate.yml
File metadata and controls
333 lines (297 loc) · 13.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
---
# Pullbox Docker Validation Pipeline
# PR/manual Docker checks prove that image changes build, scan, and smoke-test
# without publishing anything to GHCR or Docker Hub.
#
# Trusted pull requests run the full production Docker Hardened Images build on
# the dedicated Docker runner. Untrusted pull requests fall back to a reduced
# public sanity check that does not require secrets or self-hosted runners.
# GitHub Actions owns Docker validation for PR checks.
name: Docker Validate
on:
pull_request:
branches:
- develop
- main
types:
- opened
- synchronize
- reopened
- ready_for_review
- labeled
- unlabeled
workflow_dispatch:
permissions:
contents: read
concurrency:
group: docker-validate-${{ github.ref || github.run_id }}
cancel-in-progress: true
env:
PYTHON_DEFAULT: "3.14"
jobs:
release_sync_check:
name: Release Sync Check
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
is_sync: ${{ steps.release-sync.outputs.is_sync }}
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Detect safe post-release sync PR
id: release-sync
env:
RELEASE_SYNC_EVENT_NAME: ${{ github.event_name }}
RELEASE_SYNC_BASE_REF: ${{ github.base_ref || '' }}
RELEASE_SYNC_HEAD_REF: ${{ github.head_ref || '' }}
RELEASE_SYNC_REPOSITORY: ${{ github.repository }}
RELEASE_SYNC_HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name || '' }}
RELEASE_SYNC_ACTOR: ${{ github.actor }}
run: |
git fetch --no-tags origin main:refs/remotes/origin/main
if ! git cat-file -e origin/main:.github/scripts/validate-release-sync-pr.py 2>/dev/null; then
echo "is_sync=false" >> "$GITHUB_OUTPUT"
echo "reason=trusted release sync validator is not available on origin/main yet" >> "$GITHUB_OUTPUT"
echo "release_sync=false"
echo "reason=trusted release sync validator is not available on origin/main yet"
exit 0
fi
git show origin/main:.github/scripts/validate-release-sync-pr.py > /tmp/pullbox-release-sync-validator.py
python /tmp/pullbox-release-sync-validator.py
full_ci_check:
name: Full Docker Gate
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
run_full: ${{ steps.gate.outputs.run_full }}
trusted_full: ${{ steps.gate.outputs.trusted_full }}
untrusted_full: ${{ steps.gate.outputs.untrusted_full }}
label_required: ${{ steps.gate.outputs.label_required }}
permissions:
contents: read
steps:
- name: Resolve Docker validation gate
id: gate
run: |
echo "run_full=${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && !github.event.pull_request.draft && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]' || startsWith(github.event.pull_request.head.ref, 'dependabot/') || contains(github.event.pull_request.labels.*.name, 'ci:full'))) }}" >> "$GITHUB_OUTPUT"
echo "trusted_full=${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && !github.event.pull_request.draft && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' && !startsWith(github.event.pull_request.head.ref, 'dependabot/') && contains(github.event.pull_request.labels.*.name, 'ci:full')) }}" >> "$GITHUB_OUTPUT"
echo "untrusted_full=${{ github.event_name == 'pull_request' && !github.event.pull_request.draft && (github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]' || startsWith(github.event.pull_request.head.ref, 'dependabot/')) }}" >> "$GITHUB_OUTPUT"
echo "label_required=${{ github.event_name == 'pull_request' && !github.event.pull_request.draft && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' && !startsWith(github.event.pull_request.head.ref, 'dependabot/') && !contains(github.event.pull_request.labels.*.name, 'ci:full') }}" >> "$GITHUB_OUTPUT"
untrusted-sanity:
name: Docker Sanity (untrusted PR)
needs: [release_sync_check, full_ci_check]
if: needs.release_sync_check.outputs.is_sync != 'true' && needs.full_ci_check.outputs.untrusted_full == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Explain reduced validation
run: |
echo "Repository secrets are unavailable for fork or Dependabot pull requests."
echo "Running a reduced Docker sanity check instead of the trusted Docker Hardened Images build."
- name: Build local development image
run: docker build -f docker/Dockerfile.dev -t pullbox:pr-sanity .
- name: Inspect built development image
run: docker image inspect pullbox:pr-sanity >/dev/null
- name: Cleanup
if: always()
run: docker image rm -f pullbox:pr-sanity || true
trusted-production-validate:
name: Production Docker Validate (trusted)
needs: [release_sync_check, full_ci_check]
if: needs.release_sync_check.outputs.is_sync != 'true' && needs.full_ci_check.outputs.trusted_full == 'true'
runs-on: [self-hosted, Linux, X64, docker]
timeout-minutes: 35
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Runner preflight
run: .github/scripts/preflight-runner.sh docker
- name: Validate DHI authentication
env:
DHI_USERNAME: ${{ secrets.DHI_USERNAME }}
DHI_TOKEN: ${{ secrets.DHI_TOKEN }}
run: |
if [ -z "${DHI_USERNAME}" ] || [ -z "${DHI_TOKEN}" ]; then
echo "::error::DHI_USERNAME and DHI_TOKEN repository secrets are required to build Docker Hardened Images in CI."
exit 1
fi
- name: Log in to DHI
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: dhi.io
username: ${{ secrets.DHI_USERNAME }}
password: ${{ secrets.DHI_TOKEN }}
- name: Build production Docker image
run: |
BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
GIT_SHA="${GITHUB_SHA}"
docker build \
-f docker/Dockerfile \
-t pullbox:validate \
--build-arg BUILD_DATE="${BUILD_DATE}" \
--build-arg GIT_SHA="${GIT_SHA}" \
--build-arg GIT_BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" \
--build-arg VERSION="validate-${GIT_SHA::7}" \
.
- name: Inspect built production image
run: docker image inspect pullbox:validate >/dev/null
- name: Verify container security runtime
run: |
docker run --rm -i --entrypoint python pullbox:validate - \
< scripts/verify_container_security_runtime.py
- name: Run Grype scan
uses: anchore/scan-action@27805bf3b4e84b4a5c980df22ed233c00390a439 # v7.4.2
with:
image: pullbox:validate
grype-version: v0.110.0
fail-build: true
severity-cutoff: high
output-format: table
config: .grype.yaml
- name: Verify packaged static assets
run: |
docker run --rm --entrypoint python pullbox:validate -c '
import pullbox.app
assets = [
pullbox.app.STATIC_DIR / "css" / "tailwind.css",
pullbox.app.STATIC_DIR / "js" / "htmx.min.js",
]
missing = [str(asset) for asset in assets if not asset.is_file()]
if missing:
raise SystemExit("Missing packaged static assets: " + ", ".join(missing))
print("Packaged static assets verified")
'
- name: Start container
run: |
docker run -d \
--name pullbox-validate \
-p 127.0.0.1::8585 \
-e PULLBOX_SECRET_KEY=docker-validate-secret-key-for-ci \
-e PULLBOX_LOG_LEVEL=WARNING \
pullbox:validate
validate_port="$(docker port pullbox-validate 8585/tcp | awk -F: 'NR == 1 { print $NF }')"
if [ -z "${validate_port}" ]; then
echo "::error::Could not determine Pullbox validation port."
docker port pullbox-validate || true
exit 1
fi
echo "PULLBOX_VALIDATE_URL=http://127.0.0.1:${validate_port}" >> "$GITHUB_ENV"
echo "Container listening on http://127.0.0.1:${validate_port}"
- name: Wait for healthy
run: |
for i in $(seq 1 30); do
if curl -sf "${PULLBOX_VALIDATE_URL}/ping" > /dev/null 2>&1; then
echo "Container healthy after ${i}s"
exit 0
fi
sleep 1
done
echo "Container failed to become healthy"
docker logs pullbox-validate
exit 1
- name: Write Docker validation summary
if: always()
run: |
{
echo "## Docker Validation"
echo ""
echo "- Production image build: pullbox:validate"
echo "- Grype scan: high severity gate"
echo "- Smoke test: /ping health check"
echo "- Publish: disabled for validation workflow"
} >> "$GITHUB_STEP_SUMMARY"
- name: Collect container logs on failure
if: failure() || cancelled()
run: |
mkdir -p test-results/docker-validate
docker logs pullbox-validate > test-results/docker-validate/container.log 2>&1 || true
- name: Upload Docker validation failure artifacts
if: failure() || cancelled()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: docker-validate-failure-artifacts
path: test-results/docker-validate/
if-no-files-found: ignore
retention-days: 7
- name: Cleanup
if: always()
run: |
docker rm -f pullbox-validate || true
docker image rm -f pullbox:validate || true
docker-validate-required:
name: Docker Validate Required
runs-on: ubuntu-latest
needs:
- release_sync_check
- full_ci_check
- untrusted-sanity
- trusted-production-validate
if: always()
timeout-minutes: 5
permissions:
contents: read
steps:
- name: Verify Docker validation jobs
env:
NEEDS_CONTEXT: ${{ toJson(needs) }}
RELEASE_SYNC_PR: ${{ needs.release_sync_check.outputs.is_sync }}
RUN_FULL: ${{ needs.full_ci_check.outputs.run_full }}
TRUSTED_FULL: ${{ needs.full_ci_check.outputs.trusted_full }}
UNTRUSTED_FULL: ${{ needs.full_ci_check.outputs.untrusted_full }}
LABEL_REQUIRED: ${{ needs.full_ci_check.outputs.label_required }}
run: |
python - <<'PY'
import json
import os
import sys
needs = json.loads(os.environ["NEEDS_CONTEXT"])
release_sync_pr = os.environ["RELEASE_SYNC_PR"].lower() == "true"
run_full = os.environ["RUN_FULL"].lower() == "true"
trusted_full = os.environ["TRUSTED_FULL"].lower() == "true"
untrusted_full = os.environ["UNTRUSTED_FULL"].lower() == "true"
label_required = os.environ["LABEL_REQUIRED"].lower() == "true"
if release_sync_pr:
release_sync = needs.get("release_sync_check", {}).get("result")
if release_sync != "success":
print(f"Release sync validation failed: {release_sync}", file=sys.stderr)
sys.exit(1)
unexpected = {
name: info.get("result")
for name, info in needs.items()
if name != "release_sync_check" and info.get("result") not in {"skipped", "success"}
}
if unexpected:
print(f"Release sync fast path saw unexpected Docker results: {unexpected}", file=sys.stderr)
sys.exit(1)
print("Release sync fast path validated; Docker validation intentionally skipped.")
sys.exit(0)
if not run_full:
if label_required:
print("Docker validation is waiting for ci:full before running the required Docker gate.", file=sys.stderr)
else:
print("Docker validation was intentionally not requested for this PR state.", file=sys.stderr)
sys.exit(1)
if trusted_full:
result = needs.get("trusted-production-validate", {}).get("result")
if result != "success":
print(f"Trusted Docker validation did not pass: {result}", file=sys.stderr)
sys.exit(1)
print("Trusted Docker validation passed.")
sys.exit(0)
if untrusted_full:
result = needs.get("untrusted-sanity", {}).get("result")
if result != "success":
print(f"Untrusted Docker sanity validation did not pass: {result}", file=sys.stderr)
sys.exit(1)
print("Untrusted Docker sanity validation passed.")
sys.exit(0)
print("Docker validation gate resolved to no runnable validation path.", file=sys.stderr)
sys.exit(1)
PY