-
Notifications
You must be signed in to change notification settings - Fork 0
420 lines (366 loc) · 14.9 KB
/
dockerhub.yml
File metadata and controls
420 lines (366 loc) · 14.9 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
name: 🐳 Build & Push Docker Images
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: "Release tag (e.g., v1.2.3 or 1.2.3)"
required: true
default: "latest"
permissions:
contents: read
concurrency:
group: dockerhub-publish-${{ github.ref }}
cancel-in-progress: true
jobs:
build-backend:
name: 🔧 Build & Push Backend
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📝 Derive version tags
id: version
shell: bash
run: |
if [ "${{ github.event_name }}" = "release" ]; then
RAW="${GITHUB_REF#refs/tags/}"
else
RAW="${{ github.event.inputs.version }}"
fi
if [ -z "$RAW" ] || [ "$RAW" = "latest" ]; then
RELEASE_TAG="latest"
SEMVER="latest"
elif [[ "$RAW" =~ ^v ]]; then
RELEASE_TAG="$RAW"
SEMVER="${RAW#v}"
else
RELEASE_TAG="v$RAW"
SEMVER="$RAW"
fi
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
echo "SEMVER=$SEMVER" >> $GITHUB_ENV
echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
echo "✅ Version: $RELEASE_TAG (semver: $SEMVER, sha: ${GITHUB_SHA::7})"
- name: 🔧 Compute backend image name
shell: bash
run: |
USER_LC="${{ secrets.DOCKERHUB_USERNAME }}"
USER_LC="${USER_LC,,}"
IMAGE="docker.io/${USER_LC}/gitpilot-backend"
echo "BACKEND_IMAGE=$IMAGE" >> $GITHUB_ENV
echo "📦 Backend image: $IMAGE"
- name: 🏗️ Set up QEMU (multi-arch)
uses: docker/setup-qemu-action@v3
- name: 🏗️ Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 🔐 Docker Hub login
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 🏷️ Docker metadata (backend)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.BACKEND_IMAGE }}
flavor: |
latest=auto
tags: |
type=raw,value=${{ env.SEMVER }},enable=${{ env.SEMVER != 'latest' }}
type=raw,value=latest,enable=${{ github.event_name == 'release' || env.SEMVER == 'latest' }}
type=raw,value=sha-${{ env.SHORT_SHA }}
type=semver,pattern={{version}},value=${{ env.SEMVER }},enable=${{ env.SEMVER != 'latest' }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.SEMVER }},enable=${{ env.SEMVER != 'latest' }}
labels: |
org.opencontainers.image.title=gitpilot-backend
org.opencontainers.image.description=GitPilot Backend - Python FastAPI server
org.opencontainers.image.url=https://github.com/${{ github.repository }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ env.SEMVER }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ env.BUILD_DATE }}
- name: 🔨 Build & push backend
id: build
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.backend
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=backend
cache-to: type=gha,mode=max,scope=backend
build-args: |
BUILD_VERSION=${{ env.SEMVER }}
BUILD_COMMIT=${{ github.sha }}
BUILD_DATE=${{ env.BUILD_DATE }}
- name: ✅ Verify backend health endpoint
shell: bash
run: |
REF="$(echo "${{ steps.meta.outputs.tags }}" | head -n1)"
echo "🔍 Testing backend container: $REF"
# Run container in background with basic health check
docker run -d --name test-backend \
-e GITHUB_CLIENT_ID=test \
-e GITHUB_CLIENT_SECRET=test \
-e OPENAI_API_KEY=test \
-p 8000:8000 \
"$REF"
# Wait for container to start (max 30 seconds)
for i in {1..30}; do
if docker exec test-backend curl -f http://localhost:8000/api/health 2>/dev/null; then
echo "✅ Backend health check passed!"
docker stop test-backend
docker rm test-backend
exit 0
fi
echo "⏳ Waiting for backend to start... ($i/30)"
sleep 1
done
echo "❌ Backend health check failed"
docker logs test-backend
docker stop test-backend
docker rm test-backend
exit 1
- name: 📋 Inspect multi-arch manifest
if: always()
shell: bash
run: |
if [ "${{ env.SEMVER }}" != "latest" ]; then
echo "🔍 Inspecting ${{ env.SEMVER }}..."
docker buildx imagetools inspect "${{ env.BACKEND_IMAGE }}:${{ env.SEMVER }}" || true
fi
if [ "${{ github.event_name }}" = "release" ] || [ "${{ env.SEMVER }}" = "latest" ]; then
echo "🔍 Inspecting latest..."
docker buildx imagetools inspect "${{ env.BACKEND_IMAGE }}:latest" || true
fi
build-frontend:
name: 🎨 Build & Push Frontend
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📝 Derive version tags
id: version
shell: bash
run: |
if [ "${{ github.event_name }}" = "release" ]; then
RAW="${GITHUB_REF#refs/tags/}"
else
RAW="${{ github.event.inputs.version }}"
fi
if [ -z "$RAW" ] || [ "$RAW" = "latest" ]; then
RELEASE_TAG="latest"
SEMVER="latest"
elif [[ "$RAW" =~ ^v ]]; then
RELEASE_TAG="$RAW"
SEMVER="${RAW#v}"
else
RELEASE_TAG="v$RAW"
SEMVER="$RAW"
fi
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
echo "SEMVER=$SEMVER" >> $GITHUB_ENV
echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
echo "✅ Version: $RELEASE_TAG (semver: $SEMVER, sha: ${GITHUB_SHA::7})"
- name: 🎨 Compute frontend image name
shell: bash
run: |
USER_LC="${{ secrets.DOCKERHUB_USERNAME }}"
USER_LC="${USER_LC,,}"
IMAGE="docker.io/${USER_LC}/gitpilot-frontend"
echo "FRONTEND_IMAGE=$IMAGE" >> $GITHUB_ENV
echo "📦 Frontend image: $IMAGE"
- name: 🏗️ Set up QEMU (multi-arch)
uses: docker/setup-qemu-action@v3
- name: 🏗️ Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 🔐 Docker Hub login
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 🏷️ Docker metadata (frontend)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.FRONTEND_IMAGE }}
flavor: |
latest=auto
tags: |
type=raw,value=${{ env.SEMVER }},enable=${{ env.SEMVER != 'latest' }}
type=raw,value=latest,enable=${{ github.event_name == 'release' || env.SEMVER == 'latest' }}
type=raw,value=sha-${{ env.SHORT_SHA }}
type=semver,pattern={{version}},value=${{ env.SEMVER }},enable=${{ env.SEMVER != 'latest' }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.SEMVER }},enable=${{ env.SEMVER != 'latest' }}
labels: |
org.opencontainers.image.title=gitpilot-frontend
org.opencontainers.image.description=GitPilot Frontend - React/Vite with nginx
org.opencontainers.image.url=https://github.com/${{ github.repository }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ env.SEMVER }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ env.BUILD_DATE }}
- name: 🔨 Build & push frontend
id: build
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.frontend
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=frontend
cache-to: type=gha,mode=max,scope=frontend
build-args: |
BUILD_VERSION=${{ env.SEMVER }}
BUILD_COMMIT=${{ github.sha }}
BUILD_DATE=${{ env.BUILD_DATE }}
- name: ✅ Verify frontend serves correctly
shell: bash
run: |
REF="$(echo "${{ steps.meta.outputs.tags }}" | head -n1)"
echo "🔍 Testing frontend container: $REF"
# Run container in background
docker run -d --name test-frontend -p 8080:80 "$REF"
# Wait for nginx to start (max 10 seconds)
for i in {1..10}; do
if curl -f http://localhost:8080/ 2>/dev/null | grep -q "<!doctype html>"; then
echo "✅ Frontend serves HTML correctly!"
docker stop test-frontend
docker rm test-frontend
exit 0
fi
echo "⏳ Waiting for frontend to start... ($i/10)"
sleep 1
done
echo "❌ Frontend verification failed"
docker logs test-frontend
docker stop test-frontend
docker rm test-frontend
exit 1
- name: 📋 Inspect multi-arch manifest
if: always()
shell: bash
run: |
if [ "${{ env.SEMVER }}" != "latest" ]; then
echo "🔍 Inspecting ${{ env.SEMVER }}..."
docker buildx imagetools inspect "${{ env.FRONTEND_IMAGE }}:${{ env.SEMVER }}" || true
fi
if [ "${{ github.event_name }}" = "release" ] || [ "${{ env.SEMVER }}" = "latest" ]; then
echo "🔍 Inspecting latest..."
docker buildx imagetools inspect "${{ env.FRONTEND_IMAGE }}:latest" || true
fi
test-integration:
name: 🧪 Integration Test
needs: [build-backend, build-frontend]
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 🔐 Docker Hub login
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 🧪 Test both containers together
shell: bash
run: |
USER_LC="${{ secrets.DOCKERHUB_USERNAME }}"
USER_LC="${USER_LC,,}"
echo "🚀 Starting integration test..."
# Create a test docker-compose file
cat > docker-compose.test.yml <<EOF
version: '3.8'
services:
backend:
image: docker.io/${USER_LC}/gitpilot-backend:latest
environment:
- GITHUB_CLIENT_ID=test
- GITHUB_CLIENT_SECRET=test
- OPENAI_API_KEY=test
- CORS_ORIGINS=http://localhost
ports:
- "8000:8000"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/api/health"]
interval: 5s
timeout: 3s
retries: 5
frontend:
image: docker.io/${USER_LC}/gitpilot-frontend:latest
ports:
- "3000:80"
depends_on:
backend:
condition: service_healthy
EOF
# Start services
docker-compose -f docker-compose.test.yml up -d
# Wait for frontend
echo "⏳ Waiting for services to be ready..."
sleep 10
# Test backend
if curl -f http://localhost:8000/api/health; then
echo "✅ Backend health check passed"
else
echo "❌ Backend health check failed"
docker-compose -f docker-compose.test.yml logs
docker-compose -f docker-compose.test.yml down
exit 1
fi
# Test frontend
if curl -f http://localhost:3000/ | grep -q "<!doctype html>"; then
echo "✅ Frontend serves correctly"
else
echo "❌ Frontend check failed"
docker-compose -f docker-compose.test.yml logs
docker-compose -f docker-compose.test.yml down
exit 1
fi
echo "✅ Integration test passed!"
docker-compose -f docker-compose.test.yml down
summary:
name: 📊 Deployment Summary
needs: [build-backend, build-frontend, test-integration]
runs-on: ubuntu-latest
if: always()
steps:
- name: 📊 Print summary
shell: bash
run: |
USER_LC="${{ secrets.DOCKERHUB_USERNAME }}"
USER_LC="${USER_LC,,}"
echo "## 🐳 Docker Images Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Backend" >> $GITHUB_STEP_SUMMARY
echo "- 📦 \`docker.io/${USER_LC}/gitpilot-backend:latest\`" >> $GITHUB_STEP_SUMMARY
echo "- 📦 \`docker.io/${USER_LC}/gitpilot-backend:sha-${GITHUB_SHA::7}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Frontend" >> $GITHUB_STEP_SUMMARY
echo "- 📦 \`docker.io/${USER_LC}/gitpilot-frontend:latest\`" >> $GITHUB_STEP_SUMMARY
echo "- 📦 \`docker.io/${USER_LC}/gitpilot-frontend:sha-${GITHUB_SHA::7}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Pull Commands" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "docker pull ${USER_LC}/gitpilot-backend:latest" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${USER_LC}/gitpilot-frontend:latest" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Docker Compose" >> $GITHUB_STEP_SUMMARY
echo '```yaml' >> $GITHUB_STEP_SUMMARY
echo "services:" >> $GITHUB_STEP_SUMMARY
echo " backend:" >> $GITHUB_STEP_SUMMARY
echo " image: ${USER_LC}/gitpilot-backend:latest" >> $GITHUB_STEP_SUMMARY
echo " frontend:" >> $GITHUB_STEP_SUMMARY
echo " image: ${USER_LC}/gitpilot-frontend:latest" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY