Skip to main content

Astro CI/CD templates for GitHub Actions

GitHub Action templates use the Astronomer-maintained deploy-action, which is available in the GitHub Marketplace. This action automates the deploy process and includes additional features for more complex automation workflows. Specifically, the action can automatically:

  • Choose a deploy type based on the files that were changed in a commit. This allows you to use the same template for DAG deploys and image deploys.
  • Test DAGs as part of the deploy process and prevent deploying if any of the tests fail. These tests are defined in the tests directory of your Astro project.
  • Create a preview Deployment to test your code before deploying to production. A Deployment preview is an Astro Deployment that mirrors the configuration of an existing Deployment.

See the Deploy Action README to learn more about using and customizing this action.

Read the following sections to choose the right template for your use case. 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. If you do not have access to Astronomer's deploy-action, use the private network templates.

To learn more about CI/CD on Astro, see Choose a CI/CD strategy.

Prerequisites

Each CI/CD template implementation might have additional requirements.

caution

If you use a self-hosted runner to execute jobs from GitHub Actions, the Astro CLI's config.yaml file, which stores default deploy details, might be shared across your organization and hence multiple CI/CD pipelines. To reduce the risk of accidentally deploying to the wrong Deployment, ensure the following:

  • Add ASTRO_API_TOKEN to your repository and include a check in your GitHub workflow to verify that it exists.
  • Use Deployment API tokens, which are scoped only to one Deployment, instead of Workspace or Organization API tokens.
  • Specify deployment-id or deployment-name in your action. For example, astro deploy <deployment-id> or astro deploy -n <deployment-name>.
  • Add the command astro logout at the end of your workflow to ensure that your authentication token is cleared from the config.yaml file.

Deploy action templates

Templates that use the Astronomer deploy-action trigger both image deploys and DAG deploys. If you committed changes only to DAG files, the action triggers a DAG deploy. If you committed changes to any other file, the action triggers an image deploy.

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 a GitHub secret:

    • ASTRO_API_TOKEN: The value for your Workspace or Organization API token.
  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 credentials as environment variables
    ASTRO_API_TOKEN: ${{ secrets.ASTRO_API_TOKEN }}

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

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 API 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 API 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 API 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 API 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:

    • ASTRO_API_TOKEN: The value for your Workspace or Organization API token.
  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 API token as an environment variable
    ASTRO_API_TOKEN: ${{ secrets.ASTRO_API_TOKEN }}

    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 <your-deployment-id>

Was this page helpful?

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.