Accessing Autoset ENV Variables

I just setup a new Nodejs app with a Postgres db. The launch was nice and took care of the environment variables for me, but now I need to access them so I can set the proper ENV variables on my app, as it uses DATABASE_NAME, DATABASE_PASSWORD and not the DATABASE_URL fly.io automatically setup. This is for strapi installation.

The app cannot load because it can’t connect to the database, so I cannot console in to echo the variables.

Is the solution to set the ENV vars myself on the building of the app? If so how I can do that? Thanks!

Multiple ways to do so:

  1. Set env in Dockerfile: Docker ARG, ENV and .env - a Complete Guide · vsupalov.com
  2. Set env in fly.toml: Fly Launch configuration (fly.toml) · Fly Docs
  3. Set env at runtime with secrets: Secrets and Fly Apps · Fly Docs

In case you want to, sleep for inf from your entrypoint, and you should then be able to ssh into the VM to inspect it: Is there a way to disable health checks? - #9 by kurt

1 Like

Thank you @ignoramous - as for the setting the environment variables I need to set them on the database server not on the regular server, and it seems like the 3 strategies laid out won’t let me set the database server’s ENV vars. Maybe the help I really need here is how to change my default flyctl project from the app I’m developing and onto the database server that fly generated for me.

In case you want to, sleep for inf from your entrypoint , and you should then be able to ssh into the VM to inspect it: Is there a way to disable health checks? - #9 by kurt

Can you explain more about what you mean? What entrypoint file, if I’m not using docker, where would this ‘sleep’ be added onto? Sadly that link wasn’t very helpful there.

Thanks!
Cameron

Good news! I found a way to get the ENV variables on the database!
Using fly pg dettach and then fly pg attach onto my database application it displays the DATABASE_URL that was auto generated (that my app doesn’t use).

Hope this helps someone else!

1 Like