Skip to content

Deploy to -UAT v1.0.2 #5

Deploy to -UAT v1.0.2

Deploy to -UAT v1.0.2 #5

Workflow file for this run

# This workflow build and push a Docker container to Google Artifact Registry
# and deploy it on Cloud Run when a PR to the `release` PR is closed.
#GCP needs a repo
name: 'Build and Deploy PROD to Cloud Run'
on:
pull_request:
branches:
- release
types: [closed, edited] # PR opened, edited(PR title, etc)
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'
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'release'
environment:
name: prod
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: Extract Version from PR Title # Assumes PR title contains the tag. ex v0.0.0 or v0.0.0-abc
run: |
VERSION=$(echo "${{ github.event.pull_request.title }}" | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+\(-[a-zA-Z]*\)\?')
echo "Extracted Version: ${VERSION}"
- name: Generate .env.prod file
run: |
echo "VITE_CLIENT_ID = ${{ secrets.VITE_CLIENT_ID }}" > .env.prod
echo "VITE_SEARCH_ENDPOINT = ${{ secrets.VITE_SEARCH_ENDPOINT }}" >> .env.prod
echo "VITE_VOCAB_ENDPOINT= ${{ secrets.VITE_VOCAB_ENDPOINT }}" >> .env.prod
echo "VITE_MAPDRAGON_VERSION=${VERSION}" >> .env.prod
- 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 }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
docker build -t "${DOCKER_TAG}" .
- name: 'Push Docker Image'
run: |-
DOCKER_TAG="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ 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 }}'
region: '${{ env.REGION }}'
image: "${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
env_vars: VERSION=${VERSION}