This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI and CD Pipeline to Cloud Run | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
env: | |
PROJECT_ID: ${{ secrets.PROJECT_ID }} | |
jobs: | |
build: | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
id: checkout | |
uses: actions/checkout@v4 | |
- name: Set environment variables | |
id: set-env | |
run: | | |
echo "IMAGE_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV | |
- name: Gcloud Auth | |
id: gcloud-auth | |
uses: google-github-actions/auth@v2 | |
with: | |
token_format: 'access_token' | |
project_id: ${{ secrets.PROJECT_ID }} | |
service_account: ${{ secrets.SERVICE_ACCOUNT }} | |
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} | |
- name: Auth Container Registry | |
id: container-registry-auth | |
uses: docker/login-action@v3 | |
with: | |
registry: us-central1-docker.pkg.dev | |
username: oauth2accesstoken | |
password: ${{ steps.gcloud-auth.outputs.access_token }} | |
- name: Build and push Docker image Backend | |
id: build-push-back | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ./Dockerfile.back | |
push: true | |
tags: us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/cloud-run/cloud-run-back:${{ env.IMAGE_VERSION }} | |
- name: Build and push Docker image Frontend | |
id: build-push-front | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ./Dockerfile.front | |
push: true | |
tags: us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/cloud-run/cloud-run-front:${{ env.IMAGE_VERSION }} | |
- name: Deploy to Cloud Run Backend | |
id: deploy-cloud-run-back | |
uses: google-github-actions/deploy-cloudrun@v2 | |
with: | |
service: cloud-run-backend-${{ env.IMAGE_VERSION }} | |
image: us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/cloud-run/cloud-run-back:${{ env.IMAGE_VERSION }} | |
region: us-central1 | |
project_id: ${{ secrets.PROJECT_ID }} | |
flags: --port 4000 --allow-unauthenticated | |
- name: Deploy to Cloud Run Frontend | |
id: deploy-cloud-run-front | |
uses: google-github-actions/deploy-cloudrun@v2 | |
with: | |
service: cloud-run-frontend-${{ env.IMAGE_VERSION }} | |
image: us-central1-docker.pkg.dev/${{ secrets.PROJECT_ID }}/cloud-run/cloud-run-front:${{ env.IMAGE_VERSION }} | |
region: us-central1 | |
project_id: ${{ secrets.PROJECT_ID }} | |
flags: --port 8080 --allow-unauthenticated | |
- name: Test Cloud Run | |
run: | | |
'curl "${{ steps.deploy-cloud-run-back.outputs.url }}"' | |
'curl "${{ steps.deploy-cloud-run-front.outputs.url }}"' |