update GitHub Actions Workflows #10
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 | |
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: Auth Container Registry | |
id: container-registry-auth | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.REGISTRY_USER }} | |
password: ${{ secrets.REGISTRY_PASSWORD }} | |
- name: Gcloud Auth | |
id: gcloud-auth | |
uses: google-github-actions/auth@v2 | |
with: | |
token_format: 'id_token' | |
project_id: ${{ secrets.PROJECT_ID }} | |
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} | |
service_account: ${{ secrets.SERVICE_ACCOUNT }} | |
audience: workload_identity_provider | |
- name: Setup Secret for Pulling Image | |
id: setup-secret | |
run: | | |
echo -n '{"auths":{"ghcr.io":{"username":"${{ secrets.REGISTRY_USER }}","password":"${{ secrets.REGISTRY_PASSWORD }}"}}}' > /tmp/.dockerconfigjson | |
gcloud secrets create cloud-run-secret --project ${{ secrets.PROJECT_ID }} --data-file=/tmp/.dockerconfigjson --replication-policy=automatic || echo "Secret already exists" | |
gcloud secrets versions add cloud-run-secret --project ${{ secrets.PROJECT_ID }} --data-file=/tmp/.dockerconfigjson | |
- 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: ghcr.io/${{ github.repository }}/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: ghcr.io/${{ github.repository }}/cloud-run-front:${{ env.IMAGE_VERSION }} |