Deploy Backend to Cloud RUN #149
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
name: Deploy Backend to Cloud RUN | |
on: | |
# push: | |
# branches: [ "main" ] | |
# paths: | |
# - 'backend/**' | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: 'Select the environment to deploy to' | |
required: true | |
default: 'development' | |
branch: | |
description: 'Branch to deploy from' | |
required: true | |
default: 'main' | |
env: | |
SERVICE: backend | |
REGION: us-central1 | |
jobs: | |
deploy: | |
environment: ${{ github.event.inputs.environment }} | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Validate Environment Input | |
run: | | |
if [[ "${{ github.event.inputs.environment }}" != "development" && "${{ github.event.inputs.environment }}" != "prod" ]]; then | |
echo "Invalid environment: ${{ github.event.inputs.environment }}. Must be 'development' or 'prod'." | |
exit 1 | |
fi | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Google Auth | |
id: auth | |
uses: 'google-github-actions/auth@v0' | |
with: | |
credentials_json: ${{ secrets.GCP_CREDENTIALS }} | |
- run: gcloud auth configure-docker | |
- name: Build and Push Docker image | |
run: | | |
docker build -t gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }} -f backend/Dockerfile . | |
docker push gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }} | |
- name: Deploy to Cloud Run | |
id: deploy | |
uses: google-github-actions/deploy-cloudrun@v0 | |
with: | |
service: ${{ env.SERVICE }} | |
region: ${{ env.REGION }} | |
image: gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }} | |
# If required, use the Cloud Run url output in later steps | |
- name: Show Output | |
run: echo ${{ steps.deploy.outputs.url }} |