Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR: use matrix of deploy destinations instead of hardcoding one or two #74

Open
elrayle opened this issue Apr 26, 2024 · 0 comments

Comments

@elrayle
Copy link
Collaborator

elrayle commented Apr 26, 2024

Description

Current needs require a single deploy for dev and one or two for prod. To get the shared workflow for deploys merged, it was setup with a brute force approach. If more than two deploys are needed, then it would be better to go with a matrix of deploy destinations.

Proposed approach

@jmeridth did an analysis and provided an example of how this can be done.

Using an exclude in the matrix for the conditional deploy: may want an exclude for primary also

  deploy-app-to-azure:
    strategy:
      matrix:
        azure-info:
          - name: primary
            publish-profile: AZURE_WEBAPP_PUBLISH_PROFILE
            azure-webapp-name: ${{ inputs.azure-app-name-postfix }}
          - name: secondary
            publish-profile: AZURE_SECONDARY_WEBAPP_PUBLISH_PROFILE
            azure-webapp-name: ${{ inputs.secondary-azure-app-name-postfix }}
        exclude:
          - name: secondary
            if: ${{ inputs.secondary-azure-app-name-postfix == '' }}
    name: Deploy to ${{ matrix.azure-info.name }} Azure app
    needs: [get-version, build-and-publish-image]
    uses: clearlydefined/operations/.github/workflows/app-deploy-to-azure.yml@elr/reusable-deploy-workflow
    secrets:
      AZURE_WEBAPP_PUBLISH_PROFILE: ${{ secrets[matrix.azure-info.publish-profile] }}
      AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
      DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
      PRODUCTION_DEPLOYERS: ${{ secrets.PRODUCTION_DEPLOYERS }}
    with:
      deploy-env: ${{ inputs.deploy-env }}
      application-type: ${{ inputs.application-type }}
      azure-webapp-name: ${{ inputs.azure-app-base-name }}${{ matrix.azure-info.azure-webapp-name }}
      application-version: ${{ needs.get-version.outputs.version }}
      image-name-with-tag: ${{ needs.build-and-publish-image.outputs.docker-image-name-with-tag }}

Another way I tried but DID NOT work:

  deploy-app-to-azure:
    strategy:
      matrix:
        azure-info:
          - name: primary
            publish-profile: AZURE_WEBAPP_PUBLISH_PROFILE
            azure-webapp-name: ${{ inputs.azure-app-name-postfix }}
            if: ${{ inputs.azure-app-name-postfix != '' }}
          - name: secondary
            publish-profile: AZURE_SECONDARY_WEBAPP_PUBLISH_PROFILE
            azure-webapp-name: ${{ inputs.secondary-azure-app-name-postfix }}
            if: ${{ inputs.secondary-azure-app-name-postfix != '' }}
    name: Deploy to ${{ matrix.azure-info.name }} Azure app
    if: matrix.azure-info.if
    needs: [get-version, build-and-publish-image]
    uses: clearlydefined/operations/.github/workflows/app-deploy-to-azure.yml@elr/reusable-deploy-workflow
    secrets:
      AZURE_WEBAPP_PUBLISH_PROFILE: ${{ secrets[matrix.azure-info.publish-profile] }}
      AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
      DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
      PRODUCTION_DEPLOYERS: ${{ secrets.PRODUCTION_DEPLOYERS }}
    with:
      deploy-env: ${{ inputs.deploy-env }}
      application-type: ${{ inputs.application-type }}
      azure-webapp-name: ${{ inputs.azure-app-base-name }}${{ matrix.azure-info.azure-webapp-name }}
      application-version: ${{ needs.get-version.outputs.version }}
      image-name-with-tag: ${{ needs.build-and-publish-image.outputs.docker-image-name-with-tag }}

Something like this to replace the primary and secondary deploys. The only gotcha is that the if line (between name and needs, is not allowed because if conditional is evaluated before the matrix. Matrix can't be used at the job level for ifs. I'd suggest, if you want to go this path, you add the if conditional as an argument to your reusable workflow. Passing it in and then handling the conditional in your workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant