Failing to deploy Phoenix speedrun

Hi there,
I am stoked to try fly.io, yet have been failing with Phoenix speedrun. Sorry for noob question, but no luck in getting it running :sob:

  • I am on Elixir 1.13.3, Phoenix 1.6.6, flyctl v0.0.313
  • I am creating a barebones Phoenix app as described here Deploy an Elixir Phoenix Application and it runs locally on my machine just fine
  • On the first run of flyctl launch and selecting the PG, I get an error - something like can't access https://api.fly.io/graphql: unexpected EOF
  • I tried running flyctl launchagain and then I always get
ERROR! Config provider Config.Reader failed with:
	 ** (RuntimeError) environment variable DATABASE_URL is missing.
	 For example: ecto://USER:PASS@HOST/DATABASE
	     (stdlib 3.17.1) erl_eval.erl:685: :erl_eval.do_apply/6
	     (elixir 1.13.3) src/elixir.erl:296: :elixir.recur_eval/3
	     (elixir 1.13.3) src/elixir.erl:274: :elixir.eval_forms/3
	     (elixir 1.13.3) lib/config.ex:260: Config.__eval__!/3
	     (elixir 1.13.3) lib/config/reader.ex:92: Config.Reader.read!/2
	 {"init terminating in do_boot",{#{'__exception__'=>true,'__struct__'=>'Elixir.RuntimeError',message=><<101,110,118,105,114,111,110,109,101,110,116,32,118,97,114,105,97,98,108,101,32,68,65,84,65,66,65,83,69,95,85,82,76,32,105,115,32,109,105,115,115,105,110,103,46,10,70,111,114,32,101,120,97,109,112,108,101,58,32,101,99,116,111,58,47,47,85,83,69,82,58,80,65,83,83,64,72,79,83,84,47,68,65,84,65,66,65,83,69,10>>},[{erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,685},{error_info,#{module=>'Elixir.Exception'}}]},{erl_eval,expr,5,[{file,"erl_eval.erl"},{line,446}]},{erl_eval,exprs,5,[{file,"erl_eval.erl"},{line,123}]},{elixir,recur_eval,3,[{file,"src/elixir.erl"},{line,296}]},{elixir,eval_forms,3,[{file,"src/elixir.erl"},{line,274}]},{'Elixir.Code',validated_eval_string,3,[{file,"lib/code.ex"},{line,404}]},{'Elixir.Config','__eval__!',3,[{file,"lib/config.ex"},{line,260}]},{'Elixir.Config.Reader','read!',2,[{file,"lib/config/reader.ex"},{line,92}]}]}}
  • Not sure if that’s helpful, but I have notices that after the first error my apps’s name hello-elixir-fresh is not being showed anymore in Sign In · Fly and I only see some builder fly-builder-wild-pine-194.

Any help? Thanks a lot in advance!

Hey what version of Phoenix are you using?

Looking at the error message you posted it’s likely that your Phoenix might be outdated.
** (RuntimeError) environment variable DATABASE_URL is missing.

fly launch sets a SECRET_KEY_BASE for you if you’re using Phoenix > 1.6.3. For earlier versions of Phoenix, you will need to manually set DATABASE_URL

Hey I just re-read and saw that you have Phoenix 1.6.6 version.

Your app is breaking because the postgres attach process broke, you will need to either delete the app and start from scratch, or run fly pg attach command

hey, thanks for your help and in the end it worked out :sweat_smile:

but just FYI yesterday I have started from scratch multiple times to no avail. fly pg attach also didn’t help.
then weirdly this morning I tried 2 more times to start from scratch and it could create pg, but then errored at something else:

--> v0 deployed successfully

...

See the postgres docs for more information on next steps, managing postgres, connecting from outside fly: https://fly.io/docs/reference/postgres/

Running flyadmin database-list

Running flyadmin user-list

Running flyadmin database-create

Error Failed attaching autumn-frost-1869-db to the Postgres cluster autumn-frost-1869: unexpected end of JSON input.\nTry attaching manually with 'fly postgres attach --app autumn-frost-1869 --postgres-app autumn-frost-1869-db'

vs@vss-MacBook-Air new_day % fly postgres attach --app autumn-frost-1869 --postgres-app autumn-frost-1869-db

Running flyadmin database-list

? Database "autumn_frost_1869" already exists. Continue with the attachment process? Yes

Running flyadmin user-list

Running flyadmin user-create

Error unexpected end of JSON input

vs@vss-MacBook-Air new_day % fly pg attach

Error get app: Could not resolve App

vs@vss-MacBook-Air new_day % fly postgres attach --app autumn-frost-1869 --postgres-app autumn-frost-1869-db

Running flyadmin database-list

Error unexpected end of JSON input

vs@vss-MacBook-Air new_day % fly postgres attach --app autumn-frost-1869 --postgres-app autumn-frost-1869-db

Running flyadmin database-list

? Database "autumn_frost_1869" already exists. Continue with the attachment process? Yes

Running flyadmin user-list

Error Database user "autumn_frost_1869" already exists. Please specify a new database user via --database-user

then after some time and started from scratch again and it worked, so all good for now. but would be good to understand what was off. I suppose something on fly’s side as I went through exactly the same movements on my machine.

1 Like