fly launch - no more db and secret setup

Trying out fly for the first time (trying this once I saw https://twitter.com/chris_mccord/status/1468998944009166849)

Running a Phoenix app 1.6.5, Elixir 1.13.1, flyctl version 0.0.271

When I run fly launch I get an error saying database url is not set up. Which makes sense but I thought that would be part of the setup - database and secret key base.

Did something change so that those are not part of setup anymore? Would make it nice for first time users. Otherwise, looks like I’d have to go through manual database creation, attaching, etc.??

Can you paste the output of the command?

➜ flyctl launch
Creating app in /Users/kblake/Projects/alliance/alliance_app
Scanning source code
Detected a Dockerfile app
? App Name (leave blank to use an auto-generated name): allianceimports-app
Automatically selected personal organization: Karmen Blake
? Select region: sea (Seattle, Washington (US))
Created app allianceimports-app in organization personal
Wrote config file fly.toml
? Would you like to deploy now? Yes
Deploying allianceimports-app
==> Validating app configuration
→ Validating app configuration done
Services
TCP 80/443 ⇢ 8080
Remote builder fly-builder-patient-sun-1671 ready
==> Creating build context
→ Creating build context done
==> Building image with Docker
→ docker host: 20.10.12 linux x86_64
[+] Building 4.1s (0/1)
[+] Building 111.1s (28/28) FINISHED
=> [internal] load remote build context 0.0s
=> copy /context / 0.5s
=> [internal] load metadata for docker.io/library/debian:bullseye-20210902-slim 1.5s
=> [internal] load metadata for docker.io/hexpm/elixir:1.13.1-erlang-24.2-debian-bullseye-20210902-slim 1.5s
=> [stage-1 1/6] FROM docker.io/library/debian:bullseye-20210902-slim@sha256:e3ed4be20c22a1358020358331d177aa2860632f25b21681d79204ace20455a6 1.3s
=> => resolve docker.io/library/debian:bullseye-20210902-slim@sha256:e3ed4be20c22a1358020358331d177aa2860632f25b21681d79204ace20455a6 0.0s
=> => sha256:f8416d8bac72cefc0ce17bd2dc0c03aa43e123d309db92ee23be9382192cf2ed 31.37MB / 31.37MB 0.3s
=> => sha256:e3ed4be20c22a1358020358331d177aa2860632f25b21681d79204ace20455a6 1.85kB / 1.85kB 0.0s
=> => sha256:8aa2e47f9a6cf001ecf3ad0f8439e1005743a3024b98e7bbf023ace55afea903 529B / 529B 0.0s
=> => sha256:7beb0248fd8163ea6effdf58af3e836c47f2f97d7e44e5109c95333c92190a48 1.46kB / 1.46kB 0.0s
=> => extracting sha256:f8416d8bac72cefc0ce17bd2dc0c03aa43e123d309db92ee23be9382192cf2ed 108.6s
=> [builder 1/17] FROM docker.io/hexpm/elixir:1.13.1-erlang-24.2-debian-bullseye-20210902-slim@sha256:ba2e50ad59370fab4a63a3751dc867ee45074e5f5201d8b612706d07e6e3e8ba 2.5s
=> => resolve docker.io/hexpm/elixir:1.13.1-erlang-24.2-debian-bullseye-20210902-slim@sha256:ba2e50ad59370fab4a63a3751dc867ee45074e5f5201d8b612706d07e6e3e8ba 0.0s
=> => sha256:ba2e50ad59370fab4a63a3751dc867ee45074e5f5201d8b612706d07e6e3e8ba 772B / 772B 0.0s
=> => sha256:5ba4c217868f67019b1923fb6a13bdbd2f9e6b7f776f6cbfd700169b23663e4e 1.16kB / 1.16kB 0.0s
=> => sha256:77bd17eb5f51fe2ca631aaa080eedb669b4687cc245260ad0d077d414cc7c488 2.33kB / 2.33kB 0.0s
=> => sha256:f8416d8bac72cefc0ce17bd2dc0c03aa43e123d309db92ee23be9382192cf2ed 31.37MB / 31.37MB 0.3s
=> => sha256:a659df3269b5142e96f5a964ca5371ff6fcd69e375e48efdd5d6ebe162bbbda4 14.23MB / 14.23MB 0.3s
=> => sha256:28706ae06fb891d71029d814677bdb71c16ef2a54e3b983fcac5b9fe9cd21785 43.70MB / 43.70MB 0.7s
=> => sha256:cb06f6e303316a8aa2edec64a3b5a8b516e83856aa06cd85fee89985c972217b 5.04MB / 5.04MB 0.6s
=> => extracting sha256:f8416d8bac72cefc0ce17bd2dc0c03aa43e123d309db92ee23be9382192cf2ed 0.9s
=> => extracting sha256:a659df3269b5142e96f5a964ca5371ff6fcd69e375e48efdd5d6ebe162bbbda4 0.2s
=> => extracting sha256:28706ae06fb891d71029d814677bdb71c16ef2a54e3b983fcac5b9fe9cd21785 0.6s
=> => extracting sha256:cb06f6e303316a8aa2edec64a3b5a8b516e83856aa06cd85fee89985c972217b 0.2s
=> [stage-1 2/6] RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales && apt-get clean && rm -f /var/lib/apt/lists/_ 6.4s
=> [builder 2/17] RUN apt-get update -y && apt-get install -y build-essential git nodejs npm && apt-get clean && rm -f /var/lib/apt/lists/_ 55.1s
=> [stage-1 3/6] RUN sed -i ‘/en_US.UTF-8/s/^# //g’ /etc/locale.gen && locale-gen 1.7s
=> [stage-1 4/6] WORKDIR /app 0.0s
=> [stage-1 5/6] RUN chown nobody /app 0.4s
=> [builder 3/17] WORKDIR /app 0.0s
=> [builder 4/17] RUN mix local.hex --force && mix local.rebar --force 1.8s
=> [builder 5/17] COPY mix.exs mix.lock ./ 0.0s
=> [builder 6/17] RUN mix deps.get --only prod 1.6s
=> [builder 7/17] RUN mkdir config 0.3s
=> [builder 8/17] COPY config/config.exs config/prod.exs config/ 0.0s
=> [builder 9/17] RUN mix deps.compile 39.6s
=> [builder 10/17] COPY priv priv 0.0s
=> [builder 11/17] COPY assets assets 0.2s
=> [builder 12/17] RUN mix assets.deploy 3.1s
=> [builder 13/17] COPY lib lib 0.0s
=> [builder 14/17] RUN mix compile 2.1s
=> [builder 15/17] COPY config/runtime.exs config/ 0.0s
=> [builder 16/17] COPY rel rel 0.0s
=> [builder 17/17] RUN mix release 2.0s
=> [stage-1 6/6] COPY --from=builder --chown=nobody:root /app/_build/prod/rel/alliance_app ./ 0.2s
=> exporting to image 0.2s
=> => exporting layers 0.2s
=> => writing image sha256:967d1b32d6506e94fe1fa39de39000e0e97fee8ce3c5ccc91e3e88bf8d80cc61 0.0s
=> => naming to registry.fly.io/allianceimports-app:deployment-1640646069 0.0s
→ Building image done
==> Pushing image to fly
The push refers to repository [registry.fly.io/allianceimports-app]
83277403b7e4: Pushed
ca8198e34183: Pushed
278fe8d8d3c3: Pushed
c7abf3171420: Pushed
094257640238: Pushed
ba5a5fe43301: Pushed
deployment-1640646069: digest: sha256:c519d5e7558af53704d7666ec1de5bfabe27248c88a80480d7e51866bc7e0180 size: 1576
→ Pushing image done
Image: registry.fly.io/allianceimports-app:deployment-1640646069
Image size: 118 MB
==> Creating release
Release v2 created

You can detach the terminal anytime without stopping the deployment
Monitoring Deployment

1 desired, 1 placed, 0 healthy, 1 unhealthy [restarts: 2] [health checks: 1 total]
v0 failed - Failed due to unhealthy allocations - no stable job version to auto revert to
Failed Instances

==> Failure #1

Instance
ID = e7a9c870
Process =
Version = 0
Region = sea
Desired = run
Status = running
Health Checks = 1 total
Restarts = 2
Created = 23s ago

Recent Events
TIMESTAMP TYPE MESSAGE
2021-12-27T23:03:34Z Received Task received by client
2021-12-27T23:03:34Z Task Setup Building Task Directory
2021-12-27T23:03:39Z Started Task started by client
2021-12-27T23:03:43Z Terminated Exit Code: 1
2021-12-27T23:03:43Z Restarting Task restarting in 1.125407364s
2021-12-27T23:03:50Z Started Task started by client
2021-12-27T23:03:54Z Terminated Exit Code: 1
2021-12-27T23:03:54Z Restarting Task restarting in 1.010726733s
2021-12-27T23:04:00Z Started Task started by client

Recent Logs
2021-12-27T23:03:53.000 [info] Reaped child process with pid: 567 and signal: SIGUSR1, core dumped? false
2021-12-27T23:03:53.000 [info] Starting clean up.
2021-12-27T23:03:59.000 [info] Starting instance
2021-12-27T23:03:59.000 [info] Configuring virtual machine
2021-12-27T23:03:59.000 [info] Pulling container image
2021-12-27T23:03:59.000 [info] Unpacking image
2021-12-27T23:03:59.000 [info] Preparing kernel init
2021-12-27T23:04:00.000 [info] Configuring firecracker
2021-12-27T23:04:00.000 [info] Starting virtual machine
2021-12-27T23:04:00.000 [info] Starting init (commit: 7943db6)…
2021-12-27T23:04:00.000 [info] Preparing to run: /bin/sh -c /app/bin/server as nobody
2021-12-27T23:04:00.000 [info] 2021/12/27 23:04:00 listening on [fdaa:0:414e:a7b:ac4:e7a9:c870:2]:22 (DNS: [fdaa::3]:53)
2021-12-27T23:04:01.000 [info] Reaped child process with pid: 546, exit code: 0
2021-12-27T23:04:02.000 [info] ERROR! Config provider Config.Reader failed with:
2021-12-27T23:04:02.000 [info] ** (RuntimeError) environment variable DATABASE_URL is missing.
2021-12-27T23:04:02.000 [info] For example: ecto://USER:PASS@HOST/DATABASE
2021-12-27T23:04:02.000 [info] (stdlib 3.17) erl_eval.erl:685: :erl_eval.do_apply/6
2021-12-27T23:04:02.000 [info] (stdlib 3.17) erl_eval.erl:446: :erl_eval.expr/5
2021-12-27T23:04:02.000 [info] (stdlib 3.17) erl_eval.erl:123: :erl_eval.exprs/5
2021-12-27T23:04:02.000 [info] (elixir 1.13.1) src/elixir.erl:289: :elixir.recur_eval/3
2021-12-27T23:04:02.000 [info] (elixir 1.13.1) src/elixir.erl:274: :elixir.eval_forms/3
2021-12-27T23:04:02.000 [info] (elixir 1.13.1) lib/code.ex:404: Code.validated_eval_string/3
2021-12-27T23:04:02.000 [info] (elixir 1.13.1) lib/config.ex:260: Config.eval!/3
2021-12-27T23:04:02.000 [info] (elixir 1.13.1) lib/config/reader.ex:92: Config.Reader.read!/2
2021-12-27T23:04:02.000 [info] ininit 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,289}]},{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}]}]}}
nit terminating in do_boot ({,[{erl_eval,do_apply,6,[{},{},{}]},{erl_eval,expr,5,[{},{}]},{erl_eval,exprs,5,[{},{}]},{elixir,recur_eval,3,[{},{}]},{elixir,eval_forms,3,[{},{}]},{Elixir.Code,validated_eval_string,3,[{},{}]},{Elixir.Config,eval!,3,[{},{}]},{Elixir.Config.Reader,read!,2,[{},{_}]}]})
2021-12-27T23:04:02.000 [info] Crash dump is being written to: erl_crash.dump…done
2021-12-27T23:04:03.000 [info] Main child exited normally with code: 1
2021-12-27T23:04:03.000 [info] Reaped child process with pid: 567 and signal: SIGUSR1, core dumped? false
2021-12-27T23:04:03.000 [info] Starting clean up.
***v0 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v1

