-
Notifications
You must be signed in to change notification settings - Fork 53
103 lines (87 loc) · 2.75 KB
/
deploy-api.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
101
102
103
---
name: Build and deploy API Docker image
on:
push:
branches:
- main
paths:
- src/rust/api/**
- src/rust/db/**
- src/rust/types/**
- src/rust/Cargo.toml
- src/rust/Cargo.lock
- src/rust/.dockerignore
- .github/workflows/deploy-api.yml
pull_request:
branches:
- main
paths:
- src/rust/api/**
- src/rust/db/**
- src/rust/types/**
- src/rust/Cargo.toml
- src/rust/Cargo.lock
- src/rust/.dockerignore
- .github/workflows/deploy-api.yml
jobs:
build:
name: Build API Docker image
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Configure Docker driver
run: docker buildx create --use --driver=docker-container
- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: ./src/rust
tags: asia-northeast1-docker.pkg.dev/econia-0/econia-backend/api:latest
file: ./src/rust/api/Dockerfile
outputs: type=docker,dest=/tmp/image.tar
cache-from: type=gha
cache-to: type=gha,mode=max
push: false
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: image
path: /tmp/image.tar
if: github.event_name != 'pull_request'
deploy:
name: Deploy API Docker image
runs-on: ubuntu-latest
needs: build
if: github.event_name != 'pull_request'
permissions:
id-token: write
steps:
- name: Authenticate to Google Cloud
id: "auth"
uses: google-github-actions/auth@v1
with:
workload_identity_provider: projects/153655225733/locations/global/workloadIdentityPools/github-actions-identity-pool/providers/github-actions-oidc-provider
service_account: "[email protected]"
token_format: "access_token"
create_credentials_file: false
- name: Log In to Artifact Registry
uses: docker/login-action@v2
with:
registry: asia-northeast1-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: image
path: /tmp
- name: Load Docker image
run: docker load -i /tmp/image.tar
- name: Push to Artifact Registry
run: docker push asia-northeast1-docker.pkg.dev/econia-0/econia-backend/api:latest