fly deploy returns error for new app

Hey Folks,

I just created a new application using fly launch and I can’t deploy even the first deploy now. When running fly launch, I decided against giving the app a Postgres database or deploying right away, but then added my own fly secrets set DATABASE_URL="..." instead. Then, I ran fly deploy, but I receive the following error:

Running [redacted] release_command: /app/bin/migrate
  Waiting for 9080525a0735e8 to get exit event
Error release_command failed running on machine 9080525a0735e8 with exit code 1.
Check its logs: here's the last 100 lines below, or run 'fly logs -i 9080525a0735e8':
  Pulling container image registry.fly.io/[redacted]:deployment-01H5R0RY4RAZF62608GKGB4SR0
  Successfully prepared image registry.fly.io/[redacted]:deployment-01H5R0RY4RAZF62608GKGB4SR0 (2.908929238s)
  Configuring firecracker
   INFO Starting init (commit: 1d1821d)...
   INFO Preparing to run: `/app/bin/migrate` as nobody
   INFO [fly api proxy] listening at /.fly/api
  2023/07/19 21:27:10 listening on [fdaa:0:20aa:a7b:a27f:dace:d492:2]:22 (DNS: [fdaa::3]:53)
  Creating swapfile
  fallocate: cannot open /swapfile: Permission denied
   INFO Main child exited normally with code: 1
   INFO Starting clean up.
   WARN hallpass exited, pid: 249, status: signal: 15 (SIGTERM)
  2023/07/19 21:27:11 listening on [fdaa:0:20aa:a7b:a27f:dace:d492:2]:22 (DNS: [fdaa::3]:53)
  [    2.282327] reboot: Restarting system
  machine restart policy set to 'no', not restarting
Error: release command failed - aborting deployment. error release_command machine 9080525a0735e8 exited with non-zero status of 1

The app is deployed in AMS. I tried it with a database from another provider, one that I successfully used with another app, but it returned the same error.

1 Like

I destroyed the builder and moved to another region (London), but still the same error occurs.

I removed the line export ECTO_IPV6="true" from env.sh.eex because my external database only supports IPv4. This didn’t change the error though.

hi Peter, I think the error is at:

  fallocate: cannot open /swapfile: Permission denied

remove the the if... fi block from rel/env.sh.eex

that should get you going while we work on a better fix.

1 Like

Hitting the same error too on a new app launch:

  Creating swapfile
  fallocate: cannot open /swapfile: Permission denied
   INFO Main child exited normally with code: 1
   INFO Starting clean up.
   WARN hallpass exited, pid: 248, status: signal: 15 (SIGTERM)

This is my fault. Looks like not all Docker configs have the right perms to handle the swap allocation. As Dan said, if you remove the if block in rel/env.sh.eex you’ll be good to go while I work out a proper fix. Thanks!

2 Likes

That worked! Thank you @chrismccord :pray: How will we know that we can enable the swapfile again? In general, I’m unsure how I can keep track of changes like this. Usually, I run fly launch when I create an app and then never touch the config files (rel, dockerfile, fly.toml, etc) again. Is there a way of comparing the versions of these files without creating a new app using fly launch?

We never created it for you prior to this, so you aren’t any worse off :slight_smile: I have also cut a new flyctl. To make this work, you’ll need to remove USER nobody in your dockerfile above the entrypoint, and allow it to run as root. Then you can modify your rel/overlays/bin/server script that phoenix generated to do the swap allocation, then downgrade the user to nobody when running the server:

#!/bin/sh

if [ "$(id -u)" -eq 0 ] && [ ! -f /swapfile ]; then
  # allocate swap space
  fallocate -l 512M /swapfile
  chmod 0600 /swapfile
  mkswap /swapfile
  echo 10 > /proc/sys/vm/swappiness
  swapon /swapfile
  echo 1 > /proc/sys/vm/overcommit_memory
  # rerun this script as nobody
  exec su nobody -s $SHELL -c "$0 $@"
fi

cd -P -- "$(dirname -- "$0")"
PHX_SERVER=true exec ./myapp start

Replace myapp with your app name and off to the races. I’m looking at options that allows this to work generally, but for now that’s the best solution as a do-it-yourself approach.