Skip to content

Commit

Permalink
chore: deploy to production became optional with choice for the `imag…
Browse files Browse the repository at this point in the history
…e_tag` (#226)
  • Loading branch information
geekbrother authored Oct 2, 2023
1 parent 2667c1c commit 3b10917
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 39 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/auto_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ jobs:
uses: ./.github/workflows/cd.yml
with:
image_tag: ${{ github.sha }}
secrets: inherit
deploy_to_staging: true
deploy_to_prod: false
secrets: inherit
67 changes: 29 additions & 38 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
name: cd
on:
workflow_dispatch:
push:
branches:
- "main"
paths:
- "terraform/**"
release:
types: ["published"]
inputs:
deploy_to_staging:
description: "Deploy to staging"
type: boolean
required: true
default: true
deploy_to_prod:
description: "Deploy to production"
type: boolean
required: true
default: false
image_tag:
description: "App image tag. Default: latest release"
type: string
required: false
default: ""
workflow_call:
inputs:
deploy_to_staging:
type: boolean
required: true
default: true
deploy_to_prod:
type: boolean
required: false
default: false
image_tag:
type: string
required: true
Expand All @@ -21,41 +38,12 @@ concurrency:
cancel-in-progress: false

jobs:
get-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.clean_version.outputs.version }}
steps:
- id: get
uses: actions/github-script@v6
env:
LATEST_TAG: ${{ steps.latest_release.outputs.release }}
with:
result-encoding: string
script: |
if (context.eventName == "release") {
// remove the v from the tag
let tag = context.payload.release.tag_name.replace("v", "")
return tag
} else if (context.eventName == "workflow_call") {
return context.payload.inputs.image_tag
} else {
return ""
}
- id: clean_version
run: |
version=$(echo "${{ steps.get.outputs.result }}")
echo "version=$version" >> $GITHUB_OUTPUT
deploy-infra-staging:
if: ${{ inputs.deploy_to_staging }}
runs-on: ubuntu-latest
environment:
name: staging
url: https://staging.echo.walletconnect.com/health
needs:
- get-version
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -97,6 +85,7 @@ jobs:
TF_VAR_grafana_endpoint: ${{ steps.grafana-get-details.outputs.endpoint }}
TF_VAR_cloud_api_key: ${{ secrets.CLOUD_API_KEY }}
TF_VAR_jwt_secret: ${{ secrets.JWT_SECRET }}
TF_VAR_image_version: ${{ inputs.image_tag }}
with:
environment: "staging"

Expand All @@ -109,6 +98,7 @@ jobs:
workspace-id: ${{ steps.grafana-get-details.outputs.workspace-id }}

validate_staging:
if: ${{ inputs.deploy_to_staging }}
needs: [deploy-infra-staging]
uses: ./.github/workflows/validate.yml
with:
Expand All @@ -117,12 +107,12 @@ jobs:
TEST_TENANT_ID: ${{ secrets.TEST_TENANT_ID }}

deploy-infra-prod:
if: ${{ inputs.deploy_to_prod }}
runs-on: ubuntu-latest
environment:
name: prod
url: https://echo.walletconnect.com/health
needs:
- get-version
- validate_staging
steps:
- name: Checkout
Expand Down Expand Up @@ -165,6 +155,7 @@ jobs:
TF_VAR_grafana_endpoint: ${{ steps.grafana-get-details.outputs.endpoint }}
TF_VAR_cloud_api_key: ${{ secrets.CLOUD_API_KEY }}
TF_VAR_jwt_secret: ${{ secrets.JWT_SECRET }}
TF_VAR_image_version: ${{ inputs.image_tag }}
with:
environment: "prod"

Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ name: release

on:
workflow_dispatch:
inputs:
deploy_to_staging:
description: "Deploy to staging"
type: boolean
required: true
default: true
deploy_to_prod:
description: "Deploy to production"
type: boolean
required: true
default: false

permissions:
contents: write
Expand Down Expand Up @@ -108,3 +119,15 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

run-cd:
needs:
- release
- build-container
# call the cd.yml file with image tag from the new release
uses: ./.github/workflows/cd.yml
with:
image_tag: ${{ needs.release.outputs.version }}
deploy_to_staging: ${{ inputs.deploy_to_staging }}
deploy_to_prod: ${{ inputs.deploy_to_prod }}
secrets: inherit

0 comments on commit 3b10917

Please sign in to comment.