Skip to content

Dispatch Deploy

Dispatch Deploy #11

Workflow file for this run

# This workflow build and push a Docker container to Google Artifact Registry
# and deploy it on Cloud Run when manually triggered.
name: 'Dispatch Deploy'
on:
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment (e.g., dev, uat, prod, alpha)'
required: true
type: string
default: 'dev'
version:
description: 'Optional version for the deployment'
required: true
type: string
default: 'v0.0.0-env'
deploy_branch:
description: 'Branch to deploy to the environment'
required: true
type: string
default: 'main'
env:
PROJECT_ID: ${{ secrets.PROJECT_ID }}
REGION: ${{ secrets.REGION_LOC_1 }}
SERVICE: 'mapdragon'
IMAGE_NAME: 'map-dragon_img'
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}
jobs:
deploy:
runs-on: 'ubuntu-latest'
environment:
name: ${{ github.event.inputs.environment }}
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: 'Checkout'
uses: 'actions/checkout@v4'
with:
ref: ${{ github.event.inputs.deploy_branch }} # This branch is deployed
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ env.GCP_CREDENTIALS }}'
- name: Generate .env.${{ github.event.inputs.environment }} file
run: |
echo "VITE_CLIENT_ID = ${{ secrets.VITE_CLIENT_ID }}" > .env.${{ github.event.inputs.environment }}
echo "VITE_SEARCH_ENDPOINT = ${{ secrets.VITE_SEARCH_ENDPOINT }}" >> .env.${{ github.event.inputs.environment }}
echo "VITE_VOCAB_ENDPOINT= ${{ secrets.VITE_VOCAB_ENDPOINT }}" >> .env.${{ github.event.inputs.environment }}
echo "VITE_MAPDRAGON_VERSION= ${{ github.event.inputs.version }}" >> .env.${{ github.event.inputs.environment }}
- name: 'Docker Auth'
run: |-
gcloud auth configure-docker '${{ env.REGION }}-docker.pkg.dev'
- name: 'Build Docker Image' # New step to build the image
run: |-
DOCKER_TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}-${{ github.event.inputs.environment }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
docker build -t "${DOCKER_TAG}" --build-arg ENV=${{ github.event.inputs.environment }} .
- name: 'Push Docker Image'
run: |-
DOCKER_TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}-${{ github.event.inputs.environment }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
docker push "${DOCKER_TAG}"
- name: 'Deploy to Cloud Run'
uses: 'google-github-actions/deploy-cloudrun@v2'
with:
service: '${{ env.SERVICE }}-${{ github.event.inputs.environment }}'
region: '${{ env.REGION }}'
image: "${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}-${{ github.event.inputs.environment }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"