Matthew Bell
03/13/2024, 3:35 AMMarvin
03/13/2024, 3:35 AMprefect work-pool update --base-job-template base-job-template.json my-work-pool
This command updates a work pool's base job template to the contents of a file named base-job-template.json
. Each work pool has a base job template that lets you customize the behavior of the worker executing flow runs from the work pool. The base job template has a variables
section which defines the fields available to be customized per deployment.
For more details on customizing the base job template, you can refer to:
- Work Pools
- Developing a New Worker TypeMatthew Bell
03/13/2024, 3:36 AMMatthew Bell
03/13/2024, 3:37 AMMarvin
03/13/2024, 3:38 AMENV_VAR
that you would like to set to the value "example-value"
in your base job template. The JSON content would look something like this:
json
{
"apiVersion": "batch/v1",
"kind": "Job",
"metadata": {
"name": "{{ flow_run_id }}"
},
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "flow-container",
"image": "your-docker-image",
"env": [
{
"name": "ENV_VAR",
"value": "example-value"
},
// ... other environment variables
]
// ... other container specs
}
],
"restartPolicy": "Never"
}
}
}
}
In the env
section of the container spec, you can see an array of environment variables being set. Adding an object to this array with a name
and value
field allows you to define a new environment variable or alter the value of an existing one for the job that will run your flow.
Please take this example as a template and adjust the name
, value
, image
, and other fields to suit your specific requirements.Nate
03/13/2024, 3:40 AMbase job template json file that updates an environment variabledo you mean setting
env
on a deployment in a prefect.yaml
or something else?Matthew Bell
03/13/2024, 4:20 AMPIPENV_VENV_IN_PROJECT
to 1
at build time. This is needed for my dockerfile to build correctly on Google Cloud run.
Currently I have it set inside my dockerfile with
ENV PIPENV_VENV_IN_PROJECT 1
When I deploy my docker image manually to google cloud run it works as expected. But when I deploy it through prefect it breaks as this env var doesn't seem to be set or maybe it gets overwritten.
This surprises me as I wouldn't have thought prefect would mess with env vars inside my custom dockerfile, but it does seem to.
I'm wondering where I can set this env var in prefect to have it set properly when my image runs on cloud run.
I have tried setting it in the job variables of my deploy like so, but this didn't work
env = {"PIPENV_VENV_IN_PROJECT": "1"}
if __name__ == "__main__":
r = my_flow.deploy(
name="hello",
job_variables={"env": env},
work_pool_name="main-google-cloud-run",
image=DeploymentImage(
name="cdk_delta:latest",
platform="linux/amd64",
dockerfile="./Dockerfile",
),
)
Matthew Bell
03/13/2024, 4:48 AMMatthew Bell
03/13/2024, 4:48 AMMatthew Bell
03/13/2024, 4:53 AM