Can't get my app to read the env variable

My app requires an openai api key. I set the key using the secrets command and verified that it is in the environment from the console but the app does not see it. The app works fine locally using the same env variable to get the api key. I forgot the key when I first deployed so I restarted the app after setting it in case that was an issue. Any hints or thoughts?

Is your app reading the secret at runtime or at build? Secrets are injected at runtime, if you need them to be available at build, check Build Secrets.

I’m using system.get_env() locally at runtime but I have wondered if the docker image can use that to access fly secrets?

No, your Docker image won’t be able to read the secrets set through fly secrets, as they are only available at runtime. I think Build Secrets · Fly Docs is what you are looking for. Have you tried that approach?

It was a runtime issue but not on the fly side. Copied setup code from config.exs to runtime.exs and now it picks up env from fly secrets as expected. Thanks for the hint!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.