Elixir deploy fails (Phonix Petal Boilerplate )

Trying to deploy a project that is based on the phoenix petal boilerplate template

My hunch is that something in the config.exs is not happy.

LOG_LEVEL=debug fly deploy --remote-only
(...)
 1 desired, 1 placed, 0 healthy, 1 unhealthy
DEBUG --> POST https://api.fly.io/graphql

{
  "query": "query ($appName: String!, $deploymentId: ID!, $evaluationId: String!) { app(name: $appName) { deploymentStatus(id: $deploymentId, evaluationId: $evaluationId) { id inProgress status successful description version desiredCount placedCount healthyCount unhealthyCount allocations { id idShort status region desiredStatus version healthy failed canary restarts checks { status serviceName } } } } }",
  "variables": {
    "appName": "boilerplate-test",
    "deploymentId": "2a6828d7-86b8-32ed-a535-88d6ad104f5b",
    "evaluationId": "27394818-137a-50e7-f009-a00ce97370e8"
  }
}

DEBUG {}
DEBUG <-- 200 https://api.fly.io/graphql (145.23ms)

{
  "data": {
    "app": {
      "deploymentStatus": {
        "id": "2a6828d7-86b8-32ed-a535-88d6ad104f5b",
        "inProgress": false,
        "status": "failed",
        "successful": false,
        "description": "Failed due to unhealthy allocations - no stable job version to auto revert to",
        "version": 1,
        "desiredCount": 1,
        "placedCount": 1,
        "healthyCount": 0,
        "unhealthyCount": 1,
        "allocations": []
      }
    }
  }
 1 desired, 1 placed, 0 healthy, 1 unhealthy
--> v1 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v2

--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort

Things I tried:
:white_check_mark: deploy a vanilla phoenix project like so works fine :point_down:

mix phx.new bla
cd bla
fly launch
(..)
	 Starting clean up.
Monitoring Deployment

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

:person_shrugging: fly doctor

Testing authentication token... PASSED
Testing flyctl agent... PASSED
Testing local Docker instance... Nope
Pinging WireGuard gateway (give us a sec)... PASSED

so “something” in that petal boilerplate code seems not to work with fly.io

I haven’t tried to deploy this template project. That’s an interesting idea!

Just looking it over, I noticed that it doesn’t have a rel/ folder. This get’s generated when when you mix release.init.

What are the logs from a failed deploy?

fly logs

The project doesn’t have a Dockerfile, so does the fly launch create that for you?

Because Fly.io runs on an IPv6 network, there are config settings needed for that. See here:

The config/runtime.exs file looks to be missing some inet6 settings for IPv6 support.

  config :web, Web.Endpoint,
    server: true,
    url: [host: "my-cool-website.com", port: 80],
    http: [
      port: String.to_integer(System.get_env("PORT") || "4000"),
      # IMPORTANT: configure IPv6 support
      transport_options: [socket_opts: [:inet6]]
    ],
    secret_key_base: secret_key_base

  database_url =
    System.get_env("DATABASE_URL") ||
      raise """
      environment variable DATABASE_URL is missing.
      For example: ecto://USER:PASS@HOST/DATABASE
      """
  config :core, Core.Repo.Local,
    # ssl: true,
    url: database_url,
    # IMPORTANT: Or it won't find the DB server
    socket_options: [:inet6],
    pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")

Note: make sure to use the correct app configs for your project. For example, mine was: :web and :core, yours are unlikely to be that!

Hope this helps!

Thx. Those files were indeed missing. I generated them with mix release.init

I tried to redeploy with fly deploy --remote-only and still getting the same result

 1 desired, 1 placed, 0 healthy, 1 unhealthy [health checks: 1 total, 1 critical]
Failed Instances

Failure #1

Instance
ID      	PROCESS	VERSION	REGION	DESIRED	STATUS 	HEALTH CHECKS      	RESTARTS	CREATED
47084e9f	       	3      	sea   	run    	running	1 total, 1 critical	0       	4m53s ago

Recent Events
TIMESTAMP           	TYPE      	MESSAGE
2022-08-16T05:34:20Z	Received  	Task received by client
2022-08-16T05:34:20Z	Task Setup	Building Task Directory
2022-08-16T05:34:25Z	Started   	Task started by client

2022-08-16T05:34:22Z   [info]Configuring virtual machine
2022-08-16T05:34:22Z   [info]Pulling container image
2022-08-16T05:34:24Z   [info]Unpacking image
2022-08-16T05:34:24Z   [info]Preparing kernel init
2022-08-16T05:34:25Z   [info]Configuring firecracker
2022-08-16T05:34:25Z   [info]Starting virtual machine
2022-08-16T05:34:25Z   [info]Starting init (commit: c86b3dc)...
2022-08-16T05:34:25Z   [info]Preparing to run: `/app/bin/server` as nobody
2022-08-16T05:34:25Z   [info]2022/08/16 05:34:25 listening on [fdaa:0:4152:a7b:bbfc:4708:4e9f:2]:22 (DNS: [fdaa::3]:53)
2022-08-16T05:34:26Z   [info]Reaped child process with pid: 551, exit code: 0
2022-08-16T05:34:28Z   [info]Reaped child process with pid: 573 and signal: SIGUSR1, core dumped? false
--> v3 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v4

--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort

fly logs

2022-08-16T05:34:09Z app[a1f2ea61] sea [info]no label, UUID=9542d5bd-b528-4a4d-a551-407501b2b7ef
2022-08-16T05:34:09Z app[a1f2ea61] sea [info]Preparing to run: `/app/bin/migrate` as nobody
2022-08-16T05:34:09Z app[a1f2ea61] sea [info]2022/08/16 05:34:09 listening on [fdaa:0:4152:a7b:bcab:a1f2:ea61:2]:22 (DNS: [fdaa::3]:53)
2022-08-16T05:34:12Z app[a1f2ea61] sea [info]05:34:12.211 [info] Migrations already up
2022-08-16T05:34:13Z app[a1f2ea61] sea [info]Main child exited normally with code: 0
2022-08-16T05:34:13Z app[a1f2ea61] sea [info]Reaped child process with pid: 568 and signal: SIGUSR1, core dumped? false
2022-08-16T05:34:13Z app[a1f2ea61] sea [info]Starting clean up.
2022-08-16T05:34:22Z runner[47084e9f] sea [info]Starting instance
2022-08-16T05:34:22Z runner[47084e9f] sea [info]Configuring virtual machine
2022-08-16T05:34:22Z runner[47084e9f] sea [info]Pulling container image
2022-08-16T05:34:24Z runner[47084e9f] sea [info]Unpacking image
2022-08-16T05:34:24Z runner[47084e9f] sea [info]Preparing kernel init
2022-08-16T05:34:25Z runner[47084e9f] sea [info]Configuring firecracker
2022-08-16T05:34:25Z runner[47084e9f] sea [info]Starting virtual machine
2022-08-16T05:34:25Z app[47084e9f] sea [info]Starting init (commit: c86b3dc)...
2022-08-16T05:34:25Z app[47084e9f] sea [info]Preparing to run: `/app/bin/server` as nobody
2022-08-16T05:34:25Z app[47084e9f] sea [info]2022/08/16 05:34:25 listening on [fdaa:0:4152:a7b:bbfc:4708:4e9f:2]:22 (DNS: [fdaa::3]:53)
2022-08-16T05:34:26Z app[47084e9f] sea [info]Reaped child process with pid: 551, exit code: 0
2022-08-16T05:34:28Z app[47084e9f] sea [info]Reaped child process with pid: 573 and signal: SIGUSR1, core dumped? false
2022-08-16T05:39:36Z runner[47084e9f] sea [info]Shutting down virtual machine
2022-08-16T05:39:36Z app[47084e9f] sea [info]Sending signal SIGTERM to main child process w/ PID 515
2022-08-16T05:39:36Z app[47084e9f] sea [info]05:39:36.598 [notice] SIGTERM received - shutting down
2022-08-16T05:39:37Z app[47084e9f] sea [info]Reaped child process with pid: 575 and signal: SIGUSR1, core dumped? false
2022-08-16T05:39:40Z app[47084e9f] sea [info]Main child exited normally with code: 0
2022-08-16T05:39:40Z app[47084e9f] sea [info]Starting clean up.

yeah. fly launch did create it

FYI:
creating a vanilla project with mix phx.new and then fly launch creates identical files and it deploys fine.

I don’t see anything missing here. I compared the runtime.exs file from the petal_template with the runtime.exs file from a default mix phx.new project and they look identical

thx for your help!

Interesting. From the logs, it looks like it ran well enough to execute the migrations and see that they were current. Nothing else stands out in the logs.

I’d check that the secrets are set and if there any additional secrets needed by the template. Also worth checking if there are any additional ENV values that should be set int the fly.toml file.

The only other suggestion I have is to try and run in locally in prod mode. When we run in dev, it doesn’t execute the prod configs. That includes prod.exs and the prod section of runtime.exs. Then we aren’t usually building a release locally for dev either. There could be issues there.

I realize that running in “prod” mode can be difficult locally. That may or may not be practical.

Another suggestion is to add some explicit custom log messages at different points like in the lib/application.ex start function. You can determine if it’s even getting there.

Thx. Custom logging is a great idea. This is for a personal project and not pants on fire. I will play with it during the weekend.

1 Like