Reorg project #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
# This workflow build and push a Docker container to Google Artifact Registry and deploy it on Cloud Run when a commit is pushed to the "master" branch | |
# | |
# Overview: | |
# | |
# 1. Authenticate to Google Cloud | |
# 2. Authenticate Docker to Artifact Registry | |
# 3. Build a docker container | |
# 4. Publish it to Google Artifact Registry | |
# 5. Deploy it to Cloud Run | |
name: Build and Deploy to Cloud Run | |
on: | |
push: | |
branches: [ "master" ] | |
env: | |
PROJECT_ID: t-pointer-430919-v3 | |
SERVICE: sigpt-api | |
NAME: sigpt-api | |
GAR_LOCATION: europe-west2 | |
REGION: europe-west2 | |
jobs: | |
deploy: | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Google Auth | |
id: auth | |
uses: 'google-github-actions/auth@v2' | |
with: | |
token_format: 'access_token' | |
workload_identity_provider: '${{ secrets.WIF_PROVIDER }}' | |
service_account: '${{ secrets.WIF_SERVICE_ACCOUNT }}' | |
- name: Docker Auth | |
id: docker-auth | |
uses: 'docker/login-action@v3' | |
with: | |
username: 'oauth2accesstoken' | |
password: '${{ steps.auth.outputs.access_token }}' | |
registry: 'gcr.io' | |
- name: Build and Push Container | |
run: |- | |
gcloud auth configure-docker "${{ env.GAR_LOCATION }}-docker.pkg.dev" | |
docker build -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.NAME }}:${{ github.sha }}" ./ | |
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.NAME }}:${{ github.sha }}" | |
- name: Deploy to Cloud Run | |
id: deploy | |
uses: google-github-actions/deploy-cloudrun@v2 | |
with: | |
service: ${{ env.SERVICE }} | |
region: ${{ env.REGION }} | |
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.NAME }}:${{ github.sha }} | |
flags: '--port=8000 --allow-unauthenticated --memory 2Gi' | |
- name: Show Output | |
run: echo ${{ steps.deploy.outputs.url }} |