Skip to content

Update google-cloudrun-docker.yml #4

Update google-cloudrun-docker.yml

Update google-cloudrun-docker.yml #4

name: 'Build and Deploy to Cloud Run'
on:
push:
branches:
- main
env:
PROJECT_ID: 'legalqaapp' # Update this to your GCP project ID
REGION: 'us-west1' # Update to your preferred GCP region
SERVICE: 'legalqagithub' # Update to your Cloud Run service name
jobs:
deploy:
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: 'Checkout'
uses: 'actions/checkout@v3'
# Authenticate to Google Cloud using Workload Identity Federation or JSON key
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}' # Reference your saved GCP credentials secret
# Docker authentication and build
- name: 'Docker Auth'
uses: 'docker/login-action@v3'
with:
username: 'oauth2accesstoken'
password: '${{ steps.auth.outputs.token }}' # Use the correct token from the auth step
registry: '${{ env.REGION }}-docker.pkg.dev' # Google Artifact Registry URL
- name: 'Build and Push Container'
run: |-
DOCKER_TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/legalapp/${{ env.SERVICE }}:${{ github.sha }}"
docker build --tag "${DOCKER_TAG}" .
docker push "${DOCKER_TAG}"
# Deploy to Google Cloud Run
- name: 'Deploy to Cloud Run'
uses: 'google-github-actions/deploy-cloudrun@v2'
with:
service: '${{ env.SERVICE }}'
region: '${{ env.REGION }}'
image: '${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/legalapp/${{ env.SERVICE }}:${{ github.sha }}'
# Display the Cloud Run service URL
- name: 'Show output'
run: |
echo ${{ steps.deploy.outputs.url }}