Skip to content

Commit

Permalink
Add support to deploy to dev deployments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
feluelle committed Oct 25, 2024
1 parent 4755169 commit c60cb48
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 11 deletions.
51 changes: 40 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
44 changes: 44 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: |
Expand Down Expand Up @@ -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

0 comments on commit c60cb48

Please sign in to comment.