Skip to main content

Setting up branch deployments

Dagster+ feature

This feature is only available in Dagster+.

This guide covers setting up branch deployments for a code location using GitHub, GitLab, or an alternative CI platform using the dagster-cloud CLI. Once you've set up branch deployments, any time you create or update a pull request (or merge request) in the repository for your code location, it will automatically create or update an associated branch deployment in Dagster+.

info

Output created from a branch deployment -- such as a database, table, etc. -- won't be automatically removed from storage once a branch is merged or closed. For more information on handling this output, see the best practices section.

Prerequisites

To follow the steps in this guide, you'll need:

Step 1: Generate a Dagster+ agent token

The first step is to generate a token for the Dagster+ agent. The Dagster+ agent will use this token to authenticate to the agent API.

  1. Sign in to your Dagster+ instance.
  2. Click the user menu (your profile icon) > Organization Settings.
  3. On the Organization Settings page, click the Tokens tab.
  4. Click the Create agent token button.
  5. After the token has been created, click Reveal token and copy the token.

Keep the token somewhere handy, as you'll need it to complete the setup.

Step 2: Create and configure a branch deployment agent (Hybrid only)

info

If you are using Dagster+ Serverless, you can skip this step.

While you can use your existing production agent for branch deployment on Dagster+ Hybrid, we recommend creating a dedicated branch deployment agent. This ensures that your production instance isn't negatively impacted by the workload associated with branch deployments.

  1. Set up a new Kubernetes agent. For instructions, see the Kubernetes agent setup guide.

  2. After the agent is set up, modify your Helm values file to include the following:


dagsterCloud:
branchDeployments: true
workspace:
serverTTL:
enabled: true
ttlSeconds: 7200

Step 3: Automate branch deployment creation

You can set up GitHub to automatically create branch deployments for new pull requests, using GitHub Actions.

This approach may be a good fit if:

  • You use GitHub for version control
  • You want Dagster to fully automate branch deployments

Step 3.1: Add GitHub CI/CD script to your project

info

If you used the GitHub app in Dagster+ Serverless to configure your repository, you can skip ahead to Step 3.5.

Copy the following files to your project, and replace all references to quickstart_etl with the name of your project:

Step 3.2: Add the agent registry to dagster_cloud.yaml

info

If you used the GitHub app in Dagster+ Serverless to configure your repository, you can skip ahead to Step 3.5.

In the dagster_cloud.yaml file, replace build.registry with the registry used by the agent you created in step 1.

For example:

dagster_cloud.yaml
locations:
- location_name: example_location
code_source:
python_file: repo.py
build:
directory: ./example_location
registry: 764506304434.dkr.ecr.us-east-1.amazonaws.com/branch-deployment-agent

Step 3.3: Configure GitHub Action secrets

info

If you used the GitHub app in Dagster+ Serverless to configure your repository, you can skip ahead to Step 3.5.

  1. In your GitHub repository, click the Settings tab.
  2. In the Security section of the sidebar, click Secrets > Actions.
  3. Click New repository secret.
  4. In the Name field, enter the name of the secret. For example, DAGSTER_CLOUD_API_TOKEN
  5. In the Value field, paste the value of the secret.
  6. Click Add secret.

Repeat steps 3-6 for each of the secrets required for the registry used by the agent you created in step 1. See below for more details:

  • DAGSTER_CLOUD_API_TOKEN - The Dagster+ agent token you created in step 1
  • DAGSTER_CLOUD_URL - Your Dagster+ base URL (https://my_org.dagster.cloud)
  • DOCKERHUB_USERNAME - Your DockerHub username
  • DOCKERHUB_TOKEN - A DockerHub access token

Step 3.4: Configure GitHub Action

info

If you used the GitHub app in Dagster+ Serverless to configure your repository, you can skip ahead to Step 3.5.

In this step, you'll update the GitHub workflow file in your repository to set up Docker registry access.

In the .github/workflows/dagster-plus-deploy.yml file, un-comment the step associated with your registry. For example, for an Amazon ECR registry, you'd un-comment the following portion of the workflow file:

# dagster-plus-deploy.yml
jobs:
dagster-cloud-deploy:
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

Save and commit the file to your repository.

Step 3.5: Verify GitHub action runs

The last step is to verify that the GitHub Action runs successfully.

  1. In the repository, click the Actions tab.
  2. In the list of workflows, locate the latest branch deployment run. For example:

Show this in the UI

Accessing branch deployments

Once configured, branch deployments can be accessed:

Every pull request in the repository contains a View in Cloud link, which will open a branch deployment - or a preview of the changes - in Dagster+.

View in Cloud preview link highlighted in a GitHub pull request

Changing the base deployment

The base deployment has two main purposes:

  • It sets which full deployment is used to propagate Dagster+ managed environment variables that are scoped for branch deployments.
  • It is used in the UI to track changes to the branch deployment from its parent full deployment.

The default base for branch deployments is prod. To configure a different full deployment as the base, create a branch deployment using the dagster-cloud CLI (see step 3.1 above) and specify the deployment with the optional --base-deployment-name parameter.

Best practices

To ensure the best experience when using branch deployments, we recommend:

  • Configuring jobs based on environment. Dagster automatically sets environment variables containing deployment metadata, allowing you to parameterize jobs based on the executing environment. Use these variables in your jobs to configure things like connection credentials, databases, and so on. This practice will allow you to use branch deployments without impacting production data.
  • Creating jobs to automate output cleanup. As branch deployments don't automatically remove the output they create, you may want to create an additional Dagster job to perform the cleanup.

Next steps