Skip to content

Commit

Permalink
Enable GH actions job for daily deploy and Master DAG Trigger (#2034)
Browse files Browse the repository at this point in the history
Currently we are not running Astro SDK Example DAG daily, This PR enable
Actions job to deploy everyday and trigger example Master Dag for celery
and Kubernetes deployment

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
vatsrahul1001 and pre-commit-ci[bot] authored Sep 21, 2023
1 parent e5cf304 commit 54795d4
Show file tree
Hide file tree
Showing 7 changed files with 476 additions and 40 deletions.
110 changes: 81 additions & 29 deletions .github/workflows/ci-astro-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,86 @@ on:
required: false
default: ''

environment_to_deploy:
description: 'astro cloud deployment to deploy to'
required: true
type: choice
options:
- both
- astro-sdk-integration-tests
- astro-sdk-integration-tests-on-KE
dags_to_trigger_after_deployment:
description: |
Comma separated list of dag_ids to trigger after deployment
(e.g. "example_mssql_transform, example_load_file")
required: false
type: string
default: ''


jobs:
deploy:
env:
ASTRO_DOCKER_REGISTRY: ${{ secrets.ASTRO_DOCKER_REGISTRY }}
ASTRO_ORGANIZATION_ID: ${{ secrets.ASTRO_ORGANIZATION_ID }}
ASTRO_DEPLOYMENT_ID: ${{ secrets.ASTRO_DEPLOYMENT_ID }}
ASTRO_KEY_ID: ${{ secrets.ASTRO_KEY_ID }}
ASTRO_KEY_SECRET: ${{ secrets.ASTRO_KEY_SECRET }}
ASTRO_DEPLOYMENT_ID_SINGLE_WORKER: ${{ secrets.ASTRO_DEPLOYMENT_ID_SINGLE_WORKER }}
ASTRO_KEY_ID_SINGLE_WORKER: ${{ secrets.ASTRO_KEY_ID_SINGLE_WORKER }}
ASTRO_KEY_SECRET_SINGLE_WORKER: ${{ secrets.ASTRO_KEY_SECRET_SINGLE_WORKER }}
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: ${{ inputs.git_rev }}
deploy-to-astro-sdk-integration-tests:
if: |
contains(fromJSON('["both", "astro-sdk-integration-tests"]'), inputs.environment_to_deploy) ||
github.event_name == 'schedule'
uses: ./.github/workflows/reuse-wf-deploy-to-astro-cloud.yaml
with:
git_rev: ${{ inputs.git_rev }}
environment_to_deploy: 'astro-sdk-integration-tests'
secrets:
docker_registry: ${{ secrets.ASTRO_DOCKER_REGISTRY }}
organization_id: ${{ secrets.ORGANIZATION_ID }}
deployment_id: ${{ secrets.ASTRO_DEPLOYMENT_ID }}
astronomer_key_id: ${{ secrets.ASTRO_KEY_ID }}
astronomer_key_secret: ${{ secrets.ASTRO_KEY_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

wait-for-deployment-to-be-ready-and-trigger-dags-for-astro-sdk-integration-tests:
if: |
github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && inputs.dags_to_trigger_after_deployment != '')
needs: deploy-to-astro-sdk-integration-tests
uses: ./.github/workflows/reuse-wf-trigger-dag.yaml
with:
git_rev: ${{ inputs.git_rev }}
dags_to_trigger_after_deployment: ${{ inputs.dags_to_trigger_after_deployment }}
secrets:
astro_subdomain: ${{ secrets.ASTRO_SUBDOMAIN }}
deployment_id: ${{ secrets.ASTRO_DEPLOYMENT_ID }}
astronomer_key_id: ${{ secrets.ASTRO_KEY_ID }}
astronomer_key_secret: ${{ secrets.ASTRO_KEY_SECRET }}
organization_id: ${{ secrets.ORGANIZATION_ID }}
bearer_token: ${{ secrets.BEARER_TOKEN }}

deploy-to-astro-sdk-integration-tests-on-KE:
if: |
contains(fromJSON('["both", "astro-sdk-integration-tests-on-KE"]'), inputs.environment_to_deploy) ||
github.event_name == 'schedule'
uses: ./.github/workflows/reuse-wf-deploy-to-astro-cloud.yaml
with:
git_rev: ${{ inputs.git_rev }}
environment_to_deploy: 'astro-sdk-integration-tests-on-KE'
secrets:
docker_registry: ${{ secrets.ASTRO_DOCKER_REGISTRY }}
organization_id: ${{ secrets.ORGANIZATION_ID }}
deployment_id: ${{ secrets.ASTRO_DEPLOYMENT_ID_KE }}
astronomer_key_id: ${{ secrets.ASTRO_KEY_ID_KE }}
astronomer_key_secret: ${{ secrets.ASTRO_KEY_SECRET_KE }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

- name: deploy
working-directory: python-sdk/tests_integration/astro_deploy
run: |
echo "deploying ${{ inputs.git_rev }}"
bash deploy.sh \
$ASTRO_DOCKER_REGISTRY \
$ASTRO_ORGANIZATION_ID \
$ASTRO_DEPLOYMENT_ID \
$ASTRO_KEY_ID \
$ASTRO_KEY_SECRET \
$ASTRO_DEPLOYMENT_ID_SINGLE_WORKER \
$ASTRO_KEY_ID_SINGLE_WORKER \
$ASTRO_KEY_SECRET_SINGLE_WORKER
wait-for-deployment-to-be-ready-and-trigger-dags-for-astro-sdk-integration-tests-on-KE:
if: |
github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && inputs.dags_to_trigger_after_deployment != '')
needs: deploy-to-astro-sdk-integration-tests-on-KE
uses: ./.github/workflows/reuse-wf-trigger-dag.yaml
with:
git_rev: ${{ inputs.git_rev }}
dags_to_trigger_after_deployment: ${{ inputs.dags_to_trigger_after_deployment }}
secrets:
astro_subdomain: ${{ secrets.ASTRO_SUBDOMAIN }}
deployment_id: ${{ secrets.ASTRO_DEPLOYMENT_ID_KE }}
astronomer_key_id: ${{ secrets.ASTRO_KEY_ID_KE }}
astronomer_key_secret: ${{ secrets.ASTRO_KEY_SECRET_KE }}
organization_id: ${{ secrets.ORGANIZATION_ID }}
bearer_token: ${{ secrets.BEARER_TOKEN }}
199 changes: 199 additions & 0 deletions .github/workflows/reuse-wf-deploy-to-astro-cloud.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
---
name: (Reusable workflows) Deploy to astro cloud

on: # yamllint disable-line rule:truthy
workflow_call:
inputs:
git_rev:
description: 'The git revision to deploy'
required: false
type: string
default: ''
environment_to_deploy:
description: 'astro cloud deployment to deploy to'
required: true
type: string
secrets:
docker_registry:
description: 'astro cloud docker registry'
required: true
organization_id:
description: 'astro cloud organization_id'
required: true
deployment_id:
description: 'astro cloud deployment_id'
required: true
astronomer_key_id:
description: 'astro cloud astronomer_key_id'
required: true
astronomer_key_secret:
description: 'astro cloud astronomer_key_secret'
required: true
SLACK_WEBHOOK_URL:
description: 'slack webhook url for sending notification'
required: true

jobs:
deploy-to-astro-cloud:
runs-on: 'ubuntu-20.04'
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: ${{ inputs.git_rev }}

- name: get git revision
id: get_git_revision
run: echo "git_rev=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

- name: deploy
working-directory: python-sdk/tests_integration/astro_deploy
run: |
echo "deploying ${{ inputs.git_rev }} to ${{ inputs.environment_to_deploy }}"
bash deploy.sh ${{ secrets.docker_registry }}\
${{ secrets.organization_id }} \
${{ secrets.deployment_id }} \
${{ secrets.astronomer_key_id }} \
${{ secrets.astronomer_key_secret }}
- name: send succeeded notification to Slack
if: success() && github.event_name == 'workflow_dispatch'
uses: slackapi/[email protected]
with:
# yamllint disable rule:line-length
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "✅ Deploy succeeded"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Environment to deploy:*\n ${{ inputs.environment_to_deploy }}"
},
{
"type": "mrkdwn",
"text": "*Deployed git revision*:\n<${{ github.server_url }}/${{ github.repository }}/tree/${{ steps.get_git_revision.outputs.git_rev }}|${{ steps.get_git_revision.outputs.git_rev }}>"
},
{
"type": "mrkdwn",
"text": "*Link to workflow run:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}|link>"
},
{
"type": "mrkdwn",
"text": "*Triggered by:*\n<${{ github.server_url }}/${{ github.triggering_actor }}|${{ github.triggering_actor }}>"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*---Workflow Detail---*"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Workflow name:*\n<${{ github.server_url }}/${{ github.repository }}/actions/workflows/${{ github.workflow }}|${{ github.workflow }}>"
},
{
"type": "mrkdwn",
"text": "*Event name:*\n${{ github.event_name }}"
},
{
"type": "mrkdwn",
"text": "*Workflow Ref:*\n<${{ github.server_url }}/${{ github.repository }}/tree/${{ github.ref }}|${{ github.ref_name }}>"
},
{
"type": "mrkdwn",
"text": "*Workflow Sha:*\n<${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|${{ github.sha }}>"
}
]
}
]
}
# yamllint enable rule:line-length
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

