g

    Geoffrey Gross

    2 years ago
    Hey everyone got a question. I am currently working on building a flow via the
    Docker
    storage class. Right now my flow imports env vars from a
    config.py
    , found in the same directory with the file that holds my flow, which uses
    os.environ
    . I would like to set those environment variables at run time but when, the healtchecks run and deserialize my flow in the docker build step, it is trying to evaluate those environment variables. This causes an error since I don't have defaults set. Does anyone have any ideas of have to handle this without ignoring healthchecks and putting environment variables into the Dockerfile that gets generated?
    Dylan

    Dylan

    2 years ago
    Hi @Geoffrey Gross! Are those environment variables secrets? If so you might try using the Secrets feature instead:https://docs.prefect.io/core/concepts/secrets.html#overview
    Since the flow will load the secrets as part of runtime
    g

    Geoffrey Gross

    2 years ago
    Some of them are. But I guess, I like to not hard code them into the Dockerfile even if they aren't secrets. I like having python throw an error when it can't find an environment variable where a default variable wouldn't be acceptable in different environments (local, dev, stage, prod). I am already reading in secrets that way. I guess I could move more env vars into a Secret object.
    So I fetch some envars with os.getenv and set a default and some with os.environ that throw an error when the variable isn't set.
    Dylan

    Dylan

    2 years ago
    That definitely makes sense to me
    Let me take your primary question back to the team
    g

    Geoffrey Gross

    2 years ago
    Okay. Thanks!
    Dylan

    Dylan

    2 years ago
    But I’ll also add that there are a couple of different ways to get configuration into your Prefect flow
    g

    Geoffrey Gross

    2 years ago
    I'll check this out.
    Dylan

    Dylan

    2 years ago
    Although that configuration link is probably not what you’re looking for, my apologies edit: it is in conjunction to the other article, so 👍
    g

    Geoffrey Gross

    2 years ago
    I should also mention that some of my env vars are used to set defaults for Parameters. I guess if there was/is a way to have Parameters read default values from the environment that could solve my issue.
    Gotcha
    Actually I guess I could have a task that reads in my env vars couldn't I? That would solve everything
    And then it could set env vars onto the context.