-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (67 loc) · 2.61 KB
/
deploy-backend.yml
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
name: Deploy Backend
on:
push:
branches:
- main
workflow_dispatch:
env:
PROJECT_ID: ${{ secrets.PROJECT_ID }}
PROJECT_NAME: ${{ secrets.PROJECT_NAME }}
REGION: ${{ secrets.GOOGLE_CLOUD_REGION }}
REPOSITORY: ${{ secrets.ARTIFACT_REGISTRY_REPOSITORY }}
IMAGE: ${{ secrets.DOCKER_IMAGE }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
jobs:
changes:
name: Changes
runs-on: ubuntu-24.04
outputs:
backend: ${{ steps.changes.outputs.frontend }}
workflows: ${{ steps.changes.outputs.workflows }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Check frontend files changed
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changes
with:
filters: |
backend:
- 'backend/**'
workflows:
- '.github/workflows/deploy-backend.yml'
build-and-push:
runs-on: ubuntu-24.04
needs: changes
if: needs.changes.outputs.backend == 'true' || needs.changes.outputs.workflows == 'true'
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- id: auth
uses: google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f # v2
with:
project_id: ${{ env.PROJECT_NAME }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@6189d56e4096ee891640bb02ac264be376592d6a # v2
- name: Configure Docker for Artifact Registry
run: |
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
- name: Build Docker image
run: |
docker build -t ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_NAME }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:${{ github.sha }} \
-f backend/Dockerfile .
- name: Push Docker image
run: |
docker push ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_NAME }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:${{ github.sha }}
- name: Deploy to Cloud Run
run: |
gcloud run deploy ${{ env.IMAGE }} \
--image ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_NAME }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:${{ github.sha }} \
--port="3000" \
--region ${{ env.REGION }} \
--max-instances=1 \
--ingress=internal-and-cloud-load-balancing \
--allow-unauthenticated \
--set-env-vars=LITESTREAM_BUCKET=${{ secrets.LITESTREAM_BUCKET }}