Astro CI/CD templates for GitLab
Use the following CI/CD templates to automate deploys to Astro from a GitLab repository.
Read the following sections to choose the right template for your project. The templates for GitLab include the image deploy templates and dag deploy templates.
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 you want your CI/CD process to automatically decide which deploy strategy to choose, see Dag deploy templates.
To learn more about CI/CD on Astro, see Choose a CI/CD strategy.
Prerequisites
- An Astro project hosted in a GitLab repository.
- An Astro Deployment.
- A Deployment API token, Workspace API token, or Organization API token.
Each CI/CD template implementation might have additional requirements.
Image deploy templates
Single branch
Multiple branch
Use this template to push code to from a GitLab repository to Astro.
- Set the following environment variables in your GitLab project:
ASTRO_API_TOKEN
: The value for your Workspace or Organization API token.DEPLOYMENT_ID
: The ID of your Astro Deployment. You can copy the ID from your Deployment’s home page in the Astro UI.
Astronomer recommends that you always mask your API token to prevent it from being accessible in plain text. You can also set the API token as an external secret for an extra layer of security.
- Go to Build > Pipeline Editor and commit the following:
Dag deploy templates
The dag deploy template uses the --dags
flag in the Astro CLI to push dag changes to Astro. These CI/CD pipelines deploy your dags only when files in your dags
folder are modified, and they deploy the rest of your Astro project as a Docker image when other files or directories are modified. For more information about the benefits of this workflow, see Deploy dags only.
If you stage multiple commits to dag files and push them all at once to your remote branch, the template only deploys dag code changes from the most recent commit. It will miss any code changes made in previous commits.
To avoid this, either push commits individually or configure your repository to Squash commits for pull requests that merge multiple commits simultaneously.
Single branch implementation
Use this template to push code to from a GitLab repository to Astro.
- Set the following environment variables in your GitLab project:
ASTRO_API_TOKEN
: The value for your Workspace or Organization API token.DEPLOYMENT_ID
: The ID of your Astro Deployment. You can copy the ID from your Deployment’s page in the Astro UI.
Astronomer recommends that you always mask your API token to prevent it from being accessible in plain text. You can also set the API token as an external secret for an extra layer of security.
- Go to the Editor option in your project’s CI/CD section and commit the following: