Skip to main content

Configuring branch deployments with GitHub or GitLab

Dagster+ feature

This feature is only available in Dagster+.

This guide covers setting up branch deployments for a Dagster project in Dagster+ Serverless or Hybrid with GitHub or GitLab. Once you've set up branch deployments, any time you create or update a pull request (or merge request) in your project repository, an associated branch deployment will automatically be created or updated in Dagster+.

note

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.

Dagster+ Serverless

Branch deployments are automatically configured for Serverless deployments when you configure CI/CD. For more information, see the CI/CD configuration guide.

Dagster+ Hybrid

Prerequisites

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

Step 1: Configure CI/CD

Follow the CI/CD configuration guide to set up CI/CD for Dagster+ Hybrid with your preferred Git provider.

Step 2: Create a branch deployment agent

While you can use your existing production agent for branch deployments 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: Update build.yaml with the branch deployment agent

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

For example:

build.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
note

In older deployments, you may have a dagster_cloud.yaml file instead of a build.yaml file.

Step 4: Add secrets to your Git provider

  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_URL
  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_URL - Your Dagster+ base URL (https://my_org.dagster.cloud)
  • DOCKERHUB_USERNAME - Your DockerHub username
  • DOCKERHUB_TOKEN - A DockerHub access token

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 steps 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.