Skip to content

Commit

Permalink
feat - add cd workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilevk committed May 6, 2024
1 parent ea9557d commit 098d3a0
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/cd_workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build and Deploy to Cloud Run

on:
push:
branches: [ "main" ]

env:
PROJECT_ID: ${{ secrets.project_id }} # TODO: update Google Cloud project id
GAR_LOCATION: ${{ vars.gar_location }} # TODO: update Artifact Registry location
SERVICE: ${{ vars.service_name }} # TODO: update Cloud Run service name
REGION: ${{ vars.service_region }} # TODO: update Cloud Run service region

jobs:
deploy:
# Add 'id-token' with the intended permissions for workload identity federation
permissions:
contents: 'read'
id-token: 'write'

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

# NOTE: Alternative option - authentication via credentials json
- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'

- 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 }}/${{ github.sha }}" ./
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ github.sha }}"
# END - Docker auth and build

- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ env.SERVICE }}
region: ${{ env.REGION }}
# NOTE: If using a pre-built image, update the image name here
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ github.sha }}

# If required, use the Cloud Run url output in later steps
- name: Show Output
run: echo ${{ steps.deploy.outputs.url }}

0 comments on commit 098d3a0

Please sign in to comment.