Serverless runtime environment
With a Dagster+ Serverless deployment, you can customize the runtime environment where your code executes. You may want to:
Dagster uses PEX to package your code and deploy them on Docker images. You also have the option to disable PEX-based deploys and deploy using a Docker image instead of PEX.
Use a different Python version
The default Python version for Dagster+ Serverless is Python 3.8. Python versions 3.9 through 3.12 are also supported. You can specify the Python version you want to use in your GitHub or GitLab workflow, or by using the dagster-cloud
CLI.
- GitHub
- GitLab
- CLI
In your .github/workflows/deploy.yml
file, update the PYTHON_VERSION
environment variable with your desired Python version:
Loading...
-
Open your
.gitlab-ci.yml
file. If your.gitlab-ci.yml
contains aninclude
with a link to a Dagster provided CI/CD template:Loading...
Follow the link and replace the contents of your
.gitlab-ci.yml
with the YAML document at the link address. Otherwise, continue to the next step. -
Update the
PYTHON_VERSION
environment variable with your desired Python versionUpdating the Python version in .gitlab-ci.ymlLoading...
You can specify the Python version when you deploy your code with the dagster-cloud serverless deploy-python-executable
command:
dagster-cloud serverless deploy-python-executable --python-version=3.11 --location-name=my_location
Use a different base image
When possible, you should add dependencies by including the corresponding Python libraries in your Dagster project's setup.py
file:
Loading...
When adding dependencies with the setup.py
file isn't possible, you can build a custom base image:
Setting a custom base image isn't supported for GitLab CI/CD workflows out of the box, but you can write a custom GitLab CI/CD yaml file that implements the manual steps noted.
-
Include
dagster-cloud[serverless]
as a dependency in your Docker image by adding the following line to yourDockerfile
:RUN pip install "dagster-cloud[serverless]"
-
Build your Docker image, using your usual Docker toolchain.
-
Upload your Docker image to Dagster+ using the
upload-base-image
command. This command will print out the tag used in Dagster+ to identify your image:$ dagster-cloud serverless upload-base-image local-image:tag
...
To use the uploaded image run: dagster-cloud serverless deploy-python-executable ... --base-image-tag=sha256_518ad2f92b078c63c60e89f0310f13f19d3a1c7ea9e1976d67d59fcb7040d0d6 -
Specify this base image tag in you GitHub workflow, or using the
dagster-cloud
CLI:- GitHub
- CLI
In your
.github/workflows/deploy.yml
file, add theSERVERLESS_BASE_IMAGE_TAG
environment variable and set it to the tag printed out in the previous step:Setting a custom base image in deploy.ymlLoading...
You can specify the base image when you deploy your code with the
dagster-cloud serverless deploy-python-executable
command:dagster-cloud serverless deploy-python-executable \
--base-image-tag=sha256_518ad2f92b078c63c60e89f0310f13f19d3a1c7ea9e1976d67d59fcb7040d0d6 \
--location-name=my_location
Include data files
To add data files to your deployment, use the Data Files Support built into Python's setup.py
. This requires adding a package_data
or include_package_data
keyword in the call to setup()
in setup.py
. For example, given this directory structure:
- setup.py
- quickstart_etl/
- __init__.py
- definitions.py
- data/
- file1.txt
- file2.csv
If you want to include the data folder, modify your setup.py
to add the package_data
line:
Loading...
Disable PEX deploys
Prior to using PEX files, Dagster+ deployed code using Docker images. This feature is still available.
You can disable PEX in your GitHub or GitLab workflow, or by using the dagster-cloud
CLI.
- GitHub
- GitLab
- CLI
In your .github/workflows/deploy.yml
file, update the ENABLE_FAST_DEPLOYS
environment variable to false
:
Loading...
-
Open your
.gitlab-ci.yml
file. If your.gitlab-ci.yml
contains aninclude
with a link to a Dagster provided CI/CD template:Loading...
Follow the link and replace the contents of your
.gitlab-ci.yml
with the YAML document at the link address. Otherwise, continue to the next step. -
Update the
DISABLE_FAST_DEPLOYS
variable totrue
Disable PEX deploys in .gitlab-ci.ymlLoading...
You can deploy using a Docker image instead of PEX by using the dagster-cloud serverless deploy
command instead of the dagster-cloud-serverless deploy-python-executable
command:
dagster-cloud serverless deploy --location-name=my_location
You can customize the Docker image using lifecycle hooks or by customizing the base image:
- Lifecycle hooks
- Base image
This method is the easiest to set up, and doesn't require setting up any additional infrastructure.
In the root of your repo, you can provide two optional shell scripts: dagster_cloud_pre_install.sh
and dagster_cloud_post_install.sh
. These will run before and after Python dependencies are installed. They're useful for installing any non-Python dependencies or otherwise configuring your environment.
This method is the most flexible, but requires setting up a pipeline outside of Dagster to build a custom base image.
Setting a custom base image isn't supported for GitLab CI/CD workflows out of the box, but you can write a custom GitLab CI/CD yaml file that implements the manual steps noted.
-
Build you base image
-
Specify this base image tag in your GitHub workflow, or using the
dagster-cloud
CLI:- GitHub
- CLI
In your
.github/workflows/deploy.yml
file, add theSERVERLESS_BASE_IMAGE_TAG
environment variable and set it to the tag printed out in the previous step:Setting a custom base image in `deploy.yml`Loading...
You can specify the base image when you deploy your code with the
dagster-cloud serverless deploy
command:dagster-cloud serverless deploy --base-image=my_base_image:latest --location-name=my_location