Learn by example? Check out the example repo, which is set up to run in Dagster Cloud.
A code location specifies a single Python package or file that defines your Dagster code. When you add a code location in Dagster Code, you're instructing the agent where to find your code.
When you add or update a code location, the agent uses the location configuration to load your code and upload metadata about your jobs to Dagster Cloud. Each full deployment - for example, prod - can include code from one or more code locations.
Note that, unlike Dagster Open Source, Dagster Cloud doesn't require a workspace.yaml file. Instead, you use the Dagster Cloud API to configure your workspace. You can still create a workspace.yaml file if you want to load your code in an open-source Dagit instance, but doing so won't affect how your code is loaded in Dagster Cloud.
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 Cloud 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
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:
Property
Description
code_source
Set this key to either python_file: or package_name:to specify where to find your code.
executable_path
Optional. Define a specific Python executable if your code should run in a certain Python environment. If left undefined, the code will run using the default dagster command-line entry-point.
image
Required if not using a local agent. Specifies a Docker image for use with containerized agents.
working_directory
Specifies the directory to use to resolve relative Python imports while loading your code.
attribute
Specifies only a specific Dagster repository should be loaded.
container_context
Optional. For agent versions 0.14.9 and later. Customizes the code location for a specific execution environment. Refer to the Agent documentation for info on available configuration options for each agent type, including declaring environment variables and secrets.
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 Cloud. 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 Cloud. If the agent is unable to load your code, the location will show an error with more information.
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 Cloud. Note: Updating code won't interrupt any currently launched runs.
To reload your code and upload job metadata to Dagster Cloud 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.
These commands perform the same underlying operations as editing your code locations in the Deployment tab in Dagster Cloud. Refer to the dagster-cloud CLI guide for more info and installation instructions.
Note: If updating an existing code location, the full set of information about the location must be specified even if only one piece of configuration is modified.
You can also keep the YAML configuration for your entire workspace in a file and use the dagster-cloud sync command to reconcile the workspace config in Dagster Cloud with that local file.
For example, if you have the following dagster_cloud.yaml file: