Skip to content

Commit 8dbfafd

Browse files
committed
Merge branch 'main' into feat_gee_caching
2 parents 821de2b + 84214d3 commit 8dbfafd

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Auto Deploy to Google Cloud
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
env:
13+
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GCP_SA_KEY }}
14+
IMAGE_NAME: europe-west3-docker.pkg.dev/thf-climate-cloud/thf-climate/thf-climate
15+
16+
steps:
17+
# Step 1: Checkout the code
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
21+
# Step 2: Decode and Write the Service Account Key to a file properly
22+
- name: Set up Google Cloud credentials
23+
run: |
24+
echo "${{ secrets.GCP_SA_KEY_BASE64 }}" | base64 --decode > ${HOME}/gcloud-service-key.json
25+
26+
# Step 3: Set up Google Cloud SDK
27+
- name: Set up Google Cloud SDK
28+
uses: google-github-actions/setup-gcloud@v1
29+
with:
30+
project_id: ${{ secrets.GCP_PROJECT_ID }}
31+
service_account_key: ${{ secrets.GCP_SA_KEY }}
32+
export_default_credentials: true
33+
34+
# Step 4: Activate Service Account Explicitly
35+
- name: Activate Service Account
36+
run: |
37+
gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-key.json
38+
gcloud config set account $(gcloud config get-value core/account)
39+
40+
# Step 5: Configure Docker for Google Artifact Registry
41+
- name: Configure Docker for Google Artifact Registry
42+
run: |
43+
gcloud auth configure-docker europe-west3-docker.pkg.dev
44+
45+
# Step 6: Docker Login using Access Token
46+
- name: Build Docker image
47+
working-directory: ./backend
48+
run: |
49+
docker buildx build --platform linux/amd64 -t $IMAGE_NAME:latest .
50+
51+
# Step 7: Build Docker image
52+
- name: Push Docker image to Artifact Registry
53+
working-directory: ./backend
54+
run: |
55+
docker push $IMAGE_NAME:latest
56+
57+
# Step 8: Push Docker image to Google Artifact Registry
58+
- name: Deploy to Cloud Run
59+
working-directory: ./backend
60+
run: |
61+
gcloud run deploy thf-climate-run \
62+
--image=$IMAGE_NAME:latest \
63+
--port=8000 \
64+
--region=europe-west3 \
65+
--allow-unauthenticated \
66+
--platform=managed \
67+
--min-instances=1 \
68+
--max-instances=5

0 commit comments

Comments
 (0)