- name: send failure notification to Slack
if: failure()
uses: slackapi/[email protected]
with:
# yamllint disable rule:line-length
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "❌ Deploy failed"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Environment to deploy:*\n ${{ inputs.environment_to_deploy }}"
},
{
"type": "mrkdwn",
"text": "*Deployed git revision*:\n<${{ github.server_url }}/${{ github.repository }}/tree/${{ steps.get_git_revision.outputs.git_rev }}|${{ steps.get_git_revision.outputs.git_rev }}>"
},
{
"type": "mrkdwn",
"text": "*Link to workflow run:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}|link>"
},
{
"type": "mrkdwn",
"text": "*Triggered by:*\n<${{ github.server_url }}/${{ github.triggering_actor }}|${{ github.triggering_actor }}>"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*---Workflow Detail---*"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Workflow name:*\n<${{ github.server_url }}/${{ github.repository }}/actions/workflows/${{ github.workflow }}|${{ github.workflow }}>"
},
{
"type": "mrkdwn",
"text": "*Event name:*\n${{ github.event_name }}"
},
{
"type": "mrkdwn",
"text": "*Workflow Ref:*\n<${{ github.server_url }}/${{ github.repository }}/tree/${{ github.ref }}|${{ github.ref_name }}>"
},
{
"type": "mrkdwn",
"text": "*Workflow Sha:*\n<${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|${{ github.sha }}>"
}
]
}
]
}
# yamllint enable rule:line-length
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
82 changes: 82 additions & 0 deletions .github/workflows/reuse-wf-trigger-dag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
name: (Reusable workflows) Wait for deployment and trigger dags

