Skip to content

Deploy API to Cloud Run #17

Deploy API to Cloud Run

Deploy API to Cloud Run #17

Workflow file for this run

name: Deploy API to Cloud Run
on:
# workflow_run:
# workflows: ["Rust CI"]
# types:
# - completed
# branches: [main]
workflow_dispatch:
inputs:
branch:
description: "Branch to deploy"
required: true
default: "main"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/fcb-api
REGION: europe-west4
SERVICE_NAME: fcb-api
jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
contents: read
packages: write
id-token: write
# defaults:
# run:
# working-directory: src/rust
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: src/rust/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
name: Deploy to Cloud Run
needs: build-and-push
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Google Auth
id: auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.WIF_PROVIDER }}
project_id: ${{ secrets.PROJECT_ID }}
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ env.SERVICE_NAME }}
region: ${{ env.REGION }}
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
flags: |
--port=8080
--allow-unauthenticated
--min-instances=0
--max-instances=3
--cpu=1
--memory=256Mi
--timeout=300
- name: Show Output
run: echo ${{ steps.deploy.outputs.url }}