From 3b10917a836c6c3d0c66daa9a14e85e8e8fc14ad Mon Sep 17 00:00:00 2001 From: Max Kalashnikoff Date: Mon, 2 Oct 2023 16:05:26 +0300 Subject: [PATCH] chore: deploy to production became optional with choice for the `image_tag` (#226) --- .github/workflows/auto_deploy.yml | 4 +- .github/workflows/cd.yml | 67 +++++++++++++------------------ .github/workflows/release.yml | 23 +++++++++++ 3 files changed, 55 insertions(+), 39 deletions(-) diff --git a/.github/workflows/auto_deploy.yml b/.github/workflows/auto_deploy.yml index 1604c038..4b14fb52 100644 --- a/.github/workflows/auto_deploy.yml +++ b/.github/workflows/auto_deploy.yml @@ -84,4 +84,6 @@ jobs: uses: ./.github/workflows/cd.yml with: image_tag: ${{ github.sha }} - secrets: inherit \ No newline at end of file + deploy_to_staging: true + deploy_to_prod: false + secrets: inherit diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index aaf78f16..21abb0fb 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -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 @@ -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 @@ -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" @@ -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: @@ -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 @@ -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" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ad9bab3e..7d226093 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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