hi! - I'm trying to sent environment variables for a deployment that will run in a docker image. I ...
g
hi! - I'm trying to sent environment variables for a deployment that will run in a docker image. I am using this example, but
MY_SECRET_KEY
is rendering as a string -
{{ prefect.secret('MY_SECRET_KEY') }}
. Is it possible to get the rendered prefect secret in a deployment?
Copy code
deployment = Deployment.build_from_flow(
    flow=my_flow,
    name="my-flow-deployment",
    infrastructure=docker_infrastructure,
    work_pool_name="my-docker-pool",
    job_variables={
        "env": {
            "MY_SECRET_KEY": "{{ prefect.secret('MY_SECRET_KEY') }}"
        }
    }
)
b
I'm not certain, but I think the
{{...}}
syntax is just for yaml deployments? As you are deploying from python code, you probably don't want them
but also, I would recommend defining these secrets in the work pool json
g
@benorbital thanks for the response. I was originally trying to define in the work pool. Is it possible to use a Prefect secret in the work pool json?
n
hi @Gio -
build_from_flow
is old syntax for use with agents and infra blocks (deprecated). you'll want to use
some_flow.deploy()
as outlined here you can create the work pool either: • in the UI • by simply running
prefect worker start --type docker --pool some-new-pool
and we'll create a default work pool of that type
g
@Nate thank you! I've actually been using
.deploy()
I was copying that the the ask-mavin channel. For the work pool, I'm wondering if there is a way to use prefect Secrets in the work pool, so I'm not hardcoding them. Is this possible?
n
Copy code
from prefect import flow

flow.from_source(
    source="<https://gist.github.com/1672b241f7ae3e3a3ff970a07dfcf82d.git>",
    entrypoint="job_vars.py:my_flow",
).deploy(  # type: ignore
    name="test",
    work_pool_name="local",
    job_variables=dict(env=dict(some_secret="{{ prefect.blocks.secret.very-secret }}")),
)
where i've created one secret named
very-secret
assigned to
value
g
incredible, that did it. Thank you @Nate would it work to use this same syntax in the work pool Environment Variables?
n
would it work to use this same syntax in the work pool Environment Variables?
hm im not sure i know what you mean, but all
job_variables
for a given work pool are jinja template-able from block / variables like this. the above overrides the
env
job variable for this deployment specifically, but you can alter the whole template in the advanced tab of the work pool to apply defaults to all deployments using this work pool docs on this
g
ok - I got it woking my modifying the Base Job Template. Thanks for your help!
catjam 1
343 Views