-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (67 loc) · 2.42 KB
/
Copy pathdeploy.yml
File metadata and controls
76 lines (67 loc) · 2.42 KB
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
name: Deploy to Cloud Run
on:
push:
branches: [ main ]
workflow_dispatch: {}
jobs:
deploy:
name: Build & Deploy to Cloud Run
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up gcloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Configure Docker authentication for GCR
run: |
gcloud auth configure-docker --quiet
- name: Build and push backend image to GCR
env:
GCP_PROJECT: ${{ secrets.GCP_PROJECT_ID }}
IMAGE_TAG: ${{ github.sha }}
run: |
IMAGE=gcr.io/${GCP_PROJECT}/recipe-backend:${IMAGE_TAG}
docker build -t ${IMAGE} -f backend/Dockerfile backend
docker push ${IMAGE}
- name: Deploy backend to Cloud Run
env:
GCP_PROJECT: ${{ secrets.GCP_PROJECT_ID }}
GCP_REGION: ${{ secrets.GCP_REGION }}
IMAGE_TAG: ${{ github.sha }}
run: |
IMAGE=gcr.io/${GCP_PROJECT}/recipe-backend:${IMAGE_TAG}
gcloud run deploy recipe-backend \
--image ${IMAGE} \
--region ${GCP_REGION} \
--platform managed \
--project ${GCP_PROJECT} \
--port 8080 \
--allow-unauthenticated
- name: Build and push frontend image to GCR
env:
GCP_PROJECT: ${{ secrets.GCP_PROJECT_ID }}
IMAGE_TAG: ${{ github.sha }}
run: |
BACKEND_URL=https://recipe-backend-${GCP_REGION}-a.run.app
IMAGE=gcr.io/${GCP_PROJECT}/recipe-frontend:${IMAGE_TAG}
docker build --build-arg VITE_API_URL=${BACKEND_URL} -t ${IMAGE} -f frontend/Dockerfile frontend
docker push ${IMAGE}
- name: Deploy frontend to Cloud Run
env:
GCP_PROJECT: ${{ secrets.GCP_PROJECT_ID }}
GCP_REGION: ${{ secrets.GCP_REGION }}
IMAGE_TAG: ${{ github.sha }}
run: |
IMAGE=gcr.io/${GCP_PROJECT}/recipe-frontend:${IMAGE_TAG}
gcloud run deploy recipe-frontend \
--image ${IMAGE} \
--region ${GCP_REGION} \
--platform managed \
--project ${GCP_PROJECT} \
--allow-unauthenticated