Troubleshooting guide at Troubleshooting your Deployment
Error abort

Thanks. It looks like this happened because you already had a Dockerfile in your source. If we see that, we’ll skip detecting the framework you’re using and thus all the good things that come with that.

Did you add the Dockerfile or generate it with mix gen.release --docker?

The quickest solution here would be to remove the app and start over with the Dockerfile removed or renamed.

1 Like

I did do the release --docker thing before so that makes sense why I was seeing something different. Deleted Dockerfile and fly.toml and ran fly launch again… new error though… (password hidden)


➜ fly launch
Creating app in /Users/kblake/Projects/alliance/alliance_app
Scanning source code
Detected a Phoenix app
? App Name (leave blank to use an auto-generated name): alliance-imports-app
Automatically selected personal organization: Karmen Blake
? Select region: sea (Seattle, Washington (US))
Created app alliance-imports-app in organization personal
Set secrets on alliance-imports-app: SECRET_KEY_BASE
Preparing system for Elixir builds
Installing application dependencies
Running Docker release generator
Wrote config file fly.toml
? Would you like to setup a Postgres database now? Yes
Postgres cluster alliance-imports-app-db created
Username: postgres
Password: …
Hostname: alliance-imports-app-db.internal
Proxy Port: 5432
PG Port: 5433
Save your credentials in a secure place, you won’t be able to see them again!

Monitoring Deployment

1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 2 total, 2 passing]
→ v0 deployed successfully

Connect to postgres
Any app within the personal organization can connect to postgres using the above credentials and the hostname “alliance-imports-app-db.internal.”
For example: …

See the postgres docs for more information on next steps, managing postgres, connecting from outside fly: Postgres on Fly
Error error connecting to postgres: failed to connect to host=alliance-imports-app-db.internal user=flypgadmin database=postgres: hostname resolving error (lookup alliance-imports-app-db.internal on [fdaa::3]:53: no such host)

Maybe a race condition where db instance wasn’t ready before app instance was ready to use it. I subsequently ran fly launch again and it went through.

Went and check its public availability and it’s there. So far so good now!

Thanks for your tips @joshua

Yep, you’re right about the race condition. This is an attempt to run postgres attach which would generate credentials specifically for this app, and set DATABASE_URL.

While you could run attach again, you can still connect with the credentials you saw during the deployment, and it sounds like that’s what you did. Glad to hear it worked out!

It might be interesting for us to detect frameworks even when Dockerfile is present. In that case, you’d be prompted to overwrite it, so it feels safe to me.