Hello, I have a newly generated Phoenix app v1.6.10
Up until I ran the flyctl launch command, there was no Dockerfile, release.ex, or any other deployment-related files. All that to say, I’m trying to deploy a vanilla phoenix application.
Whenever I run flyctrl deploy I get the following error:
1 desired, 1 placed, 0 healthy, 1 unhealthy
--> v2 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v3
--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort
The link references a section on port checking and it says that when you deploy, you see a message like this:
TCP 80/443 ⇢ 8080
EDIT: when I run fly launch I see the TCP 80/443 → 8080 message. I do not see it when I run fly deploy
I do not see that message at all. I’m not sure how to troubleshoot this as I can’t seem to make anything out from the logs.
Fly doesn’t export PORT, but your runtime.exs will default then to 4000. Your generated fly.toml should have had:
[[services]]
...
internal_port = 4000
Which would let fly forward the default phoenix 4000 port. Can you confirm whether this line was present in your fly.toml after running fly launch? Thanks!
@kurt good to know! Now I’m wondering if there are other changes I should be making? Should I try re-generating these files by deleting them and running flyctl launch once more? Or maybe there’s not much more of a difference?
I generated a new Phoenix project yesterday on flyctl v0.0.335. Knowing about the 1.6.10 detection bug I intentionally downgraded to phx_new 1.6.9, I still ended up with a 1.6.10 Phoenix app because of optimistic versioning, while avoiding the launch bug. But I did notice that even on 1.6.9 the default internal port in fly.toml was 8080. That might be a separate issue or at least warrant a note in the docs?
The new app I just created had no PORT set in the env. On another project I had added [env] PORT = "8080" and that worked for me. On this new one I followed the LiveBeats example and changed internal_port = 4000, with nothing set for PORT in the env. That also worked. The default fly.toml seems to be incompatible with the default runtime.exs
EDIT:
Also can confirm that v0.0.336 is still missing the Phoenix 1.6.10 check, and that the default fly.toml on Phoenix apps looks like this:
I added some html, followed the tutorial to add Tailwind.
And then I ran fly launch
System information:
MacOSX latest stable version
Macbook Pro 2019 intel
Updated phoenix to 1.16.10
Didn’t create a database
Later on, tried creating with database (on the fly ctl), also didn’t work.
I suspect this is happening because of either my region (gru) and/or tailwind. So I tried creating a sample Phoenix project and just deploy it. It failed. Here’s how it went:
$ mix phx.new exemplo
Fetch and install dependencies? [Yn] Y
$ cd exemplo
$ mix ecto.create
$ fly launch
Would you like to setup a Postgresql database now? (y/N) y
(...)
We recommend upgrading to Phoenix 1.6.3 which includes a release configuration for Docker-based deployment.
$ fly launch
And then it fails.
Error message:
==> Creating release
Release v2 created
Release command detected: this new release will not be available until the command succeeds.
You can detach the terminal anytime without stopping the deployment
==> Release command
Command: /app/bin/migrate
Starting instance
Configuring virtual machine
Pulling container image
Unpacking image
Preparing kernel init
Starting virtual machine
Starting init (commit: e21acb3)...
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=d392b0bf-41f7-4fc6-85ab-a4255daa05eb
Preparing to run: `/app/bin/migrate` as nobody
2022/06/25 13:08:21 listening on [fdaa:0:71f1:a7b:1f60:18b3:4778:2]:22 (DNS: [fdaa::3]:53)
13:08:24.008 [error] Postgrex.Protocol (#PID<0.136.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (top2.nearest.of.solitary-water-4912-db.internal:5432): non-existing domain - :nxdomain
13:08:24.008 [error] Postgrex.Protocol (#PID<0.135.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (top2.nearest.of.solitary-water-4912-db.internal:5432): non-existing domain - :nxdomain
13:08:25.242 [error] Postgrex.Protocol (#PID<0.136.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (top2.nearest.of.solitary-water-4912-db.internal:5432): non-existing domain - :nxdomain
13:08:25.402 [error] Postgrex.Protocol (#PID<0.135.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (top2.nearest.of.solitary-water-4912-db.internal:5432): non-existing domain - :nxdomain
* The database does not exist
* The "schema_migrations" table, which Ecto uses for managing
migrations, was defined by another library
* There is a deadlock while migrating (such as using concurrent
To fix the first issue, run "mix ecto.create".
To address the second, you can run "mix ecto.drop" followed by
"mix ecto.create". Alternatively you may configure Ecto to use
another table and/or repository for managing migrations:
config :exemplo, Exemplo.Repo,
migration_repo: AnotherRepoForSchemaMigrations
The full error report is shown below.
2. Tracking down slow queries and making sure they are running fast enough
3. Increasing the pool_size (although this increases resource consumption)
4. Allowing requests to wait longer by increasing :queue_target and :queue_interval
(ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:932: Ecto.Adapters.SQL.raise_sql_call_error/1
(elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
(ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:1024: Ecto.Adapters.SQL.execute_ddl/4
(ecto_sql 3.8.3) lib/ecto/migrator.ex:146: Ecto.Migrator.with_repo/3
Main child exited normally with code: 1
Reaped child process with pid: 569 and signal: SIGUSR1, core dumped? false
Starting clean up.
Error Release command failed, deployment aborted
I added no code. I left private info there just to help debug.
But wow, I already put 25usd in my account just to try this service and I can’t deploy even a boilerplate.
❯ mix phx.new exemplo
* creating exemplo/config/config.exs
* creating exemplo/config/dev.exs
* creating exemplo/config/prod.exs
* creating exemplo/config/runtime.exs
* creating exemplo/config/test.exs
* creating exemplo/lib/exemplo/application.ex
* creating exemplo/lib/exemplo.ex
* creating exemplo/lib/exemplo_web/views/error_helpers.ex
* creating exemplo/lib/exemplo_web/views/error_view.ex
* creating exemplo/lib/exemplo_web/endpoint.ex
* creating exemplo/lib/exemplo_web/router.ex
* creating exemplo/lib/exemplo_web/telemetry.ex
* creating exemplo/lib/exemplo_web.ex
* creating exemplo/mix.exs
* creating exemplo/README.md
* creating exemplo/.formatter.exs
* creating exemplo/.gitignore
* creating exemplo/test/support/channel_case.ex
* creating exemplo/test/support/conn_case.ex
* creating exemplo/test/test_helper.exs
* creating exemplo/test/exemplo_web/views/error_view_test.exs
* creating exemplo/lib/exemplo/repo.ex
* creating exemplo/priv/repo/migrations/.formatter.exs
* creating exemplo/priv/repo/seeds.exs
* creating exemplo/test/support/data_case.ex
* creating exemplo/lib/exemplo_web/controllers/page_controller.ex
* creating exemplo/lib/exemplo_web/views/page_view.ex
* creating exemplo/test/exemplo_web/controllers/page_controller_test.exs
* creating exemplo/test/exemplo_web/views/page_view_test.exs
* creating exemplo/assets/vendor/topbar.js
* creating exemplo/lib/exemplo_web/templates/layout/root.html.heex
* creating exemplo/lib/exemplo_web/templates/layout/app.html.heex
* creating exemplo/lib/exemplo_web/templates/layout/live.html.heex
* creating exemplo/lib/exemplo_web/views/layout_view.ex
* creating exemplo/lib/exemplo_web/templates/page/index.html.heex
* creating exemplo/test/exemplo_web/views/layout_view_test.exs
* creating exemplo/lib/exemplo/mailer.ex
* creating exemplo/lib/exemplo_web/gettext.ex
* creating exemplo/priv/gettext/en/LC_MESSAGES/errors.po
* creating exemplo/priv/gettext/errors.pot
* creating exemplo/assets/css/phoenix.css
* creating exemplo/assets/css/app.css
* creating exemplo/assets/js/app.js
* creating exemplo/priv/static/robots.txt
* creating exemplo/priv/static/images/phoenix.png
* creating exemplo/priv/static/favicon.ico
Fetch and install dependencies? [Yn]
* running mix deps.get
* running mix deps.compile
We are almost there! The following steps are missing:
$ cd exemplo
Then configure your database in config/dev.exs and run:
$ mix ecto.create
Start your Phoenix app with:
$ mix phx.server
You can also run your app inside IEx (Interactive Elixir) as:
$ iex -S mix phx.server
❯ cd exemplo
❯ mix ecto.create
Compiling 14 files (.ex)
Generated exemplo app
The database for Exemplo.Repo has been created
❯ fly launch
Creating app in /Users/jeanlucaslima/dev/github.com/jeanlucaslima/exemplo
Scanning source code
Detected a Phoenix app
? App Name (leave blank to use an auto-generated name):
Automatically selected personal organization: Jean Lucas
? Select region: gru (São Paulo)
Created app solitary-water-4912 in organization personal
Set secrets on solitary-water-4912: 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 Postgresql database now? Yes
For pricing information visit: https://fly.io/docs/about/pricing/#postgresql-clusters
? Select configuration: Development - Single node, 1x shared CPU, 256MB RAM, 1GB disk
Creating postgres cluster solitary-water-4912-db in organization personal
Postgres cluster solitary-water-4912-db created
Username: postgres
Password: [redacted]
Hostname: solitary-water-4912-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: 3 total, 3 passing]
--> v0 deployed successfully
Connect to postgres
Any app within the personal organization can connect to postgres using the above credentials and the hostname "solitary-water-4912-db.internal."
For example: postgres://postgres:296055e332e4c4a2634aa903a9ffedd01c890c8a3e79aefc@solitary-water-4912-db.internal:5432
See the postgres docs for more information on next steps, managing postgres, connecting from outside fly: https://fly.io/docs/reference/postgres/
Postgres cluster solitary-water-4912-db is now attached to solitary-water-4912
The following secret was added to solitary-water-4912:
DATABASE_URL=postgres://solitary_water_4912:QQDdJaswY9LSYtE@top2.nearest.of.solitary-water-4912-db.internal:5432/solitary_water_4912
Postgres cluster solitary-water-4912-db is now attached to solitary-water-4912
We recommend upgrading to Phoenix 1.6.3 which includes a release configuration for Docker-based deployment.
If you do upgrade, you can run 'fly launch' again to get the required deployment setup.
If you don't want to uprade, you'll need to add a few files and configuration options manually.
We've placed a Dockerfile compatible with other Phoenix 1.6 apps in this directory. See
https://hexdocs.pm/phoenix/fly.html for details, including instructions for setting up
a Postgresql database.
❯ fly launch
An existing fly.toml file was found for app solitary-water-4912
App is not running, deploy...
Deploying solitary-water-4912
==> Validating app configuration
--> Validating app configuration done
Services
TCP 80/443 ⇢ 8080
Remote builder fly-builder-damp-shadow-4483 ready
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
Sending build context to Docker daemon 40.02kB
[+] Building 54.2s (28/28) FINISHED
=> [internal] load remote build context 0.0s
=> copy /context / 0.0s
=> [internal] load metadata for docker.io/library/debian:bullseye-20210902-slim 1.6s
=> [internal] load metadata for docker.io/hexpm/elixir:1.13.4-erlang-25.0.2-debian-bullseye-20210902-slim 1.6s
=> [builder 1/17] FROM docker.io/hexpm/elixir:1.13.4-erlang-25.0.2-debian-bullseye-20210902-slim@sha256:9d9b1c244804e80da042719578670ad08018efc614bb266641f96a288a898b1e 0.0s
=> [stage-1 1/6] FROM docker.io/library/debian:bullseye-20210902-slim@sha256:e3ed4be20c22a1358020358331d177aa2860632f25b21681d79204ace20455a6 0.0s
=> CACHED [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/*_* 0.0s
=> CACHED [stage-1 3/6] RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen 0.0s
=> CACHED [stage-1 4/6] WORKDIR /app 0.0s
=> CACHED [stage-1 5/6] RUN chown nobody /app 0.0s
=> CACHED [builder 2/17] RUN apt-get update -y && apt-get install -y build-essential git && apt-get clean && rm -f /var/lib/apt/lists/*_* 0.0s
=> CACHED [builder 3/17] WORKDIR /app 0.0s
=> CACHED [builder 4/17] RUN mix local.hex --force && mix local.rebar --force 0.0s
=> [builder 5/17] COPY mix.exs mix.lock ./ 0.0s
=> [builder 6/17] RUN mix deps.get --only prod 5.1s
=> [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 41.3s
=> [builder 10/17] COPY priv priv 0.0s
=> [builder 11/17] COPY lib lib 0.0s
=> [builder 12/17] COPY assets assets 0.0s
=> [builder 13/17] RUN mix assets.deploy 2.4s
=> [builder 14/17] RUN mix compile 0.9s
=> [builder 15/17] COPY config/runtime.exs config/ 0.0s
=> [builder 16/17] COPY rel rel 0.0s
=> [builder 17/17] RUN mix release 1.9s
=> [stage-1 6/6] COPY --from=builder --chown=nobody:root /app/_build/prod/rel/exemplo ./ 0.2s
=> exporting to image 0.2s
=> => exporting layers 0.2s
=> => writing image sha256:2889a58a47775fcc2511989acc37749bff771567960bb61ed39fdaa67bda9784 0.0s
=> => naming to registry.fly.io/solitary-water-4912:deployment-1656162406 0.0s
--> Building image done
==> Pushing image to fly
The push refers to repository [registry.fly.io/solitary-water-4912]
301ddad2998d: Pushed
74ac0eec01c4: Mounted from dark-sun-6389
eea61e80bc84: Mounted from dark-sun-6389
3c648ad50c8b: Mounted from dark-sun-6389
d41c4ebb1dbd: Mounted from dark-sun-6389
ba5a5fe43301: Mounted from dark-sun-6389
deployment-1656162406: digest: sha256:93639018a97d771227e8e84e232ed32a40ba6be9ea6c482b714adf285c779da3 size: 1576
--> Pushing image done
Image: registry.fly.io/solitary-water-4912:deployment-1656162406
Image size: 117 MB
==> Creating release
Release v2 created
Release command detected: this new release will not be available until the command succeeds.
You can detach the terminal anytime without stopping the deployment
==> Release command
Command: /app/bin/migrate
Starting instance
Configuring virtual machine
Pulling container image
Unpacking image
Preparing kernel init
Starting virtual machine
Starting init (commit: e21acb3)...
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=d392b0bf-41f7-4fc6-85ab-a4255daa05eb
Preparing to run: `/app/bin/migrate` as nobody
2022/06/25 13:08:21 listening on [fdaa:0:71f1:a7b:1f60:18b3:4778:2]:22 (DNS: [fdaa::3]:53)
13:08:24.008 [error] Postgrex.Protocol (#PID<0.136.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (top2.nearest.of.solitary-water-4912-db.internal:5432): non-existing domain - :nxdomain
13:08:24.008 [error] Postgrex.Protocol (#PID<0.135.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (top2.nearest.of.solitary-water-4912-db.internal:5432): non-existing domain - :nxdomain
13:08:25.242 [error] Postgrex.Protocol (#PID<0.136.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (top2.nearest.of.solitary-water-4912-db.internal:5432): non-existing domain - :nxdomain
13:08:25.402 [error] Postgrex.Protocol (#PID<0.135.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (top2.nearest.of.solitary-water-4912-db.internal:5432): non-existing domain - :nxdomain
* The database does not exist
* The "schema_migrations" table, which Ecto uses for managing
migrations, was defined by another library
* There is a deadlock while migrating (such as using concurrent
To fix the first issue, run "mix ecto.create".
To address the second, you can run "mix ecto.drop" followed by
"mix ecto.create". Alternatively you may configure Ecto to use
another table and/or repository for managing migrations:
config :exemplo, Exemplo.Repo,
migration_repo: AnotherRepoForSchemaMigrations
The full error report is shown below.
2. Tracking down slow queries and making sure they are running fast enough
3. Increasing the pool_size (although this increases resource consumption)
4. Allowing requests to wait longer by increasing :queue_target and :queue_interval
(ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:932: Ecto.Adapters.SQL.raise_sql_call_error/1
(elixir 1.13.4) lib/enum.ex:1593: Enum."-map/2-lists^map/1-0-"/2
(ecto_sql 3.8.3) lib/ecto/adapters/sql.ex:1024: Ecto.Adapters.SQL.execute_ddl/4
(ecto_sql 3.8.3) lib/ecto/migrator.ex:146: Ecto.Migrator.with_repo/3
Main child exited normally with code: 1
Reaped child process with pid: 569 and signal: SIGUSR1, core dumped? false
Starting clean up.
Error Release command failed, deployment aborted
What does mix phx.new -v report? Did you upgrade your latest phoenix installer in between the 1.6.3 notice and your second time running fly launch? If not, you need to be on a newer phoenix since fly launch uses the phoenix release/docker generator under the hood. You can get a new app going with the following:
$ mix archive.install hex phx_new
$ mix phx.new example
$ cd example
$ fly launch
I’ll try that on a brand new project, @chrismccord. In one of my iterations I did change manually to 1.16.10 and updated, but yet got the same error. I’ll report it here.
The project structure/config changed on newer phoenix’s to better support releases, so easiest would be to start a fresh project on latest phx installer since you don’t have an existing app.
Looks like it’s that because the error message changed.
Yet it isn’t that.
But I tried upgrading it from 1.16.0 to 1.16.10 before and it didn’t work, that was the cli suggestion.
Now the project is not live, I have new errors. Will put them on the next reply.
Feedbacks:
(1) The error message couldn’t be worse, I spent hours not figuring out what I messed up because of the way it communicated I thought it was either environment or a database error.
(2) Even with phoenix 1.16.10 installed, I got the following message:
We recommend upgrading to Phoenix 1.6.3 which includes a release configuration for Docker-based deployment.
If you do upgrade, you can run 'fly launch' again to get the required deployment setup.
Running fly launch again after that got me deployed.
This is not an ideal dev experience, especially if someone is just testing it out before deciding which tool to use.
Even with a brand new project it didn’t go on. I feel lost tbh. Reading the link sent me on the final message about how to troubleshoot. But it feels like I shouldn’t be troubleshooting a hello world created by Phoenix.
Hello! This is actually due to a bug in our CLI. It was treating Phoenix 1.6.10 projects as Phoenix 1.6.1. We just shipped a fix, so you should have a better experience if you run fly version update, remove fly.toml and Dockerfile from your directory, then run fly launch again.