-
Notifications
You must be signed in to change notification settings - Fork 0
291 lines (259 loc) · 10.7 KB
/
Copy pathcd.yml
File metadata and controls
291 lines (259 loc) · 10.7 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
name: CD - Container Publish
on:
push:
branches: [master, main]
tags:
- 'v*.*.*'
env:
BACKEND_IMAGE: jobhunter-backend
FRONTEND_IMAGE: jobhunter-frontend
GHCR_NAMESPACE: jasontm17
permissions:
contents: read
packages: write
jobs:
docker-hub-check:
name: Check Docker Hub credentials
runs-on: ubuntu-latest
if: >-
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/tags/v'))
outputs:
should_publish: ${{ steps.gate.outputs.should_publish }}
reason: ${{ steps.gate.outputs.reason }}
steps:
- name: Evaluate Docker Hub secrets
id: gate
env:
DH_USER: ${{ secrets.DOCKERHUB_USERNAME }}
DH_PASS: ${{ secrets.DOCKERHUB_PASSWORD }}
run: |
if [ -z "$DH_USER" ] || [ -z "$DH_PASS" ]; then
echo "should_publish=false" >> "$GITHUB_OUTPUT"
echo "reason=missing Docker Hub credentials" >> "$GITHUB_OUTPUT"
echo "::notice title=Docker Hub publish skipped::Add DOCKERHUB_USERNAME and DOCKERHUB_PASSWORD in repository Actions secrets to enable image publishing."
exit 0
fi
missing_scope=false
for image in "$BACKEND_IMAGE" "$FRONTEND_IMAGE"; do
scope="repository:${DH_USER}/${image}:pull,push"
status="$(curl --silent --show-error --output /tmp/dockerhub-token.json --write-out "%{http_code}" \
--user "${DH_USER}:${DH_PASS}" \
"https://auth.docker.io/token?service=registry.docker.io&scope=${scope}" || true)"
if [ "$status" != "200" ]; then
missing_scope=true
echo "::warning title=Docker Hub publish skipped::Credentials are present but do not have pull,push scope for ${DH_USER}/${image}. Create a Docker Hub access token with Read & Write permission."
fi
done
if [ "$missing_scope" = "true" ]; then
echo "should_publish=false" >> "$GITHUB_OUTPUT"
echo "reason=credentials missing Docker Hub pull,push scope" >> "$GITHUB_OUTPUT"
else
echo "should_publish=true" >> "$GITHUB_OUTPUT"
echo "reason=credentials valid for Docker Hub pull,push" >> "$GITHUB_OUTPUT"
fi
publish-docker-hub:
name: Publish to Docker Hub
runs-on: ubuntu-latest
needs: docker-hub-check
if: >-
needs.docker-hub-check.outputs.should_publish == 'true' &&
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/tags/v'))
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Docker metadata (backend)
id: meta-backend
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.BACKEND_IMAGE }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha,prefix=
flavor: |
latest=true
labels: |
org.opencontainers.image.title=Jobhunter Backend API
org.opencontainers.image.description=Jobhunter REST API backend - Spring Boot, JWT authentication, RBAC, Flyway, MySQL, and production MVP workflows.
org.opencontainers.image.source=https://github.com/JasonTM17/JobHunter_SpringBoot_RestfulAPI_React
org.opencontainers.image.licenses=MIT
org.opencontainers.image.vendor=Jobhunter
- name: Docker metadata (frontend)
id: meta-frontend
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.FRONTEND_IMAGE }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha,prefix=
flavor: |
latest=true
labels: |
org.opencontainers.image.title=Jobhunter Frontend Web
org.opencontainers.image.description=Jobhunter frontend - Next.js 16, TypeScript, responsive IT recruitment UI, E2E coverage, and visual regression.
org.opencontainers.image.source=https://github.com/JasonTM17/JobHunter_SpringBoot_RestfulAPI_React
org.opencontainers.image.licenses=MIT
org.opencontainers.image.vendor=Jobhunter
- name: Build and push backend
uses: docker/build-push-action@v6
with:
context: ./backend
push: true
tags: ${{ steps.meta-backend.outputs.tags }}
labels: ${{ steps.meta-backend.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: true
sbom: true
- name: Build and push frontend
uses: docker/build-push-action@v6
with:
context: ./frontend
push: true
tags: ${{ steps.meta-frontend.outputs.tags }}
labels: ${{ steps.meta-frontend.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: true
sbom: true
- name: Image digest (backend)
run: |
echo "Backend image: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.BACKEND_IMAGE }}"
echo "Tags: ${{ steps.meta-backend.outputs.tags }}"
- name: Image digest (frontend)
run: |
echo "Frontend image: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.FRONTEND_IMAGE }}"
echo "Tags: ${{ steps.meta-frontend.outputs.tags }}"
publish-ghcr:
name: Publish to GitHub Packages
runs-on: ubuntu-latest
if: >-
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/tags/v'))
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: GHCR metadata (backend)
id: ghcr-meta-backend
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.GHCR_NAMESPACE }}/${{ env.BACKEND_IMAGE }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha,prefix=
flavor: |
latest=true
labels: |
org.opencontainers.image.title=Jobhunter Backend API
org.opencontainers.image.description=Spring Boot API for the Jobhunter IT recruitment platform with JWT auth, RBAC, Flyway migrations, MySQL, Actuator metrics, and local production observability.
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.licenses=MIT
org.opencontainers.image.vendor=Jobhunter
- name: GHCR metadata (frontend)
id: ghcr-meta-frontend
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.GHCR_NAMESPACE }}/${{ env.FRONTEND_IMAGE }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha,prefix=
flavor: |
latest=true
labels: |
org.opencontainers.image.title=Jobhunter Frontend Web
org.opencontainers.image.description=Next.js frontend for the Jobhunter IT recruitment platform with responsive job search, candidate/recruiter/admin workspaces, E2E coverage, and visual regression.
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.licenses=MIT
org.opencontainers.image.vendor=Jobhunter
- name: Build and push backend to GHCR
uses: docker/build-push-action@v6
with:
context: ./backend
push: true
tags: ${{ steps.ghcr-meta-backend.outputs.tags }}
labels: ${{ steps.ghcr-meta-backend.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: true
sbom: true
- name: Build and push frontend to GHCR
uses: docker/build-push-action@v6
with:
context: ./frontend
push: true
tags: ${{ steps.ghcr-meta-frontend.outputs.tags }}
labels: ${{ steps.ghcr-meta-frontend.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: true
sbom: true
- name: GHCR summary
run: |
echo "## GitHub Packages" >> "$GITHUB_STEP_SUMMARY"
echo "Backend tags:" >> "$GITHUB_STEP_SUMMARY"
echo '${{ steps.ghcr-meta-backend.outputs.tags }}' >> "$GITHUB_STEP_SUMMARY"
echo "Frontend tags:" >> "$GITHUB_STEP_SUMMARY"
echo '${{ steps.ghcr-meta-frontend.outputs.tags }}' >> "$GITHUB_STEP_SUMMARY"
verify-tag-build:
name: Verify tag Docker build
runs-on: ubuntu-latest
needs: docker-hub-check
if: >-
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v') &&
needs.docker-hub-check.outputs.should_publish != 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Verify backend build
uses: docker/build-push-action@v6
with:
context: ./backend
push: false
load: true
tags: jobhunter-backend:verify
cache-from: type=gha
- name: Verify frontend build
uses: docker/build-push-action@v6
with:
context: ./frontend
push: false
load: true
tags: jobhunter-frontend:verify
cache-from: type=gha
- name: Docker images
run: docker images | grep jobhunter
- name: Summary
env:
PUBLISH_REASON: ${{ needs.docker-hub-check.outputs.reason }}
run: |
echo "## Release Docker verification" >> "$GITHUB_STEP_SUMMARY"
echo "Tag: ${{ github.ref_name }}" >> "$GITHUB_STEP_SUMMARY"
echo "Docker Hub publish: skipped because ${PUBLISH_REASON:-credentials are not configured}" >> "$GITHUB_STEP_SUMMARY"
echo "Backend image: jobhunter-backend:verify" >> "$GITHUB_STEP_SUMMARY"
echo "Frontend image: jobhunter-frontend:verify" >> "$GITHUB_STEP_SUMMARY"