-
Notifications
You must be signed in to change notification settings - Fork 12
132 lines (117 loc) · 5.08 KB
/
main-cd.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
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
name: CD-Main
run-name: ${{ github.actor }} acitvates the actions 🚀
on:
workflow_dispatch:
branches: ['feat_system_cicd_enhancment']
inputs:
build-services:
description: 'build which services'
required: true
default: 'relay-frontend'
type: choice
options:
- relay-frontend
- contract
version:
description: 'current deploy version'
required: true
default: '0.0.1'
jobs:
build:
permissions:
contents: 'read'
id-token: 'write'
uses: ./.github/workflows/build-all.yml
with:
build-services: ${{ inputs.build-services }}
version: ${{ inputs.version }}
secrets: inherit
backend:
needs: build
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
steps:
- name: Production Code
uses: 'actions/checkout@v3'
- name: Authenticate to Google Cloud
id: auth
uses: 'google-github-actions/auth@v1'
with:
token_format: access_token
workload_identity_provider: '${{ secrets.WIF_PROVIDER }}'
service_account: '${{ secrets.WIF_SERVICE_ACCOUNT }}'
access_token_lifetime: 300s
## artifact registry auth setup
- name: Login to Artifact Registry
id: docker-auth
uses: docker/login-action@v1
with:
registry: ${{ vars.GAR_LOCATION }}-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v0
with:
service: ${{ vars.BACKEND_SERVICE }}
region: ${{ vars.REGION }}
image: ${{ vars.GAR_LOCATION }}-docker.pkg.dev/${{ vars.REPOSITORY }}/${{vars.BACKEND_SERVICE}}:${{inputs.version}}
# add ENV as below
env_vars: |
TWITTER_CLIENT_ID=${{ secrets.TWITTER_CLIENT_ID }}
TWITTER_CLIENT_KEY=${{ secrets.TWITTER_CLIENT_KEY }}
TENDERLY_ACCESS_KEY=${{ secrets.TENDERLY_ACCESS_KEY }}
TENDERLY_PROJECT_SLUG=${{ secrets.TENDERLY_PROJECT_SLUG }}
TENDERLY_DEVNET_TEMPLATE=${{ secrets.TENDERLY_DEVNET_TEMPLATE }}
TENDERLY_ACCOUNT_ID=${{ secrets.TENDERLY_ACCOUNT_ID }}
CLIENT_URL=${{ vars.CLIENT_URL }}
CALLBACK_URL=${{ vars.CALLBACK_URL }}
- name: Allow public access
id: unauthenticated
run: gcloud run services add-iam-policy-binding ${{ vars.BACKEND_SERVICE }} --region=${{ vars.REGION }} --member="allUsers" --role="roles/run.invoker"
- name: Show Output
run: echo ${{ steps.deploy.outputs.url }}
frontend:
needs: build
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
steps:
- name: Production Code
uses: 'actions/checkout@v3'
- name: Authenticate to Google Cloud
id: auth
uses: 'google-github-actions/auth@v1'
with:
token_format: access_token
workload_identity_provider: '${{ secrets.WIF_PROVIDER }}'
service_account: '${{ secrets.WIF_SERVICE_ACCOUNT }}'
access_token_lifetime: 900s
## artifact registry auth setup
- name: Login to Artifact Registry
id: docker-auth
uses: docker/login-action@v1
with:
registry: ${{ vars.GAR_LOCATION }}-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v0
with:
service: ${{ vars.FRONTEND_SERVICE }}
region: ${{ vars.REGION }}
image: ${{ vars.GAR_LOCATION }}-docker.pkg.dev/${{ vars.REPOSITORY }}/${{vars.FRONTEND_SERVICE}}:${{inputs.version}}
## set --max-old-space-size=8192 for node.js to increase memory limit
env_vars: |
ENV=${{ vars.ENV }}
STAGE_SERVER=${{ vars.ENV }}_SERVER
NODE_OPTIONS=${{ vars.NODE_OPTIONS }}
- name: Allow public access
id: unauthenticated
run: gcloud run services add-iam-policy-binding ${{ vars.FRONTEND_SERVICE }} --region=${{ vars.REGION }} --member="allUsers" --role="roles/run.invoker"
- name: Show Output
run: echo ${{ steps.deploy.outputs.url }}