-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (130 loc) · 5.12 KB
/
docker.yml
File metadata and controls
143 lines (130 loc) · 5.12 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
name: Docker Scan & Promote
# Runs after Stack Tests completes on main — promotes sha-xxx → latest.
# "latest" is NEVER set during build. Only this workflow can set it,
# and only after all tests pass. If any test fails, latest stays unchanged.
on:
workflow_run:
workflows: ["Stack Tests"]
types: [completed]
workflow_dispatch:
inputs:
sha:
description: 'Full commit SHA to promote (defaults to latest main)'
required: false
env:
REGISTRY: ghcr.io
jobs:
scan:
name: Scan ${{ matrix.image }}
if: >
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main')
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
packages: read
strategy:
fail-fast: false
matrix:
image:
- base
- backend
- frontend
- cert-generator
steps:
- uses: actions/checkout@v6
- name: Compute image ref
id: ref
run: |
PREFIX="${GITHUB_REPOSITORY_OWNER,,}/integr8scode"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
SHA="${{ github.event.inputs.sha || github.sha }}"
else
SHA="${{ github.event.workflow_run.head_sha }}"
fi
TAG="sha-${SHA::7}"
echo "image=${{ env.REGISTRY }}/$PREFIX/${{ matrix.image }}:$TAG" >> $GITHUB_OUTPUT
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.34.1
with:
image-ref: ${{ steps.ref.outputs.image }}
format: 'sarif'
output: 'trivy-${{ matrix.image }}-results.sarif'
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
timeout: '5m0s'
trivyignores: 'backend/.trivyignore'
version: 'v0.68.2'
- name: Upload Trivy scan results
if: always()
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: 'trivy-${{ matrix.image }}-results.sarif'
category: 'trivy-${{ matrix.image }}'
# Promote SHA tag → latest using crane (registry-level manifest copy, no rebuild)
promote:
name: Promote to Latest
needs: [scan]
if: >
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main')
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install crane
uses: imjasonh/setup-crane@v0.5
- name: Promote images (SHA → latest)
run: |
PREFIX="${GITHUB_REPOSITORY_OWNER,,}/integr8scode"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
SHA="${{ github.event.inputs.sha || github.sha }}"
else
SHA="${{ github.event.workflow_run.head_sha }}"
fi
TAG="sha-${SHA::7}"
echo "Promoting tag: $TAG → latest"
echo ""
crane copy "$REGISTRY/$PREFIX/base:$TAG" "$REGISTRY/$PREFIX/base:latest"
crane copy "$REGISTRY/$PREFIX/backend:$TAG" "$REGISTRY/$PREFIX/backend:latest"
crane copy "$REGISTRY/$PREFIX/frontend:$TAG" "$REGISTRY/$PREFIX/frontend:latest"
crane copy "$REGISTRY/$PREFIX/cert-generator:$TAG" "$REGISTRY/$PREFIX/cert-generator:latest"
summary:
name: Summary
needs: [promote]
runs-on: ubuntu-latest
steps:
- name: Generate summary
run: |
PREFIX="${GITHUB_REPOSITORY_OWNER,,}/integr8scode"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
SHA="${{ github.event.inputs.sha || github.sha }}"
else
SHA="${{ github.event.workflow_run.head_sha }}"
fi
TAG="sha-${SHA::7}"
echo "## Docker Images Promoted to Latest" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
echo "Images promoted manually from \`$TAG\` to \`latest\` — Stack Tests may not have run." >> $GITHUB_STEP_SUMMARY
else
echo "All Stack Tests passed. Images promoted from \`$TAG\` to \`latest\`." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Image | Pull Command |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------------|" >> $GITHUB_STEP_SUMMARY
echo "| Base | \`docker pull $REGISTRY/$PREFIX/base:latest\` |" >> $GITHUB_STEP_SUMMARY
echo "| Backend | \`docker pull $REGISTRY/$PREFIX/backend:latest\` |" >> $GITHUB_STEP_SUMMARY
echo "| Frontend | \`docker pull $REGISTRY/$PREFIX/frontend:latest\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Security Scans" >> $GITHUB_STEP_SUMMARY
echo "All 4 images scanned with Trivy (CRITICAL + HIGH, unfixed ignored)." >> $GITHUB_STEP_SUMMARY