on: # yamllint disable-line rule:truthy
workflow_call:
inputs:
git_rev:
description: 'The git revision to deploy'
required: false
type: string
default: ''
dags_to_trigger_after_deployment:
description: |
Comma separated list of dag_ids to trigger after deployment
(e.g. "example_mssql_transform, example_load_file")
required: false
type: string
default: ''
secrets:
astro_subdomain:
description: 'astro cloud subdomain'
required: true
deployment_id:
description: 'astro cloud deployment_id'
required: true
astronomer_key_id:
description: 'astro cloud astronomer_key_id'
required: true
astronomer_key_secret:
description: 'astro cloud astronomer_key_secret'
required: true
organization_id:
description: 'astro cloud organization_id'
required: true
bearer_token:
description: 'workspace bearer token'
required: true

jobs:
wait-for-deployment-to-be-ready-and-trigger-dag:
runs-on: 'ubuntu-20.04'
steps:

- name: Wait for deployment to be healthy
run: |
astro_core_api="https://api.astronomer.io/v1alpha1/organizations/${{secrets.organization_id }}/\
deployments"
tries=15
health_flag=false
while [[ $tries -gt 0 && $health_flag == false ]]; do
sleep 120
response=$(curl -s -H "Authorization: Bearer ${{ secrets.bearer_token }}" -X GET \
"$astro_core_api?deploymentIds=${{ secrets.deployment_id }}")
echo "response is $response"
deployment_status=$(echo "$response" | jq -r '.deployments[0].status')
echo "Deployment status is: $deployment_status"
echo "Waiting for deployment to be in ready state!!!"
if [[ $deployment_status == "HEALTHY" ]]; then
health_flag=true
fi
tries=$((tries - 1))
done
if [[ $health_flag == false ]]; then
echo "Timed out waiting for deployment ${{ secrets.deployment_id }} to be HEALTHY"
exit 1
fi
echo "${{ secrets.deployment_id }} is in HEALTHY state now"
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ inputs.git_rev }}

- name: Trigger DAG(s)
run: |
python3 python-sdk/dev/integration_test_scripts/trigger_dag.py \
"org-airflow-team-org" \
${{ secrets.deployment_id }} \
${{ secrets.astronomer_key_id }} \
${{ secrets.astronomer_key_secret }} \
--dag-ids "${{ inputs.dags_to_trigger_after_deployment }}"
Loading

0 comments on commit 54795d4

Please sign in to comment.