Skip to content

[dl-queue] Build - Push - Deploy #1

[dl-queue] Build - Push - Deploy

[dl-queue] Build - Push - Deploy #1

name: 'Build docker image, push to GCP Artifact Registry and deploy on GCP Cloud Run'
on:
push:
paths:
- dl-queue/**
branches:
- main
workflow_dispatch:
jobs:
build-push-deploy:
runs-on: ubuntu-latest
env:
IMAGE_NAME: dl-queue
PROJECT_ID: dl-utils
SA_NAME: github-actions
CLOUD_RUN_SERVICE: dl-queue
REGION: europe-west1
REGISTRY_HOSTNAME: europe-west1-docker.pkg.dev
REGISTRY_NAME: docker-images
# From docs
permissions:
contents: 'read'
id-token: 'write'
steps:
# Important to do this before GCP Auth
- name: Checkout
uses: actions/checkout@v4
- name: Authenticate GCP
uses: google-github-actions/auth@v2
with:
service_account: ${{ env.SA_NAME }}@${{ env.PROJECT_ID }}.iam.gserviceaccount.com
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Setup GCP
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ env.PROJECT_ID }}
- name: Build the Docker image
run: docker build -t ${{ env.IMAGE_NAME }}:latest ./dl-queue
- name: Configure Docker
run: |
gcloud auth configure-docker ${{ env.REGISTRY_HOSTNAME }}
- name: Generate reuseable variable for image
run: |
echo "IMAGE_LOCATION=${{ env.REGISTRY_HOSTNAME }}/${{ env.PROJECT_ID }}/${{ env.REGISTRY_NAME }}/${{ env.IMAGE_NAME }}" >> $GITHUB_ENV
- name: Push docker image to GCP Artifact Registry
run: |
docker tag ${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_LOCATION }}:latest
docker push ${{ env.IMAGE_LOCATION }}:latest
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ env.CLOUD_RUN_SERVICE }}
image: ${{ env.IMAGE_LOCATION }}:latest
region: ${{ env.REGION }}
project_id: ${{ env.PROJECT_ID }}
- name: Test the deployed service
run: curl "${{ steps.deploy.outputs.url }}"