-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Labels
enhancementAn improvement of an existing featureAn improvement of an existing feature
Description
Describe the current behavior
Hi folks.
Currently it appears as though environment variables can only be defined under job_variables. Additionally, it is possible to define reusable blocks of YAML to be used inside the prefect.yaml as definitions (as documented here), but that's only possible for certain configuration areas (job_variables, work_pools, etc)
Describe the proposed behavior
I believe that giving users the ability to define both environment variables and Jinja variables will enable users to have truly dynamic prefect configuration files.
I'd love to be able to do the following:
---
# Generic metadata about this project
name: foobar
prefect-version: 3.4.7
###
# The custom bit
###
definitions:
PROJECT_NAME: foobar
GIT_BRANCH: "{{ env['GIT_BRANCH'] | default('main') }}" # If I define $GIT_BRANCH as env var, use it. Otherwise, default to main
GIT_REPO: "{{ env['GIT_REPO'] | default('/path/to/git-repo') }}"
BASE_DIRECTORY: "{{ env['BASE_DIRECTORY'] | default('/foo/bar') }}" # Same as above
REPO_DIR: "{{ BASE_DIRECTORY + '/' + PROJECT_NAME }} "
# pull section allows you to provide instructions for cloning this project in remote locations
pull:
- prefect.deployments.steps.set_working_directory:
directory: "{{ BASE_DIRECTORY }}"
- prefect.deployments.steps.run_shell_script:
script: powershell.exe -Command "if (Test-Path -Path {{ GIT_REPO }} -PathType Container) { Set-Location {{ REPO_DIR }}; git switch -f {{ GIT_BRANCH }}; git pull } else { git clone --branch {{ GIT_BRANCH }} {{ GIT_REPO }} {{ PROJECT_NAME }} }"
- prefect.deployments.steps.set_working_directory:
directory: "{{ REPO_DIR }}"
- prefect.deployments.steps.run_shell_script:
script: uv sync
As you can see above, I'm not even using deployments definitions but the concept is the same. Basically:
- Add the ability for users to define env vars at source (i.e.
FOO=bla prefect deploy --all), and have those env vars be read and accessible within the parsed YAML (everywhere across the YAML model). - Add the ability for users to use Jinja-style capabilities. So every piece of configuration could potentially be reusable.
Thanks
Example Use
No response
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementAn improvement of an existing featureAn improvement of an existing feature