-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (138 loc) · 4.92 KB
/
back.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Back - Test, Build, and Deploy to GCP
on:
push:
paths:
- 'src/back/**'
- '.github/workflows/back.yml'
- '.github/actions/back/**'
- 'src/common/**'
- 'data/migrations/**'
- 'data/knexfile.js'
- 'data/package*.json'
defaults:
run:
working-directory: src/back
permissions:
id-token: write
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/cache@v3
id: cache
with:
path: ~/.cache/firebase/emulators
key: ${{ runner.os }}-firebase-emulators-${{ hashFiles('~/.cache/firebase/emulators/**') }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: src/back/.node-version
- name: Install Dependencies
run: |
npm ci
cd ../common && npm ci
- name: Test
run: |
npm run lint
npm run test:ci
deploy-staging:
name: Migration DB, Build, and Deploy to Staging
runs-on: ubuntu-latest
needs: test
environment:
name: Staging
if: github.ref_name == 'staging'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: DB Migrations
uses: ./.github/actions/back/db-migrations
with:
environment: Staging
project_id: ${{ secrets.PROJECT_ID }}
identity_provider: ${{ secrets.IDENTITY_PROVIDER }}
service_account_email: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
cloudsql_instance: ${{ secrets.CLOUDSQL_INSTANCE }}
env:
DATABASE_ADMIN_PASSWORD: ${{ secrets.DATABASE_ADMIN_PASSWORD }}
- name: 🚀 Deploy
uses: agrc/cloud-run-docker-deploy-composite-action@v1
with:
docker-context: ./src
docker-file: ./src/back/Dockerfile
identity-provider: ${{ secrets.IDENTITY_PROVIDER }}
service-account-email: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
project-id: ${{ secrets.PROJECT_ID }}
service: api
flags: |
--service-account=cloud-run-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
--max-instances=10
--min-instances=0
--set-cloudsql-instances=${{ secrets.CLOUDSQL_INSTANCE }}
--allow-unauthenticated
env-vars: |
ADMIN_EMAIL=${{ secrets.ADMIN_EMAIL }}
API=${{ secrets.API }}
DATABASE_HOST=${{ secrets.DATABASE_HOST }}
ENVIRONMENT=staging
PROJECT_ID=${{ secrets.PROJECT_ID }}
WEBSITE=${{ secrets.WEBSITE }}
mounted-secrets: |
/secrets/client_id/value=client-id:latest,
/secrets/database_password/value=database-password:latest,
/secrets/sendgrid_api_key/value=sendgrid-api-key:latest
/secrets/apple_sign_in_props/value=apple-sign-in-props:latest
deploy-prod:
name: Migration DB, Build, and Deploy to Production
runs-on: ubuntu-latest
needs: test
environment:
name: Production
if: github.ref_name == 'production'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: DB Migrations
uses: ./.github/actions/back/db-migrations
with:
environment: Production
project_id: ${{ secrets.PROJECT_ID }}
identity_provider: ${{ secrets.IDENTITY_PROVIDER }}
service_account_email: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
cloudsql_instance: ${{ secrets.CLOUDSQL_INSTANCE }}
env:
DATABASE_ADMIN_PASSWORD: ${{ secrets.DATABASE_ADMIN_PASSWORD }}
- name: 🚀 Deploy
uses: agrc/cloud-run-docker-deploy-composite-action@v1
with:
docker-context: ./src
docker-file: ./src/back/Dockerfile
identity-provider: ${{ secrets.IDENTITY_PROVIDER }}
service-account-email: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
project-id: ${{ secrets.PROJECT_ID }}
service: api
flags: |
--service-account=cloud-run-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
--max-instances=10
--min-instances=1
--set-cloudsql-instances=${{ secrets.CLOUDSQL_INSTANCE }}
--allow-unauthenticated
env-vars: |
ADMIN_EMAIL=${{ secrets.ADMIN_EMAIL }}
API=${{ secrets.API }}
DATABASE_HOST=${{ secrets.DATABASE_HOST }}
ENVIRONMENT=production
PROJECT_ID=${{ secrets.PROJECT_ID }}
WEBSITE=${{ secrets.WEBSITE }}
mounted-secrets: |
/secrets/client_id/value=client-id:latest,
/secrets/database_password/value=database-password:latest,
/secrets/sendgrid_api_key/value=sendgrid-api-key:latest
/secrets/apple_sign_in_props/value=apple-sign-in-props:latest