A code location specifies a single Python package or file that defines your Dagster code. When you add a code location in Dagster+, you're instructing your deployment's agent where to find your code. This applies to both Hybrid and Serverless deployments.
Dagster+ agents use this location configuration to load your code and upload metadata about your jobs. Each full deployment - for example, prod - can include code from one or more code locations.
By the end of this guide, you'll understand:
The requirements for Dagster code to work with Dagster+
How to interact with code locations using the Dagster UI
How to interact with code locations using the dagster-cloud CLI
And you're using an Amazon Elastic Container Service (ECS), Kubernetes, or Docker agent, your code must be packaged into a Docker image and pushed to a registry your agent can access. Dagster+ doesn't need access to your image - your agent only needs to be able to pull it.
Additionally, the Dockerfile for your image doesn't need to specify an entry point or command. These will be supplied by the agent when it runs your code using your supplied image.
And you're using a local agent, your code must be in a Python environment that can be accessed on the same machine as your agent.
Additionally, note that:
Your code doesn't need to use the same version of Dagster as your agent
Different code locations can use different versions of Dagster
Dagster+ doesn't require a workspace.yaml file. You can still create a workspace.yaml file to load your code in an open source Dagster webserver instance, but doing so won't affect how your code is loaded in Dagster+.
Editor, Admin, or Organization Admin permissions are required to manage code locations in Dagster+.
If you're an Editor or Admin, you can only manage code locations in deployments where you're an Editor or Admin.
Interacting with code locations can be done using the Dagster+ UI or the dagster-cloud CLI. The CLI commands perform the same underlying operations as those in the Deployment tab of the UI.
For Serverless deployments, there are two ways to deploy your code to Dagster+:
Start from a template- Use one of our quickstart templates to get up and running. All templates come with CI/CD already configured and will be cloned to a new git repository.
Import an existing project - Import an existing git repository using our GitHub or GitLab integrations or the dagster-cloud CLI. Note: If using the GitHub or GitLab integrations, Dagster+ will:
Add a dagster_cloud.yaml to the repository if one doesn't already exist, and
Select an option in the UI and follow the prompts.
Sign in to your Dagster+ account.
Click Deployment.
Click + Add code location. This will open a YAML editor with a schema describing the acceptable fields:
In the editor, define the code location's configuration. Refer to the dagster_cloud.yaml reference for information about the properties in the configuration.
For example, the following config specifies that a code location should include a secret named my_secret and run in a k8s namespace (my_namespace) whenever the Kubernetes agent creates a pod for the location:
The agent will attempt to load your code and send its metadata to Dagster+. Note: This may take some time.
Once your code has loaded, the location will show a green Loaded status and jobs will appear in Dagster+. If the agent is unable to load your code, the location will show an error with more information.
Code locations can be added using the deployment add-location command. For example, to add Dagster+'s public example image, run:
# Set up YAML file for example locationcat> example_location.yaml <<EOL
location_name: cloud-examples
image: dagster/dagster-cloud-examples:latest
code_source:
package_name: dagster_cloud_examples
EOL
dagster-cloud deployment add-location --from example_location.yaml
To modify a code location, click the dropdown menu to the right of the location. In the menu, click Modify:
After a code location is updated, the agent will perform a rolling update of your code and jobs will update in Dagster+. Note: Updating code won't interrupt any currently launched runs.
Heads up! When using this command, the full set of information about the location must be specified even if only one piece of configuration is modified.
To reload your code and upload job metadata to Dagster+ without modifying the code location, click the Redeploy button:
For example, if the agent was unable to pull your image due to a permissions issue that's since been addressed, clicking Redeploy will tell the agent to try again.
The YAML configuration for all code locations in a workspace can be kept in a dagster_cloud.yaml file and reconciled with the workspace config in Dagster+ using the deployment sync-locations command.
For example, if you have the following dagster_cloud.yaml file: