Skip to content

Commit

Permalink
build(Github): Refactors main workflow and adds Dry Run mode and envi…
Browse files Browse the repository at this point in the history
…ronment override
  • Loading branch information
KevSanchez committed May 16, 2024
1 parent f25e824 commit 6678e61
Show file tree
Hide file tree
Showing 13 changed files with 1,400 additions and 340 deletions.
85 changes: 85 additions & 0 deletions .github/actions/build-and-deploy-cloud-run/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Build And Deploy to Cloud Run
description: Build And Deploy to Cloud Run
inputs:
GCP_SA_KEY:
description: "Service Account Key to log into GCP"
required: true
REPOSITORY:
description: "Repository"
required: true
SERVICE:
description: "Service"
required: true
PROJECT_ID:
description: "GCP Project Id"
required: true
GAR_LOCATION:
description: "GCP Artifact Registry url"
required: true
ENVIRONMENT_NAME:
description: "Environment name (PRODUCTION, STAGING)"
required: true
REGION:
description: "GCP Region"
required: true
COMPONENT_PATH:
description: "Component path of the component to be deployed (./cms, ./client ...)"
required: true
DRY_RUN:
description: "Makes the action work in Dry Run Mode"
required: false
type: boolean
default: false

#NOTE Actions needs to specify the shell to use on every action https://stackoverflow.com/questions/71041836/github-actions-required-property-is-missing-shell

outputs:
url:
description: url
value: ${{steps.deploy.output}}

runs:
using: "composite"
steps:
- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v1'
with:
credentials_json: "${{ inputs.GCP_SA_KEY }}"
token_format: 'access_token'

# Authenticate Docker to Google Cloud Artifact Registry via credentials json
- name: Docker Auth
id: docker-auth
uses: 'docker/login-action@v3'
with:
registry: ${{ inputs.GAR_LOCATION }}-docker.pkg.dev
username: _json_key
password: ${{ inputs.GCP_SA_KEY }}

- name: Build Container
shell: bash
run: |-
docker build -f ${{ inputs.COMPONENT_PATH }}/Dockerfile.prod -t "${{ inputs.GAR_LOCATION }}-docker.pkg.dev/${{ inputs.PROJECT_ID }}/${{ inputs.REPOSITORY }}/${{ inputs.SERVICE }}:${{ github.sha }}" ${{ inputs.COMPONENT_PATH }}
- name: Push Container
if: ${{ ! inputs.DRY_RUN }}
shell: bash
run: |-
docker push "${{ inputs.GAR_LOCATION }}-docker.pkg.dev/${{ inputs.PROJECT_ID }}/${{ inputs.REPOSITORY }}/${{ inputs.SERVICE }}:${{ github.sha }}"
# tag as "latest"
docker tag "${{ inputs.GAR_LOCATION }}-docker.pkg.dev/${{ inputs.PROJECT_ID }}/${{ inputs.REPOSITORY }}/${{ inputs.SERVICE }}:${{ github.sha }}" "${{ inputs.GAR_LOCATION }}-docker.pkg.dev/${{ inputs.PROJECT_ID }}/${{ inputs.REPOSITORY }}/${{ inputs.SERVICE }}:latest"
docker push "${{ inputs.GAR_LOCATION }}-docker.pkg.dev/${{ inputs.PROJECT_ID }}/${{ inputs.REPOSITORY }}/${{ inputs.SERVICE }}:latest"
- name: Deploy to Cloud Run
if: ${{ ! inputs.DRY_RUN }}
id: deploy
uses: google-github-actions/deploy-cloudrun@v1
with:
service: ${{ inputs.SERVICE }}
region: ${{ inputs.REGION }}
image: ${{ inputs.GAR_LOCATION }}-docker.pkg.dev/${{ inputs.PROJECT_ID }}/${{ inputs.REPOSITORY }}/${{ inputs.SERVICE }}:${{ github.sha }}
# NOTE: You can also set env variables here:
# env_vars: |
# NODE_ENV=production
# TOKEN_EXPIRE=6400
Loading

0 comments on commit 6678e61

Please sign in to comment.