@@ -9,215 +9,30 @@ concurrency:
9
9
cancel-in-progress : true
10
10
11
11
jobs :
12
- deploy-python-dev :
13
- name : Deploy python to staging
14
- needs : test
15
- runs-on : ubuntu-latest
16
- if : github.ref == 'refs/heads/dev'
17
- environment :
18
- name : dev
19
- permissions :
20
- id-token : write
21
- contents : read
22
-
23
- steps :
24
- - name : ⬇️ Checkout code
25
- uses : actions/checkout@v4
26
- with :
27
- show-progress : false
28
-
29
- - name : 🗝️ Authenticate to Google Cloud
30
- id : auth
31
- uses : google-github-actions/auth@v2
32
- with :
33
- workload_identity_provider : ${{ secrets.IDENTITY_PROVIDER }}
34
- service_account : ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
35
- token_format : ' access_token'
36
-
37
- - name : 🐳 Set up Docker Buildx
38
- id : builder
39
- uses : docker/setup-buildx-action@v3
40
-
41
- - name : 🗝️ Authenticate Docker to Google Cloud
42
- uses : docker/login-action@v3
43
- with :
44
- registry : us-central1-docker.pkg.dev
45
- username : oauth2accesstoken
46
- password : ${{ steps.auth.outputs.access_token }}
47
-
48
- - name : 🏷️ Extract tags from GitHub
49
- id : meta
50
- uses : docker/metadata-action@v5
51
- with :
52
- github-token : ${{ secrets.GITHUB_TOKEN }}
53
- images : us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/images/job
54
- tags : |
55
- type=ref,suffix=-{{sha}},event=branch
56
- type=ref,prefix=pr-,suffix=-{{sha}},event=pr
57
- type=semver,pattern={{version}}
58
- latest
59
-
60
- - name : 📦 Build and push image
61
- uses : docker/build-push-action@v6
62
- with :
63
- builder : ${{ steps.builder.outputs.name }}
64
- tags : ${{ steps.meta.outputs.tags }}
65
- context : .
66
- file : ./Dockerfile
67
- push : true
68
- cache-from : type=gha
69
- cache-to : type=gha,mode=max
70
- provenance : false
71
-
72
- - name : ☁️ Set up Cloud SDK
73
- uses : google-github-actions/setup-gcloud@v2
74
-
75
- - name : 🚀 Deploy to Cloud Run Job
76
- uses : google-github-actions/deploy-cloudrun@v2
77
- with :
78
- project_id : secrets.PROJECT_ID
79
- region : us-central1
80
- image : us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/images/job:latest
81
- job : default
82
- secrets : /secrets/app/secrets.json=skid-secrets:latest
83
- timeout : 3h
84
- flags : >
85
- '--cpu=1
86
- --memory=3Gi
87
- --service-account=cloud-run-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
88
- --timeout=3h
89
- --max-instances=1
90
- --max-retries=0
91
- --parallelism=0'
92
-
93
- - name : 🕰️ Create Cloud Scheduler
94
- run : |
95
- if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep saturday-evening)" ]; then
96
- gcloud scheduler jobs create http saturday-evening \
97
- --description="Trigger the nfhl-skid bot once a week on saturday evening" \
98
- --schedule="0 3 * * 6" \
99
- --time-zone=America/Denver \
100
- --location=us-central1 \
101
- --uri="https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${{ secrets.PROJECT_ID }}/jobs/default:run" \
102
- --oauth-service-account-email=scheduler-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
103
- else
104
- gcloud scheduler jobs update http saturday-evening \
105
- --description="Trigger the nfhl-skid bot once a week on saturday evening" \
106
- --schedule="0 3 * * 6" \
107
- --time-zone=America/Denver \
108
- --location=us-central1 \
109
- --uri="https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${{ secrets.PROJECT_ID }}/jobs/default:run" \
110
- --oauth-service-account-email=scheduler-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
111
- fi
112
-
113
- deploy-python-prod :
12
+ deploy-cloudrun-prod :
114
13
name : Deploy python production
115
- needs : test
116
14
runs-on : ubuntu-latest
117
- if : github.ref == 'refs/heads/ main'
15
+ if : github.ref_name == 'main'
118
16
environment :
119
17
name : prod
120
18
permissions :
121
19
id-token : write
122
20
contents : read
123
21
124
22
steps :
125
- - name : ⬇️ Checkout code
23
+ - name : ⬇️ Set up code
126
24
uses : actions/checkout@v4
127
25
with :
128
26
show-progress : false
129
27
130
- - name : 🗝️ Authenticate to Google Cloud
131
- id : auth
132
- uses : google-github-actions/auth@v2
133
- with :
134
- workload_identity_provider : ${{ secrets.IDENTITY_PROVIDER }}
135
- service_account : ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
136
- token_format : ' access_token'
137
-
138
- - name : 🐳 Set up Docker Buildx
139
- id : builder
140
- uses : docker/setup-buildx-action@v3
141
-
142
- - name : 🗝️ Authenticate Docker to Google Cloud
143
- uses : docker/login-action@v3
144
- with :
145
- registry : us-central1-docker.pkg.dev
146
- username : oauth2accesstoken
147
- password : ${{ steps.auth.outputs.access_token }}
148
-
149
- - name : 🏷️ Extract tags from GitHub
150
- id : meta
151
- uses : docker/metadata-action@v5
152
- with :
153
- github-token : ${{ secrets.GITHUB_TOKEN }}
154
- images : us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/images/job
155
- tags : |
156
- type=ref,suffix=-{{sha}},event=branch
157
- type=ref,prefix=pr-,suffix=-{{sha}},event=pr
158
- type=semver,pattern={{version}}
159
- latest
160
-
161
- - name : 📦 Build and push image
162
- uses : docker/build-push-action@v6
28
+ - name : 🚀 Deploy
29
+ uses : ./.github/actions/deploy-cloudrun
30
+ timeout-minutes : 15
163
31
with :
164
- builder : ${{ steps.builder.outputs.name }}
165
- tags : ${{ steps.meta.outputs.tags }}
166
- context : .
167
- file : ./Dockerfile
168
- push : true
169
- cache-from : type=gha
170
- cache-to : type=gha,mode=max
171
- provenance : false
172
-
173
- - name : ☁️ Set up Cloud SDK
174
- uses : google-github-actions/setup-gcloud@v2
175
-
176
- - name : 🚀 Deploy to Cloud Run Job
177
- run : |
178
- if [ ! "$(gcloud run jobs list | grep default)" ]; then
179
- gcloud run jobs create default \
180
- --region us-central1 \
181
- --image us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/images/job:latest \
182
- --service-account cloud-run-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com \
183
- --memory=3Gi \
184
- --cpu=1 \
185
- --max-retries 0 \
186
- --parallelism 0 \
187
- --set-secrets=/secrets/app/secrets.json=skid-secrets:latest \
188
- --task-timeout 3h
189
- else
190
- gcloud run jobs update default \
191
- --region us-central1 \
192
- --image us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/images/job:latest \
193
- --service-account cloud-run-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com \
194
- --memory=3Gi \
195
- --cpu=1 \
196
- --max-retries 0 \
197
- --parallelism 0 \
198
- --set-secrets=/secrets/app/secrets.json=skid-secrets:latest \
199
- --task-timeout 3h
200
- fi
201
-
202
- - name : 🕰️ Create Cloud Scheduler
203
- run : |
204
- if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep saturday-evening)" ]; then
205
- gcloud scheduler jobs create http saturday-evening \
206
- --description="Trigger the nfhl-skid bot once a week on saturday evening" \
207
- --schedule="0 3 * * 6" \
208
- --time-zone=America/Denver \
209
- --location=us-central1 \
210
- --uri="https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${{ secrets.PROJECT_ID }}/jobs/default:run" \
211
- --oauth-service-account-email=scheduler-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
212
- else
213
- gcloud scheduler jobs update http saturday-evening \
214
- --description="Trigger the nfhl-skid bot once a week on saturday evening" \
215
- --schedule="0 3 * * 6" \
216
- --time-zone=America/Denver \
217
- --location=us-central1 \
218
- --uri="https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${{ secrets.PROJECT_ID }}/jobs/default:run" \
219
- --oauth-service-account-email=scheduler-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
220
- fi
32
+ project_id : ${{ secrets.PROJECT_ID }}
33
+ identity_provider : ${{ secrets.IDENTITY_PROVIDER }}
34
+ service_account_email : ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
35
+ github_token : ${{ secrets.GITHUB_TOKEN }}
221
36
222
37
deploy-ui-prod :
223
38
name : Deploy UI to production
0 commit comments