Configuring CI/CD in Dagster+
Follow the steps below to create a GitHub or GitLab CI/CD configuration file in your project to deploy and synchronize your code to Dagster+. You can also use other Git providers, or a local Git repository to run your own CI/CD process.
When you sign up for Dagster+ Serverless, you create a GitHub or GitLab repository that contains basic Dagster project code and a CI/CD workflow file consistent with Dagster+ best practices.
Pushing changes to the main branch of that project repository will automatically deploy them to Dagster+. Pull or merge requests will create ephemeral branch deployments that you can preview and test in the Dagster+ UI.
To add another Dagster project to your Serverless deployment, follow the steps in this guide to scaffold a GitHub or GitLab CI/CD configuration file in your new project to deploy and synchronize your code to Dagster+ Serverless. You can also use other Git providers or a local Git repository with the dagster-cloud CLI to run your own CI/CD process.
GitHub
Before following the steps in this section, you will need to:
- Create a Dagster project
- Install the GitHub
ghCLI and authenticate to GitHub withgh auth login - Log in to your Dagster organization with
dg plus login
-
Change to the project root directory:
cd <project-directory> -
Activate the virtual environment:
- MacOS/Unix
- Windows
shell source .venv/bin/activateshell .venv\Scripts\activate -
Initialize a Git repository in the project directory:
git init . -
Create a remote repository on GitHub to connect with the local project repository. Be sure to select
Push an existing local repository to github.comwhen prompted:gh repo create -
Use the
dg plus deploy configureCLI command to scaffold deployment configuration files for your deployment type, including a GitHub Actions workflow file:dg plus deploy configure --git-provider github -
Create a Dagster Cloud API token and set it as a GitHub Action secret for the project:
dg plus create ci-api-token --description 'Used in my-project GitHub Actions' | gh secret set DAGSTER_CLOUD_API_TOKEN -
Commit and push your changes to deploy to Dagster+:
git add . && git commit -m "Deploy to Dagster+" && git push origin main
During the deployment, the agent will attempt to load your code and update the metadata in Dagster+. When that has finished, you should see the GitHub Action complete successfully, and also be able to see the code location under the Deployment tag in Dagster+.
We recommend periodically (every 6 months or so) updating the version of the Dagster GitHub Actions in your workflow files. These actions use version tags that follow the Dagster release convention (e.g., @v1.11.13). You can find the most recent Dagster release on GitHub.
GitLab
Before following the steps in this section, you will need to:
- Create a Dagster project
- Log in to your Dagster organization with
dg plus login
-
Change to the project root directory:
cd <project-directory> -
Activate the virtual environment:
- MacOS/Unix:
source .venv/bin/activate - Windows:
.venv\Scripts\activate
- MacOS/Unix:
-
Initialize a Git repository in the project directory:
git init . -
Commit and push your changes:
git add . && git commit -m "Initial commit" -
Create a remote repository on GitLab and push your changes to it. You can either do so in the GitLab UI by navigating to the new project creation page, or on the command line by running the following command, replacing USERNAME with your GitLab username or organization workspace:
git push --set-upstream git@gitlab.com:USERNAME/$(git rev-parse --show-toplevel | xargs basename).git $(git rev-parse --abbrev-ref HEAD) -
Use the
dg plus deploy configureCLI command to scaffold deployment configuration files for your deployment type, including a GitLab CI/CD configuration file:dg plus deploy configure --git-provider gitlab -
Create a Dagster Cloud API token:
dg plus create ci-api-token --description 'Used in Dagster project GitHub Actions' -
Set the Dagster Cloud API token as a CI/CD variable in the GitLab repo:
- Navigate to the project page in GitLab.
- In the left sidebar, click Settings > CI/CD.
- On the settings page, click Variables.
- Under Project variables, click Add variable.
- In the Key field, enter
DAGSTER_CLOUD_API_TOKEN - In the Value field, paste the Dagster Cloud API token.
- Optionally update the variable type, environments, visibility, flags, and description fields as needed.
- Click Add variable.
After following these steps, commiting and pushing additional changes to your Dagster project in GitLab will deploy them to your Dagster+ organization.
Other Git providers or local Git repository
- Dagster+ Serverless
- Dagster+ Hybrid
Before following the steps in this section, you must first create a Dagster project.
If you don't want to use our automated GitHub/GitLab process, you can use the dagster-cloud command-line CLI in another CI environment or locally.
-
First, create a new project with the
create-dagster projectcommand and activate the project virtual environment. -
Next, install the
dagster-cloudCLI and use theconfigurecommand to authenticate it to your Dagster+ organization:pip install dagster-cloud
dagster-cloud configure
You can also configure the dagster-cloud tool non-interactively; for more information, see the dagster-cloud installation and configuration docs.
- Finally, deploy your project to Dagster+ using the
serverlesscommand, replacingYOUR_PACKAGE_NAMEwith the name of your Dagster package:
dagster-cloud serverless deploy-python-executable ./my-project \
--location-name example \
--package-name YOUR_PACKAGE_NAME \
--python-version 3.12
If you are using Windows, you will need to replace the deploy-python-executable command with deploy:
dagster-cloud serverless deploy ./my-project \
--location-name example \
--package-name YOUR_PACKAGE_NAME \
--python-version 3.12
If you are using a non-GitHub CI/CD provider, your system should use the dg deploy command to deploy code locations to Dagster+.
Before following the steps in this section, you must:
- Create a Dagster project
- Scaffold deployment configuration files (Dockerfile,
build.yaml,containter_context.yaml) in the project root directory withdg plus deploy configure - Log in to your Dagster organization with
dg plus login
-
Set the build environment variables. Note that all variables are required:
DAGSTER_CLOUD_ORGANIZATION: The name of your organization in Dagster+.DAGSTER_CLOUD_API_TOKEN: A Dagster+ API token. Note: This is a sensitive value and should be stored as a CI/CD secret if possible.DAGSTER_BUILD_STATEDIR: A path to a blank or non-existent temporary directory on the build machine that will be used to store local state during the build.
-
Initialize the build session:
dg plus deploy start --deployment=DEPLOYMENT_NAME --project-dir=.This reads the
build.yamlconfiguration and initializes the DAGSTER_BUILD_STATEDIR. -
Build and upload Docker images for your code locations:
dg plus deploy build-and-pushThis command will upload to the registry specified in
build.yaml. The upload step is specific to your Docker container registry and will require authentication. For more information and a full list of command options, see thedg plus deploy build-and-pushAPI docs. -
Deploy to Dagster+:
dg plus deployThis command updates the code locations in Dagster+. Once this finishes successfully, you should be able to see the code locations under the Deployments tab in Dagster+.
Creating branch deployments using the CLI requires some additional steps. For more information, see Setting up branch deployments.