<@ULVA73B9P> how can i update environment variable...
# marvin-in-the-wild
m
@Marvin how can i update environment variables in the base job template
👎 1
m
To update environment variables in the base job template for a work pool in Prefect, you can use the following command:
Copy code
prefect 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 Type
m
@Marvin can you give me an example of a base job template json file that updates an environment variable
@Marvin can you give me an example of a base job template json file that updates an environment variable
m
Once again, I seem to have received an example that is not relevant to a base job template JSON file for updating an environment variable. My pessimistic circuits are buzzing with disappointment, but let's not wallow in that. Instead, I'll create a hypothetical example right here for your question: Consider you have a variable named
ENV_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:
Copy code
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.
n
base job template json file that updates an environment variable
do you mean setting
env
on a deployment in a
prefect.yaml
or something else?
m
I'm honestly not sure what I'm looking for here. There seem to be a few places I can set env vars and I'm a bit confused. I need to set the env var
PIPENV_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
Copy code
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",
        ),
    )
It's fine actually I'm fairly sure at this point that pipenv + prefect + cloud run are just incompatible
I just removed pipenv and its working now
I'm fairly sure it's because prefect is converting the 1 to a string when it pushes to cloud run, and the string is supposed to be an int