-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (68 loc) · 2.63 KB
/
Copy pathdocker-build.yml
File metadata and controls
79 lines (68 loc) · 2.63 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
name: Docker Build
on:
push:
branches: [develop, main]
pull_request:
branches: [develop, main]
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: true
env:
AR_REGION: asia-northeast3
GCP_PROJECT_ID: project-4f918446-ebe5-4774-a52
AR_REPO: speedcam
jobs:
build:
name: ${{ matrix.service.name }}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
strategy:
fail-fast: false
matrix:
service:
- name: main
dockerfile: docker/Dockerfile.main
- name: ocr
dockerfile: docker/Dockerfile.ocr
- name: alert
dockerfile: docker/Dockerfile.alert
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Authenticate to Google Cloud
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.WIF_PROVIDER }}
service_account: ${{ secrets.WIF_SERVICE_ACCOUNT }}
- name: Configure Docker for Artifact Registry
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: gcloud auth configure-docker ${{ env.AR_REGION }}-docker.pkg.dev
- name: Build and push ${{ matrix.service.name }} image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.service.dockerfile }}
push: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
cache-from: type=gha,scope=${{ matrix.service.name }}
cache-to: type=gha,mode=max,scope=${{ matrix.service.name }}
tags: |
${{ env.AR_REGION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.AR_REPO }}/speedcam-${{ matrix.service.name }}:latest
${{ env.AR_REGION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.AR_REPO }}/speedcam-${{ matrix.service.name }}:${{ github.sha }}
trigger-deploy:
name: Trigger Deploy
needs: build
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Trigger depoly CD workflow
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.BACKEND_DEPLOY_TOKEN }}" \
https://api.github.com/repos/${{ github.repository_owner }}/depoly/dispatches \
-d '{"event_type":"deploy-backend","client_payload":{"image_tag":"${{ github.sha }}","triggered_by":"${{ github.actor }}"}}'