-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (84 loc) · 2.96 KB
/
deploy.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Deploy
on:
push:
branches:
- main
paths:
- 'src-api/**/*'
- '.github/workflows/deploy.yml'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src-api
permissions:
contents: read
id-token: write # Required for Google Cloud
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Load target cache
uses: actions/cache/restore@v4
id: cache-restore
with:
path: |
/home/runner/work/attendance/attendance/src-api/target
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-rust-cache-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-rust-cache
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true
override: true
- name: Build
run: cargo build --release
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
- name: Login to Google Cloud
id: gcp-auth
uses: google-github-actions/auth@v2
with:
token_format: 'access_token'
project_id: ${{ secrets.GCP_PROJECT_ID }}
workload_identity_provider: ${{ secrets.GCP_WLIF_PROVIDER }}
service_account: ${{ secrets.GCP_SA }}
access_token_lifetime: 600s
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to Artifact Registry
uses: docker/login-action@v2
with:
registry: us-central1-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp-auth.outputs.access_token }}
- name: Build Docker image
run: |
docker build . -t onlycs/attendance:latest -t us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/attendance/attendance:latest
- name: Push Docker image
run: |
docker push us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/attendance/attendance:latest
docker push onlycs/attendance:latest
- name: Deploy to Cloud Run
run: |
gcloud run deploy attendance \
--image=us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/attendance/attendance:latest \
--platform=managed \
--region=us-central1 \
--allow-unauthenticated
- name: Save target cache
if: always() && (steps.cache-restore.outputs.cache-hit != 'true' || steps.cache-restore.outputs.cache-primary-key == '${{ runner.os }}-rust-cache')
uses: actions/cache/save@v4
with:
path: |
/home/runner/work/attendance/attendance/src-api/target
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-rust-cache-${{ hashFiles('**/Cargo.lock') }}