From c60cb48d3159dd41b8791eb2773d12cf6e845e60 Mon Sep 17 00:00:00 2001 From: Felix Uellendall Date: Fri, 25 Oct 2024 10:51:27 +0200 Subject: [PATCH] Add support to deploy to dev deployments This adds a new `wake-on-deploy` input that allows for creating a hibernation override that will ensure the dev deployment is awake for the time of deploying. --- .github/workflows/tests.yaml | 51 ++++++++++++++++++++++++++++-------- action.yaml | 44 +++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 58b9ff2..9850d5b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -55,9 +55,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - deployment: [deployment.yaml] + deployment: [deployment-hibernate.yaml, deployment.yaml] outputs: DEPLOYMENT_ID: ${{ steps.create-deployment.outputs.DEPLOYMENT_ID }} + HIBERNATE_DEPLOYMENT_ID: ${{ steps.create-deployment.outputs.HIBERNATE_DEPLOYMENT_ID }} steps: - name: Checkout code uses: actions/checkout@v4 @@ -98,8 +99,11 @@ jobs: sed -i "s| name:.*| name: deploy-action-e2e-${{ env.test_uid }}|g" e2e-setup/deployment-templates/${{ matrix.deployment }} DEPLOYMENT_ID=$(astro deployment create --deployment-file e2e-setup/deployment-templates/${{ matrix.deployment }} | yq e '.deployment.metadata.deployment_id' -) - echo "DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT - + if [[ "${{ matrix.deployment }}" == "deployment.yaml" ]]; then + echo "DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT + else + echo "HIBERNATE_DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT + fi default-deploy-tests: name: Default Deploy Test runs-on: ubuntu-latest @@ -108,7 +112,10 @@ jobs: max-parallel: 1 matrix: deployment_id: - ["${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}"] + [ + "${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}", + "${{ needs.create-test-deployments.outputs.HIBERNATE_DEPLOYMENT_ID }}", + ] deploy_type: [dags, image-and-dags] steps: - name: Checkout code @@ -193,7 +200,10 @@ jobs: strategy: matrix: deployment_id: - ["${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}"] + [ + "${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}", + "${{ needs.create-test-deployments.outputs.HIBERNATE_DEPLOYMENT_ID }}", + ] steps: - name: Checkout code uses: actions/checkout@v4 @@ -268,7 +278,10 @@ jobs: strategy: matrix: deployment_id: - ["${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}"] + [ + "${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}", + "${{ needs.create-test-deployments.outputs.HIBERNATE_DEPLOYMENT_ID }}", + ] steps: - name: Checkout code uses: actions/checkout@v4 @@ -348,7 +361,10 @@ jobs: max-parallel: 1 matrix: deployment_id: - ["${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}"] + [ + "${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}", + "${{ needs.create-test-deployments.outputs.HIBERNATE_DEPLOYMENT_ID }}", + ] deploy_type: [dags, image-and-dags] steps: - name: Checkout code @@ -432,7 +448,10 @@ jobs: strategy: matrix: deployment_id: - ["${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}"] + [ + "${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}", + "${{ needs.create-test-deployments.outputs.HIBERNATE_DEPLOYMENT_ID }}", + ] deploy_type: [infer, dbt, dags, image-and-dags] steps: - name: Checkout code @@ -539,7 +558,10 @@ jobs: strategy: matrix: deployment_id: - ["${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}"] + [ + "${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}", + "${{ needs.create-test-deployments.outputs.HIBERNATE_DEPLOYMENT_ID }}", + ] steps: - name: Checkout code uses: actions/checkout@v4 @@ -615,7 +637,10 @@ jobs: strategy: matrix: deployment_id: - ["${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}"] + [ + "${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}", + "${{ needs.create-test-deployments.outputs.HIBERNATE_DEPLOYMENT_ID }}", + ] steps: - name: Checkout code uses: actions/checkout@v4 @@ -698,7 +723,10 @@ jobs: strategy: matrix: deployment_id: - ["${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}"] + [ + "${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }}", + "${{ needs.create-test-deployments.outputs.HIBERNATE_DEPLOYMENT_ID }}", + ] steps: - name: Checkout code uses: actions/checkout@v4 @@ -959,3 +987,4 @@ jobs: - name: Delete Deployment run: | astro deployment delete -f ${{ needs.create-test-deployments.outputs.DEPLOYMENT_ID }} + astro deployment delete -f ${{ needs.create-test-deployments.outputs.HIBERNATE_DEPLOYMENT_ID }} diff --git a/action.yaml b/action.yaml index a86675e..5a524a5 100644 --- a/action.yaml +++ b/action.yaml @@ -94,6 +94,10 @@ inputs: required: false default: false description: "Whether to checkout submodules when cloning the repository: `false` to disable (default), `true` to checkout submodules or `recursive` to recursively checkout submodules. Works only when `checkout` is set to `true`." + wake-on-deploy: + required: false + default: false + description: "If true, the deployment will be woken up before deploying and hibernated again after deploying." outputs: preview-id: description: "The ID of the created deployment preview. Only works when action=create-deployment-preview" @@ -449,6 +453,39 @@ runs: echo ::endgroup:: shell: bash id: deploy-options + - name: Determine if Development Mode is enabled + if: inputs.wake-on-deploy == 'true' + run: | + echo ::group::Determine if Development Mode is enabled + if [[ ${{ inputs.action }} != delete-deployment-preview ]]; then + DEPLOYMENT_TYPE=$(astro deployment inspect ${{steps.deployment-preview.outputs.FINAL_DEPLOYMENT_ID}} --clean-output --key configuration.deployment_type) + # only inspect development mode if deployment is not hybrid + if [[ $DEPLOYMENT_TYPE != "HYBRID" ]]; then + DEV_MODE=$(astro deployment inspect ${{steps.deployment-preview.outputs.FINAL_DEPLOYMENT_ID}} --clean-output --key configuration.is_development_mode) + echo "Deployment development mode: $DEV_MODE" + if [[ $DEV_MODE == "" ]]; then + echo "DEVELOPMENT_MODE=false" >> $GITHUB_OUTPUT + else + echo "DEVELOPMENT_MODE=$DEV_MODE" >> $GITHUB_OUTPUT + fi + else + echo "DEVELOPMENT_MODE=false" >> $GITHUB_OUTPUT + fi + else + echo "DEVELOPMENT_MODE=false" >> $GITHUB_OUTPUT + fi + echo ::endgroup:: + shell: bash + id: development-mode + - name: Override to wake up the Deployment + if: ${{ inputs.wake-on-deploy == 'true' && inputs.action != 'delete-deployment-preview' && steps.development-mode.outputs.DEVELOPMENT_MODE == 'true' }} + run: | + echo ::group::Override to wake up the Deployment + astro deployment wake-up ${{steps.deployment-preview.outputs.FINAL_DEPLOYMENT_ID}} --force + # Give it some time to wake up + sleep 60 + echo ::endgroup:: + shell: bash - name: DAG Deploy to Astro if: ${{ (inputs.deploy-type == 'dags-only' || inputs.deploy-type == 'infer') && steps.deploy-type.outputs.DAGS_ONLY_DEPLOY == 'true' }} run: | @@ -506,3 +543,10 @@ runs: fi echo ::endgroup:: shell: bash + - name: Remove override on Deployment to resume schedule + if: ${{ inputs.wake-on-deploy == 'true' && steps.development-mode.outputs.DEVELOPMENT_MODE == 'true' }} + run: | + echo ::group::Remove override on Deployment to resume schedule + astro deployment wake-up ${{steps.deployment-preview.outputs.FINAL_DEPLOYMENT_ID}} --remove-override --force + echo ::endgroup:: + shell: bash