@@ -9,113 +9,30 @@ concurrency:
9
9
cancel-in-progress : true
10
10
11
11
jobs :
12
- deploy-python -prod :
12
+ deploy-cloudrun -prod :
13
13
name : Deploy python production
14
14
runs-on : ubuntu-latest
15
- if : github.ref == 'refs/heads/ main'
15
+ if : github.ref_name == 'main'
16
16
environment :
17
17
name : prod
18
18
permissions :
19
19
id-token : write
20
20
contents : read
21
21
22
22
steps :
23
- - name : ⬇️ Checkout code
23
+ - name : ⬇️ Set up code
24
24
uses : actions/checkout@v4
25
25
with :
26
26
show-progress : false
27
27
28
- - name : 🗝️ Authenticate to Google Cloud
29
- id : auth
30
- uses : google-github-actions/auth@v2
31
- with :
32
- workload_identity_provider : ${{ secrets.IDENTITY_PROVIDER }}
33
- service_account : ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
34
- token_format : ' access_token'
35
-
36
- - name : 🐳 Set up Docker Buildx
37
- id : builder
38
- uses : docker/setup-buildx-action@v3
39
-
40
- - name : 🗝️ Authenticate Docker to Google Cloud
41
- uses : docker/login-action@v3
42
- with :
43
- registry : us-central1-docker.pkg.dev
44
- username : oauth2accesstoken
45
- password : ${{ steps.auth.outputs.access_token }}
46
-
47
- - name : 🏷️ Extract tags from GitHub
48
- id : meta
49
- uses : docker/metadata-action@v5
50
- with :
51
- github-token : ${{ secrets.GITHUB_TOKEN }}
52
- images : us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/images/job
53
- tags : |
54
- type=ref,suffix=-{{sha}},event=branch
55
- type=ref,prefix=pr-,suffix=-{{sha}},event=pr
56
- type=semver,pattern={{version}}
57
- latest
58
-
59
- - name : 📦 Build and push image
60
- uses : docker/build-push-action@v6
28
+ - name : 🚀 Deploy
29
+ uses : ./.github/actions/deploy-cloudrun
30
+ timeout-minutes : 15
61
31
with :
62
- builder : ${{ steps.builder.outputs.name }}
63
- tags : ${{ steps.meta.outputs.tags }}
64
- context : .
65
- file : ./Dockerfile
66
- push : true
67
- cache-from : type=gha
68
- cache-to : type=gha,mode=max
69
- provenance : false
70
-
71
- - name : ☁️ Set up Cloud SDK
72
- uses : google-github-actions/setup-gcloud@v2
73
-
74
- - name : 🚀 Deploy to Cloud Run Job
75
- run : |
76
- if [ ! "$(gcloud run jobs list | grep default)" ]; then
77
- gcloud run jobs create default \
78
- --region us-central1 \
79
- --image us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/images/job:latest \
80
- --service-account cloud-run-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com \
81
- --memory=3Gi \
82
- --cpu=1 \
83
- --max-retries 0 \
84
- --parallelism 0 \
85
- --set-secrets=/secrets/app/secrets.json=skid-secrets:latest \
86
- --task-timeout 3h
87
- else
88
- gcloud run jobs update default \
89
- --region us-central1 \
90
- --image us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/images/job:latest \
91
- --service-account cloud-run-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com \
92
- --memory=3Gi \
93
- --cpu=1 \
94
- --max-retries 0 \
95
- --parallelism 0 \
96
- --set-secrets=/secrets/app/secrets.json=skid-secrets:latest \
97
- --task-timeout 3h
98
- fi
99
-
100
- - name : 🕰️ Create Cloud Scheduler
101
- run : |
102
- if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep saturday-evening)" ]; then
103
- gcloud scheduler jobs create http saturday-evening \
104
- --description="Trigger the nfhl-skid bot once a week on saturday evening" \
105
- --schedule="0 3 * * 6" \
106
- --time-zone=America/Denver \
107
- --location=us-central1 \
108
- --uri="https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${{ secrets.PROJECT_ID }}/jobs/default:run" \
109
- --oauth-service-account-email=scheduler-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
110
- else
111
- gcloud scheduler jobs update http saturday-evening \
112
- --description="Trigger the nfhl-skid bot once a week on saturday evening" \
113
- --schedule="0 3 * * 6" \
114
- --time-zone=America/Denver \
115
- --location=us-central1 \
116
- --uri="https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${{ secrets.PROJECT_ID }}/jobs/default:run" \
117
- --oauth-service-account-email=scheduler-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
118
- 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 }}
119
36
120
37
deploy-firebase-prod :
121
38
name : Deploy Firebase project to production
0 commit comments