Prerequisites
- An Astro project hosted in a Git repository that CircleCI can access.
- An Astro Deployment.
- A Deployment API token, Workspace API token, or Organization API token.
- A CircleCI account.
Image deploy templates
Image deploy templates build a Docker image and push it to Astro whenever you update any file in your Astro project.- Single branch
- Multiple branch
- Custom Image
To automate code deploys to a Deployment using CircleCI for a single branch implementation, complete the following setup in a Git-based repository that hosts an Astro project:
Configuration requirements
- You have a
mainbranch of an Astro project hosted in a single GitHub repository. - You have a production Deployment on Astro where you want to deploy your
mainGitHub branch. - You have a production CircleCI context that stores environment variables for your CI/CD workflows.
Implementation
- Set the following environment variables in a CircleCI context:
ASTRO_API_TOKEN: The value for your Workspace or Organization API token.ASTRO_DEPLOYMENT_ID: The ID for your Deployment.
- Create a new YAML file in
.circleci/config.ymlthat includes the following configuration:
.circleci/config.yml
Dag deploy templates
A dag deploy template uses the--dags flag in the astro deploy command in the Astro CLI to push only dags to your Deployment.
This CI/CD pipeline deploys your dags to Astro when one or more files in your dags folder are modified. It deploys the rest of your Astro project as a Docker image when other files or directories are also modified. For more information about the benefits of this workflow, see Deploy dags only.
Configuration requirements
For each Deployment that you use with dag deploy templates, you must enable dag deploys.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
To automate code deploys to a Deployment using CircleCI, complete the following setup in a Git-based repository that hosts an Astro project:- Set the following environment variables in a CircleCI context:
ASTRO_API_TOKEN: The value for your Workspace or Organization API token.ASTRO_DEPLOYMENT_ID: The ID for your Deployment.
- In your project repository, create a new YAML file in
.circleci/config.ymlthat includes the following configuration:
.circleci/config.yml
dags then it executes a dag-only deploy. Otherwise, it executes an image-based deploy. Make sure to customize the script to use your specific branch and context.
You can customize this script to work for multiple branches as shown in the image-based multi-branch deploy template by creating separate job and workflow for each branch.