Skip to content

Commit fcf9e77

Browse files
committed
feat: Update Cloud Run workflow to build and deploy both backend and frontend containers
1 parent 24957dc commit fcf9e77

1 file changed

Lines changed: 63 additions & 26 deletions

File tree

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
# This workflow build and push a Docker container to Google Artifact Registry
2-
# and deploy it on Cloud Run when a commit is pushed to the "dev"
1+
# This workflow builds and pushes Docker containers to Google Artifact Registry
2+
# and deploys both backend and frontend on Cloud Run when a commit is pushed to the "production"
33
# branch.
44

5-
name: 'Build and Deploy to Cloud Run'
5+
name: 'Build and Deploy QueryPal to Cloud Run'
66

77
on:
88
push:
99
branches:
10-
- '"dev"'
10+
- 'production'
11+
workflow_dispatch:
1112

1213
env:
13-
PROJECT_ID: 'my-project' # TODO: update to your Google Cloud project ID
14-
REGION: 'us-central1' # TODO: update to your region
15-
SERVICE: 'my-service' # TODO: update to your service name
16-
WORKLOAD_IDENTITY_PROVIDER: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' # TODO: update to your workload identity provider
14+
PROJECT_ID: 'gen-lang-client-0698668474'
15+
REGION: 'europe-west1'
16+
BACKEND_SERVICE: 'querypal-backend'
17+
FRONTEND_SERVICE: 'querypal-frontend'
18+
WORKLOAD_IDENTITY_PROVIDER: 'projects/gen-lang-client-0698668474/locations/global/workloadIdentityPools/github-actions-pool/providers/github-provider'
1719

1820
jobs:
1921
deploy:
@@ -28,43 +30,78 @@ jobs:
2830
uses: 'actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' # actions/checkout@v4
2931

3032
# Configure Workload Identity Federation and generate an access token.
31-
#
32-
# See https://github.com/google-github-actions/auth for more options,
33-
# including authenticating via a JSON credentials file.
3433
- id: 'auth'
3534
name: 'Authenticate to Google Cloud'
3635
uses: 'google-github-actions/auth@f112390a2df9932162083945e46d439060d66ec2' # google-github-actions/auth@v2
3736
with:
3837
workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER }}'
3938

4039
# BEGIN - Docker auth and build
41-
#
42-
# If you already have a container image, you can omit these steps.
4340
- name: 'Docker Auth'
4441
uses: 'docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567' # docker/login-action@v3
4542
with:
4643
username: 'oauth2accesstoken'
4744
password: '${{ steps.auth.outputs.auth_token }}'
4845
registry: '${{ env.REGION }}-docker.pkg.dev'
4946

50-
- name: 'Build and Push Container'
47+
# Build and Push Backend Container
48+
- name: 'Build and Push Backend Container'
5149
run: |-
52-
DOCKER_TAG="$${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}"
53-
docker build --tag "${DOCKER_TAG}" .
50+
cd backend
51+
DOCKER_TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.BACKEND_SERVICE }}:${{ github.sha }}"
52+
docker build --tag "${DOCKER_TAG}" --platform linux/amd64 .
5453
docker push "${DOCKER_TAG}"
55-
- name: 'Deploy to Cloud Run'
56-
57-
# END - Docker auth and build
5854
55+
# Deploy Backend to Cloud Run
56+
- id: 'deploy-backend'
57+
name: 'Deploy Backend to Cloud Run'
5958
uses: 'google-github-actions/deploy-cloudrun@33553064113a37d688aa6937bacbdc481580be17' # google-github-actions/deploy-cloudrun@v2
6059
with:
61-
service: '${{ env.SERVICE }}'
60+
service: '${{ env.BACKEND_SERVICE }}'
6261
region: '${{ env.REGION }}'
63-
# NOTE: If using a pre-built image, update the image name below:
62+
image: '${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.BACKEND_SERVICE }}:${{ github.sha }}'
63+
env_vars: |
64+
AZURE_TENANT_ID=${{ secrets.AZURE_TENANT_ID }}
65+
AZURE_CLIENT_ID=${{ secrets.AZURE_CLIENT_ID }}
66+
AZURE_CLIENT_SECRET=${{ secrets.AZURE_CLIENT_SECRET }}
67+
ARM_SCOPE=https://management.azure.com/.default
68+
GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}
69+
DB_USER=${{ secrets.DB_USER }}
70+
DB_PASS=${{ secrets.DB_PASS }}
71+
DB_NAME=querypal
72+
DB_UNIX_SOCKET=/cloudsql/gen-lang-client-0698668474:europe-west1:querypal-db
73+
flags: |
74+
--port=8000
75+
--add-cloudsql-instances=gen-lang-client-0698668474:europe-west1:querypal-db
76+
--allow-unauthenticated
77+
78+
# Build and Push Frontend Container
79+
- name: 'Build and Push Frontend Container'
80+
run: |-
81+
cd frontend
82+
DOCKER_TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.FRONTEND_SERVICE }}:${{ github.sha }}"
83+
docker build --tag "${DOCKER_TAG}" --platform linux/amd64 \
84+
--build-arg VITE_API_BASE_URL=${{ steps.deploy-backend.outputs.url }} \
85+
--build-arg VITE_AZURE_REDIRECT_URI=https://${{ env.FRONTEND_SERVICE }}-zynyyoxona-ew.a.run.app \
86+
.
87+
docker push "${DOCKER_TAG}"
6488
65-
image: '${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}'
66-
# If required, use the Cloud Run URL output in later steps
67-
- name: 'Show output'
68-
run: |2-
89+
# Deploy Frontend to Cloud Run
90+
- id: 'deploy-frontend'
91+
name: 'Deploy Frontend to Cloud Run'
92+
uses: 'google-github-actions/deploy-cloudrun@33553064113a37d688aa6937bacbdc481580be17' # google-github-actions/deploy-cloudrun@v2
93+
with:
94+
service: '${{ env.FRONTEND_SERVICE }}'
95+
region: '${{ env.REGION }}'
96+
image: '${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.FRONTEND_SERVICE }}:${{ github.sha }}'
97+
env_vars: |
98+
PORT=4000
99+
flags: |
100+
--port=4000
101+
--allow-unauthenticated
69102
70-
echo ${{ steps.deploy.outputs.url }}
103+
# Show output URLs
104+
- name: 'Show deployment URLs'
105+
run: |-
106+
echo "Backend URL: ${{ steps.deploy-backend.outputs.url }}"
107+
echo "Frontend URL: ${{ steps.deploy-frontend.outputs.url }}"

0 commit comments

Comments
 (0)