From 7c2660902eb9f17687e9b69561b98dc80025e5bb Mon Sep 17 00:00:00 2001 From: Andrea De Rinaldis Date: Thu, 21 Sep 2023 08:22:58 +0200 Subject: [PATCH] [NOD-473] fix: refactored code --- .github/workflows/04_release_deploy.yml | 10 ++-- .github/workflows/04_self_hosted.yml | 76 ++++++++++++++++--------- pom.xml | 2 +- 3 files changed, 55 insertions(+), 33 deletions(-) diff --git a/.github/workflows/04_release_deploy.yml b/.github/workflows/04_release_deploy.yml index 08b5246..6e9ca5a 100644 --- a/.github/workflows/04_release_deploy.yml +++ b/.github/workflows/04_release_deploy.yml @@ -60,7 +60,9 @@ jobs: steps: - name: Semver setup id: semver_setup - uses: pagopa/github-actions-template/node-semver-setup@ff1d20edd8236ade3cb06020c273292b9a62d391 + uses: pagopa/github-actions-template/node-semver-setup@a1b72480e9ac555364be0b7ecdcc8f5ab1c89ad9 + with: + semver: ${{ inputs.semver }} # Set deploy variables - run: echo "ENV_SHORT=$(echo ${{steps.semver_setup.outputs.environment}} | cut -c1-1)" >> $GITHUB_ENV @@ -115,6 +117,7 @@ jobs: strategy: matrix: environment: [ dev, uat, prod ] + secrets: inherit uses: ./.github/workflows/04_self_hosted.yml with: environment: ${{ matrix.environment }} @@ -122,7 +125,6 @@ jobs: resource_group: ${{ needs.setup.outputs.resource_group }} app_name: ${{ needs.setup.outputs.app_name }} registry_image: ${{ needs.release.outputs.registry_image }} - secrets: inherit notify: name: Notify @@ -136,9 +138,9 @@ jobs: with: status: ${{ needs.deploy_azure_fn.result }} token: ${{ secrets.GITHUB_TOKEN }} - notification_title: 'New Release on ${{ needs.setup.outputs.environment }} ${{ needs.release.outputs.version }} has {status_message}' + notification_title: 'New Release on ${{ needs.setup.outputs.environment }} for ${{ needs.release.outputs.version }} has {status_message}' message_format: '{emoji} <{run_url}|{workflow}> {status_message} in <{repo_url}|{repo}>' footer: 'Linked to <{workflow_url}| workflow file>' icon_success: ':white_check_mark:' env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/04_self_hosted.yml b/.github/workflows/04_self_hosted.yml index a6d879c..a41067b 100644 --- a/.github/workflows/04_self_hosted.yml +++ b/.github/workflows/04_self_hosted.yml @@ -29,6 +29,19 @@ permissions: contents: read jobs: + show_input: + runs-on: ubuntu-latest + if: ${{ inputs.target == inputs.environment }} + steps: + - name: Get input parameters + run: | + echo environment=${{ inputs.environment }} + echo target=${{ inputs.target }} + echo resource_group=${{ inputs.resource_group }} + echo app_name=${{ inputs.app_name }} + echo registry_image=${{ inputs.registry_image }} + + # Starting the Azure Function's staging slot, if deploying in PROD start_staging_slot: name: Create staging slots @@ -36,48 +49,55 @@ jobs: if: ${{ inputs.target == inputs.environment && inputs.target == 'prod' }} environment: name: ${{ inputs.environment }} - uses: pagopa/github-actions-template/azure-function-start-staging-slot@ff1d20edd8236ade3cb06020c273292b9a62d391 - with: - branch: ${{ github.ref_name }} - client_id: ${{ secrets.CLIENT_ID }} - tenant_id: ${{ secrets.TENANT_ID }} - subscription_id: ${{ secrets.SUBSCRIPTION_ID }} - resource_group: ${{ inputs.resource_group }} - app_name: ${{ inputs.app_name }} - registry_image: ${{ inputs.registry_image }} + steps: + - name: Create staging slots + uses: pagopa/github-actions-template/azure-function-start-staging-slot@a1b72480e9ac555364be0b7ecdcc8f5ab1c89ad9 + with: + branch: ${{ github.ref_name }} + client_id: ${{ secrets.CLIENT_ID }} + tenant_id: ${{ secrets.TENANT_ID }} + subscription_id: ${{ secrets.SUBSCRIPTION_ID }} + resource_group: ${{ inputs.resource_group }} + app_name: ${{ inputs.app_name }} + registry_image: ${{ inputs.registry_image }} # Executing the deploy of the Azure function with the new image deploy: name: Deploy Azure Function runs-on: ubuntu-22.04 - needs: [ create_staging_slot ] + needs: [ start_staging_slot ] + if: ${{ always() && inputs.target == inputs.environment }} environment: name: ${{ inputs.environment }} - uses: pagopa/github-actions-template/azure-function-deploy@ff1d20edd8236ade3cb06020c273292b9a62d391 - with: - branch: ${{ github.ref_name }} - client_id: ${{ secrets.CLIENT_ID }} - tenant_id: ${{ secrets.TENANT_ID }} - subscription_id: ${{ secrets.SUBSCRIPTION_ID }} - app_name: ${{ inputs.app_name }} - registry_image: ${{ inputs.registry_image }} + steps: + - name: Deploy Azure Function + uses: pagopa/github-actions-template/azure-functions-deploy@a1b72480e9ac555364be0b7ecdcc8f5ab1c89ad9 + with: + branch: ${{ github.ref_name }} + client_id: ${{ secrets.CLIENT_ID }} + tenant_id: ${{ secrets.TENANT_ID }} + subscription_id: ${{ secrets.SUBSCRIPTION_ID }} + app_name: ${{ inputs.app_name }} + registry_image: ${{ inputs.registry_image }} # Stopping the Azure Function's staging slot, if deploying in PROD stop_staging_slot: name: Clean staging slots - needs: [ create_staging_slot, deploy ] + needs: [ start_staging_slot, deploy ] if: ${{ success() || failure() && (inputs.target == inputs.environment && inputs.target == 'prod') }} runs-on: ubuntu-22.04 environment: name: ${{ inputs.environment }} - uses: pagopa/github-actions-template/azure-function-stop-staging-slot@ff1d20edd8236ade3cb06020c273292b9a62d391 - with: - branch: ${{ github.ref_name }} - client_id: ${{ secrets.CLIENT_ID }} - tenant_id: ${{ secrets.TENANT_ID }} - subscription_id: ${{ secrets.SUBSCRIPTION_ID }} - resource_group: ${{ inputs.resource_group }} - app_name: ${{ inputs.app_name }} - registry_image: ${{ inputs.registry_image }} \ No newline at end of file + steps: + - name: Deploy Azure Function + uses: pagopa/github-actions-template/azure-function-stop-staging-slot@a1b72480e9ac555364be0b7ecdcc8f5ab1c89ad9 + with: + branch: ${{ github.ref_name }} + client_id: ${{ secrets.CLIENT_ID }} + tenant_id: ${{ secrets.TENANT_ID }} + subscription_id: ${{ secrets.SUBSCRIPTION_ID }} + resource_group: ${{ inputs.resource_group }} + app_name: ${{ inputs.app_name }} + registry_image: ${{ inputs.registry_image }} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 975f2d2..44b39d4 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ it.gov.pagopa nodoretotablestorage - 0.1.2-4-NOD-473-migrazione-cd-su-git-hub-action-per-nodo-re-to-tablestorage + 0.1.2 jar Nodo RE to Table Storage Fn