Dispatch Deploy #3
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 manually triggered. | |
name: 'Build and Deploy Alpha to Cloud Run' | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: 'Deployment environment (e.g., dev, qa, prod, alpha)' | |
required: true | |
type: string | |
default: 'dev' | |
tag: | |
description: 'Optional version for the deployment' | |
required: false | |
type: string | |
default: 'dispatch' | |
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: release # release is deployed, not the default or working branch | |
- id: 'auth' | |
name: 'Authenticate to Google Cloud' | |
uses: 'google-github-actions/auth@v2' | |
with: | |
credentials_json: '${{ env.GCP_CREDENTIALS }}' | |
- name: Generate .env.alpha file | |
run: | | |
echo "VITE_CLIENT_ID = ${{ secrets.VITE_CLIENT_ID }}" > .env.alpha | |
echo "VITE_SEARCH_ENDPOINT = ${{ secrets.VITE_SEARCH_ENDPOINT }}" >> .env.alpha | |
echo "VITE_VOCAB_ENDPOINT= ${{ secrets.VITE_VOCAB_ENDPOINT }}" >> .env.alpha | |
echo "VITE_MAPDRAGON_VERSION= ${{ github.event.inputs.tag }}" >> .env.alpha | |
- 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 }}" |