Following `fly launch` guide for elixir fails

In preparation for launching a real app, I’m trying to follow this guide. Getting Started · Fly Docs

After selecting a location, the fly launch command fails with…

? Choose a region for deployment: Los Angeles, California (US) (lax)
...
Preparing system for Elixir builds
Installing application dependencies
Running Docker release generator
Error failed running /Users/someuser/.asdf/shims/mix phx.gen.release --docker: exit status 1 

Running mix phx.gen.release --docker locally yields this output:

21:57:02.326 [debug] Fetching latest image information from https://hub.docker.com/v2/namespaces/hexpm/repositories/elixir/tags?name=1.14.0-erlang-25.0.3-debian-bullseye-
** (UndefinedFunctionError) function CAStore.file_path/0 is undefined (module CAStore is not available)
    CAStore.file_path()
    lib/mix/tasks/phx.gen.release.ex:253: Mix.Tasks.Phx.Gen.Release.fetch_body!/1
    lib/mix/tasks/phx.gen.release.ex:200: Mix.Tasks.Phx.Gen.Release.gen_docker/1
    lib/mix/tasks/phx.gen.release.ex:76: Mix.Tasks.Phx.Gen.Release.run/1
    (mix 1.14.0) lib/mix/task.ex:421: anonymous fn/3 in Mix.Task.run_task/4
    (mix 1.14.0) lib/mix/cli.ex:84: Mix.CLI.run_task/2

I’ve tried adding castore directly to my deps in mix.exs. I’ve tried cleaning deps, etc. to no avail.

This is a fresh mix phx.new hello_elixir for 1.7.2 Phoenix. Any thoughts?

MacOS - elixir, erlang via asdf…

I just did a fly version update and made sure I had the latest phx_new mix archive.install hex phx_new generated a new app and fly launched and it’s good first try for me.

I think this issue happens if you have an older phx rc generator lying around? Though I can’t be sure.

an older phx rc generator lying around?

Any idea how to check if I have one lying around and how to purge it out?

I’ll try the fly version update as well.

if you do mix archive.install hex phx_new it will replace it. Can also check your mix.exs for older versions.

Actually, it worked, up to a point…

fly launch worked all the way through the process, DB, redis, etc. until…

Preparing system for Elixir builds
Installing application dependencies
Running Docker release generator
Error failed running /Users/kenbarker/.asdf/shims/mix phx.gen.release --docker: exit status 1 

painlesspm/hello_elixir

Any further ideas?

Running mix phx.gen.release --docker locally produces…

painlesspm/hello_elixir ~ mix phx.gen.release --docker
* creating rel/overlays/bin/server
* creating rel/overlays/bin/server.bat
* creating rel/overlays/bin/migrate
* creating rel/overlays/bin/migrate.bat
* creating lib/hello_elixir/release.ex

22:18:01.799 [debug] Fetching latest image information from https://hub.docker.com/v2/namespaces/hexpm/repositories/elixir/tags?name=1.14.0-erlang-25.0.3-debian-bullseye-
** (UndefinedFunctionError) function CAStore.file_path/0 is undefined (module CAStore is not available)
    CAStore.file_path()
    lib/mix/tasks/phx.gen.release.ex:253: Mix.Tasks.Phx.Gen.Release.fetch_body!/1
    lib/mix/tasks/phx.gen.release.ex:200: Mix.Tasks.Phx.Gen.Release.gen_docker/1
    lib/mix/tasks/phx.gen.release.ex:76: Mix.Tasks.Phx.Gen.Release.run/1
    (mix 1.14.0) lib/mix/task.ex:421: anonymous fn/3 in Mix.Task.run_task/4
    (mix 1.14.0) lib/mix/cli.ex:84: Mix.CLI.run_task/2

Can you share the code maybe?

Thanks! Yes. Here’s a repo. GitHub - kEND/hello_elixir

So I just tried this with fly launch and it worked.

It looks like maybe you’re building it locally and having troubles, try the remote builder with flyctl launch --remote-only

hello_elixir (kb: main) ~ flyctl launch --remote-only


Creating app in /Users/kenbarker/projects/kbc/current-painless/painlesspm/hello_elixir
Scanning source code
Resolving Hex dependencies...
Resolution completed in 0.091s
Unchanged:
  castore 1.0.1
  connection 1.1.0
  cowboy 2.9.0
  cowboy_telemetry 0.4.0
  cowlib 2.11.0
  db_connection 2.4.3
  decimal 2.0.0
  ecto 3.9.5
  ecto_sql 3.9.2
  esbuild 0.7.0
  expo 0.4.0
  file_system 0.2.10
  finch 0.15.0
  floki 0.34.2
  gettext 0.22.1
  hpax 0.1.2
  jason 1.4.0
  mime 2.0.3
  mint 1.5.1
  nimble_options 1.0.1
  nimble_pool 0.2.6
  phoenix 1.7.2
  phoenix_ecto 4.4.0
  phoenix_html 3.3.1
  phoenix_live_dashboard 0.7.2
  phoenix_live_reload 1.4.1
  phoenix_live_view 0.18.18
  phoenix_pubsub 2.1.1
  phoenix_template 1.0.1
  plug 1.14.2
  plug_cowboy 2.6.1
  plug_crypto 1.2.5
  postgrex 0.16.5
  ranch 1.8.0
  swoosh 1.9.1
  tailwind 0.2.0
  telemetry 1.2.1
  telemetry_metrics 0.6.1
  telemetry_poller 1.0.0
  websock 0.5.0
  websock_adapter 0.5.0
