Phoenix deployments (for Gigalixir): problems with ENV variables

I’m following along with the instructions for converting an existing app as I prepare to launch a simple Phoenix app on Gigalixir:

I’ve noticed that the config files do not pick up environment variables as expected:

config :hello, Hello.Repo,
       adapter: Ecto.Adapters.Postgres,
#       url: "${DATABASE_URL}", # <--- this does not!
       url: System.get_env("DATABASE_URL"), # <-- this works!
       database: "",
       ssl: false,
       pool_size: 2 # Free tier db only allows 4 connections. Rolling deploys need pool_size*(n+1) connections.

Then doing a test of the setup via this bash command:

SECRET_KEY_BASE="$(mix phx.gen.secret)" MIX_ENV=prod DATABASE_URL="postgresql://uuuuuu:ppppppp@localhost:5432/hello" PORT=4000 mix phx.server

"${DATABASE_URL}" does not work. I kept getting errors:

** (Ecto.InvalidURLError) invalid url ${DATABASE_URL}, host is not present

System.get_env("DATABASE_URL") worked as expected.

Anyone else run into this? And why is this the case?

You are using the mix based deployment, this requires the usage of System.get_env/1. The other syntax is for distillery based deployments.

But today with distillery 2, using a config provider might be even better.

1 Like