Skip to content

update GitHub Actions Workflows #12

update GitHub Actions Workflows

update GitHub Actions Workflows #12

Workflow file for this run

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:
project_id: ${{ secrets.PROJECT_ID }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT }}
- 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 }}