All dependencies are up to date
[error] Postgrex.Protocol (#PID<0.634.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "hello_elixir_dev" does not exist
[error] Postgrex.Protocol (#PID<0.626.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "hello_elixir_dev" does not exist
[error] Postgrex.Protocol (#PID<0.628.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "hello_elixir_dev" does not exist
[error] Postgrex.Protocol (#PID<0.629.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "hello_elixir_dev" does not exist
[error] Postgrex.Protocol (#PID<0.631.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "hello_elixir_dev" does not exist
[error] Postgrex.Protocol (#PID<0.633.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "hello_elixir_dev" does not exist
[error] Postgrex.Protocol (#PID<0.627.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "hello_elixir_dev" does not exist
[error] Postgrex.Protocol (#PID<0.635.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "hello_elixir_dev" does not exist
[error] Postgrex.Protocol (#PID<0.630.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "hello_elixir_dev" does not exist
[error] Postgrex.Protocol (#PID<0.632.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "hello_elixir_dev" does not exist
[info] Configuration :server was not enabled for HelloElixirWeb.Endpoint, http/https services won't start
Detected a Phoenix app
? Choose an app name (leave blank to generate one): 
automatically selected personal organization: ken.barker@gmail.com
Some regions require a paid plan (fra, maa).
See https://fly.io/plans to set up a plan.

? Choose a region for deployment: Los Angeles, California (US) (lax)
Created app 'cold-sound-1161' in organization 'personal'
Admin URL: https://fly.io/apps/cold-sound-1161
Hostname: cold-sound-1161.fly.dev
Set secrets on cold-sound-1161: SECRET_KEY_BASE
? Would you like to set up a Postgresql database now? No
? Would you like to set up an Upstash Redis database now? No
Preparing system for Elixir builds
Installing application dependencies
Running Docker release generator
Error failed running /Users/kenbarker/.asdf/shims/mix phx.gen.release --docker: exit status 1 

I tried the --remote-only switch. No joy. Any other ideas?

It looks like there might be an issue with your ASDF setup. Can you run other mix commands? Maybe share your Elixir/Erlang Version as well?

Jason, this helped, but still ran into an issue further through the process. I had not yet set my .tool-versions for this project (:man_facepalming:) I set up a .tool-versions with my latest versions,

erlang 25.3
elixir 1.14.3-otp-25

and retried fly launch --remote-only and got much further…

==> Creating release
--> release v2 created

--> You can detach the terminal anytime without stopping the deployment
==> Release command detected: /app/bin/migrate

--> This release will not be available until the release command succeeds.
	 Starting instance
	 Configuring virtual machine
	 Pulling container image
	 Unpacking image
	 Preparing kernel init
	 Configuring firecracker
	 Starting virtual machine
	 Starting init (commit: 9e69c24)...
	 Preparing to run: `/app/bin/migrate` as nobody
	 2023/04/07 02:41:47 listening on [fdaa:0:534f:a7b:112:c89d:b98c:2]:22 (DNS: [fdaa::3]:53)
	     (stdlib 4.3) erl_eval.erl:748: :erl_eval.do_apply/7
	     (stdlib 4.3) erl_eval.erl:492: :erl_eval.expr/6
	     (stdlib 4.3) erl_eval.erl:136: :erl_eval.exprs/6
	     (elixir 1.14.3) src/elixir.erl:294: :elixir.eval_forms/4
	     (elixir 1.14.3) lib/module/parallel_checker.ex:110: Module.ParallelChecker.verify/1
	     (elixir 1.14.3) lib/code.ex:425: Code.validated_eval_string/3
	 init terminating in do_boot ({,[{elixir_eval,__FILE__,1,[{_},{_}]},{elixir,-eval_external_handler/1-fun-2-,4,[{_},{_},{_}]},{erl_eval,do_apply,7,[{_},{_}]},{erl_eval,expr,6,[{_},{_}]},{erl_eval,exprs,6,[{_},{_}]},{elixir,eval_forms,4,[{_},{_}]},{Elixir.Module.ParallelChecker,verify,1,[{_},{_}]},{Elixir.Code,validated_eval_string,3,[{_},{_}]}]})
	 Crash dump is being written to: erl_crash.dump...done
	 Starting clean up.
Error release command failed, deployment aborted
1 Like

Any further thoughts on this…

Alright so re-reviewing this thread I’m noticing a couple issues:

  • You repo has postgres setup but you haven’t added postgres to your fly setup. The migrate is failing cause it doesn’t have a database. Delete your app and hit Y when fly launch asks if you want postgres or add a postgres setup/DATABASE_URL to the app manually
  • Remote builds didn’t fail per-say but for some reason your code is failing to connect to a database, when it should fail in runtime.exs on boot, not in Application.start. Make sure your generate Dockerfile has ENV MIX_ENV=prod line in it. You might also want to check your fly.toml for similar key.

None of this happens when I clone your repo fresh and do fly launch and hit Yes for postgres. With macos and the same erlang/elixir installed via asdf. So either you haven’t pushed up the same code (ie you have local changes) or you have a local problem I cannot reproduce…

Sorry if that’s not helpful :confused:

2 Likes

I’ll take a look. I do appreciate your help!

I’m on a clean laptop and all is working per the guide as expected.