Skip to main content

Astro CI/CD templates for GitHub Actions

Use the following CI/CD templates to automate deploying Apache Airflow DAGs from a GitHub repository using GitHub Actions.

The following templates for GitHub Actions are available:

Each template type supports multiple implementations. If you have one Deployment and one environment on Astro, use the single branch implementation. If you have multiple Deployments that support development and production environments, use the multiple branch implementation. If your team builds custom Docker images, use the custom image implementation.

GitHub Action templates use the Astronomer-maintained Deploy Action in the GitHub Marketplace. See the Deploy Action README to learn more about using and customizing this action. If you can't access public GitHub actions from your repository, see Private network templates.

For more information on each template or to configure your own, see Template overview. To learn more about CI/CD on Astro, see Choose a CI/CD strategy.

Prerequisites

Each CI/CD template implementation might have additional requirements.

Image-only templates

Image-only deploy templates build a Docker image and push it to Astro whenever you update any file in your Astro project.

To automate code deploys to a single Deployment using GitHub Actions, complete the following setup in a Git-based repository that hosts an Astro project:

  1. Set the following as GitHub secrets:

    • ASTRONOMER_KEY_ID = <your-key-id>
    • ASTRONOMER_KEY_SECRET = <your-key-secret>
  2. In your project repository, create a new YAML file in .github/workflows that includes the following configuration:

    name: Astronomer CI - Deploy code

    on:
    push:
    branches:
    - main

    env:
    ## Sets Deployment API key credentials as environment variables
    ASTRONOMER_KEY_ID: ${{ secrets.ASTRONOMER_KEY_ID }}
    ASTRONOMER_KEY_SECRET: ${{ secrets.ASTRONOMER_KEY_SECRET }}

    jobs:
    build:
    runs-on: ubuntu-latest
    steps:
    - name: Deploy to Astro
    uses: astronomer/deploy-action@v0.2

DAG-based templates

The following templates show how to configure DAG-based deploys in GitHub Actions. They use the Deploy action dag-deploy-enabled option to implement a DAG-based deploy workflow.

Implementation

To automate code deploys to a Deployment using GitHub Actions, complete the following setup in a Git-based repository that hosts an Astro project:

  1. Set the following as GitHub secrets:

    • ASTRONOMER_KEY_ID = <your-key-id>
    • ASTRONOMER_KEY_SECRET = <your-key-secret>
  2. In your project repository, create a new YAML file in .github/workflows that includes the following configuration:

    name: Astronomer CI - Deploy code

    on:
    push:
    branches:
    - main

    env:
    ## Sets Deployment API key credentials as environment variables
    ASTRONOMER_KEY_ID: ${{ secrets.ASTRONOMER_KEY_ID }}
    ASTRONOMER_KEY_SECRET: ${{ secrets.ASTRONOMER_KEY_SECRET }}

    jobs:
    build:
    runs-on: ubuntu-latest
    steps:
    - name: Deploy to Astro
    uses: astronomer/deploy-action@v0.2
    with:
    dag-deploy-enabled: true

This Github Actions script checks the diff between your current commit and your main branch when a commit is pushed to main. Make sure to customize the script for your specific use case.

Deployment preview templates

The Astronomer Deploy Action includes several sub-actions that can be used together to create a complete Deployment preview pipeline.

Prerequisites

Deployment preview implementation

  1. Copy and save the Deployment ID for your Astro deployment.
  2. Set the following GitHub secret in the repository hosting your Astro project:
  • Key: ASTRO_API_TOKEN
  • Secret: <your-token>
  1. In your project repository, create a new YAML file in .github/workflows named create-deployment-preview.yml that includes the following configuration:

    name: Astronomer CI - Create preview Deployment

    on:
    create:
    branches:
    - "**"

    env:
    ## Set your Workspace API key token as a GitHub secret
    ASTRO_API_TOKEN: ${{ secrets.ASTRO_API_TOKEN }}

    jobs:
    deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Create preview Deployment
    uses: astronomer/deploy-action@v0.2
    with:
    action: create-deployment-preview
    deployment-id: <main-deployment-id>
  2. In the same folder, create a new YAML file named deploy-to-preview.yml that includes the following configuration:

    name: Astronomer CI - Deploy code to preview

    on:
    pull_request:
    branches:
    - main

    env:
    ## Set your Workspace API key token as a GitHub secret
    ASTRO_API_TOKEN: ${{ secrets.ASTRO_API_TOKEN }}

    jobs:
    deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Deploy code to preview
    uses: astronomer/deploy-action@v0.2
    with:
    action: deploy-deployment-preview
    deployment-id: <main-deployment-id>
  3. In the same folder, create a new YAML file named delete-preview-deployment.yml that includes the following configuration:

    name: Astronomer CI - Delete Preview Deployment

    on:
    delete:
    branches:
    - "**"
    env:
    ## Set your Workspace API key token as a GitHub secret
    ASTRO_API_TOKEN: ${{ secrets.ASTRO_API_TOKEN }}

    jobs:
    deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Delete preview Deployment
    uses: astronomer/deploy-action@v0.2
    with:
    action: delete-deployment-preview
    deployment-id: <main-deployment-id>
  4. In the same folder, create a new YAML file named deploy-to-main-deployment.yml that includes the following configuration:

    name: Astronomer CI - Deploy code to main Deployment

    on:
    push:
    branches:
    - main

    env:
    ## Set your Workspace API key token as a GitHub secret
    ASTRO_API_TOKEN: ${{ secrets.ASTRO_API_TOKEN }}

    jobs:
    deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Deploy code to main Deployment
    uses: astronomer/deploy-action@v0.2
    with:
    deployment-id: <main-deployment-id>

    All four workflow files must have the same Deployment ID specified. The actions use this Deployment ID to create and delete preview Deployments based on your main Deployment.

Private network templates

If you use GitHub Enterprise and can't use the public Astronomer Deploy Action in the GitHub Marketplace, use the following templates to implement CI/CD.

To automate code deploys to a Deployment using GitHub Actions, complete the following setup in a Git-based repository that hosts an Astro project:

  1. Set the following as GitHub secrets:

    • ASTRONOMER_KEY_ID = <your-key-id>
    • ASTRONOMER_KEY_SECRET = <your-key-secret>
  2. In your project repository, create a new YAML file in .github/workflows that includes the following configuration:

    name: Astronomer CI - Deploy code

    on:
    push:
    branches:
    - main

    env:
    ## Sets Deployment API key credentials as environment variables
    ASTRONOMER_KEY_ID: ${{ secrets.ASTRONOMER_KEY_ID }}
    ASTRONOMER_KEY_SECRET: ${{ secrets.ASTRONOMER_KEY_SECRET }}

    jobs:
    build:
    runs-on: ubuntu-latest
    steps:
    - name: checkout repo
    uses: actions/checkout@v3
    - name: Deploy to Astro
    run: |
    curl -sSL install.astronomer.io | sudo bash -s
    astro deploy

Sign up for Developer Updates

Get a summary of new Astro features once a month.

You can unsubscribe at any time.
By proceeding you agree to our Privacy Policy, our Website Terms and to receive emails from Astronomer.