-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(Github): Refactors main workflow and adds Dry Run mode and envi…
…ronment override
- Loading branch information
1 parent
26a58ea
commit fec4962
Showing
2 changed files
with
148 additions
and
68 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: Build And Deploy to Cloud Run | ||
description: Build And Deploy to Cloud Run | ||
inputs: | ||
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 | ||
|
||
|
||
|
||
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: "${{ secrets[format('TF_{0}_GCP_SA_KEY', inputs.ENVIRONMENT_NAME)] }}" | ||
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: ${{ secrets[format('TF_{0}_GCP_SA_KEY', inputs.ENVIRONMENT_NAME)] }} | ||
|
||
- name: Build Container | ||
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 }} | ||
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 |
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