Deploying for the first time - environment variable DATABASE_URL is missing

Hi I’m deploying someone else’s elixir/phoenix code (GitHub - algora-io/tv: Open source Twitch for developers) and it already had a toml file, which I tweaked.

I did fly launch and I got this error:

environment variable DATABASE_URL is missing

I have a .env file with the DATABASE_URL set. how do I inject into the runtime environment?

Regards,

Error release_command failed running on machine e824503a7e7178 with exit code 1.
Check its logs: here's the last 100 lines below, or run 'fly logs -i e824503a7e7178':
  Pulling container image registry.fly.io/ca-sidha-teevee:deployment-01HZGGXAVCEJRR549WRDWJXN9H
  Successfully prepared image registry.fly.io/ca-sidha-teevee:deployment-01HZGGXAVCEJRR549WRDWJXN9H (26.130196034s)
  Configuring firecracker
  2024-06-04T02:32:10.012102490 [01HZGHD2Q9E4YNE0J517B4R771:main] Running Firecracker v1.7.0
  [    0.038635] Spectre V2 : WARNING: Unprivileged eBPF is enabled with eIBRS on, data leaks possible via Spectre v2 BHB attacks!
  [    0.042699] PCI: Fatal: No config space access function found
   INFO Starting init (commit: d772ddd9)...
   INFO Preparing to run: `/app/bin/migrate` as nobody
   INFO [fly api proxy] listening at /.fly/api
  2024/06/04 02:32:10 INFO SSH listening listen_address=[fdaa:0:3adb:a7b:234:1623:ad45:2]:22 dns_server=[fdaa::3]:53
  Machine created and started in 27.925s
  ERROR! Config provider Config.Reader failed with:
  ** (RuntimeError) environment variable DATABASE_URL is missing.
  For example: ecto://USER:PASS@HOST/DATABASE
      /app/releases/0.1.0/runtime.exs:24: (file)
      (elixir 1.15.7) src/elixir.erl:396: :elixir.eval_external_handler/3
      (stdlib 5.2) erl_eval.erl:750: :erl_eval.do_apply/7
      (stdlib 5.2) erl_eval.erl:494: :erl_eval.expr/6
      (stdlib 5.2) erl_eval.erl:136: :erl_eval.exprs/6
      (elixir 1.15.7) src/elixir.erl:375: :elixir.eval_forms/4
      (elixir 1.15.7) lib/module/parallel_checker.ex:112: Module.ParallelChecker.verify/1
      (elixir 1.15.7) lib/code.ex:543: Code.validated_eval_string/3

Maybe you haven’t set the variable.

You can do it with the cli like this:

fly secrets set DATABASE_URL=<database_url> --stage

And then you can deploy and it will be set.

You can find more info here: Secrets and Fly Apps · Fly Docs

1 Like

Thanks!

So I’m looking into the code further and my question is the reason the app doesn’t have a DATABASE_URL is because it’s configured to use the fly_postgres hex package so that it is in a primary/replica configuration? How do I configure my fly app to use a primary/replica configuration?

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