Elixir Buildpacks Error

I’m trying to setup an elixir/phoenix/postgres application and having a couple issues. I tried using the Dockerfile from the demo Kurt did for twitter but that kept erroring at the last step and docker isn’t my strong suit.

So… I have lots of heroku experience and I figured lets try out a build pack.

From the docs it looks like i just need something like this in my fly.toml

# fly.toml file generated for fermi on 2021-04-22T12:19:09-05:00

app = "fermi"

kill_signal = "SIGINT"
kill_timeout = 5

[env]
  MIX_ENV = "prod"
  SECRET_KEY_BASE = "sosecret"

[build]
  builder = "heroku/buildpacks:20"
  buildpacks = ["https://github.com/HashNuke/heroku-buildpack-elixir.git", "https://github.com/gjaldon/heroku-buildpack-phoenix-static.git" ]

[deploy]
  release_command = "POOL_SIZE=1 MIX_ENV=prod mix ecto.migrate"

[experimental]
  auto_rollback = true
  private_network=true

[[services]]
  http_checks = []
  internal_port = 8080
  protocol = "tcp"
  script_checks = []

  [[services.ports]]
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 6
    timeout = "2s"

But when it always fails with the following logs:

❯ fly deploy  
Deploying fermi
==> Validating app configuration
--> Validating app configuration done
Services
TCP 80/443 ⇢ 8080
==> Building image with Buildpacks
20: Pulling from heroku/buildpacks
Digest: sha256:487fb53b35f9b41b4931eec7c3eb138b605aac13c947ba34731dd2f0d040b3fa
Status: Image is up to date for heroku/buildpacks:20
20: Pulling from heroku/pack
Digest: sha256:e3e29ffe59b09e2d5bcfeaf0497e7765411b56b2b9e392049f94b738b4e6201c
Status: Image is up to date for heroku/pack:20
Downloading from https://github.com/HashNuke/heroku-buildpack-elixir.git
182 KB/-1 B 
Error extracting from https://github.com/HashNuke/heroku-buildpack-elixir.git: inspecting buildpack blob: failed to get next tar entry: archive/tar: invalid tar header

Try this:

[build]
  builder = "heroku/buildpacks:20"
  buildpacks = ["https://cnb-shim.herokuapp.com/v1/hashnuke/elixir" ]

Heroku buildpacks and CNB buildpacks aren’t quite the same, so they need to be translated.

Getting a 503 from that

Looks like https://cnb-shim.herokuapp.com is down. Might be related to an outage earlier Heroku Status. You’ll need to wait until it’s back up, but I’m going to look into running the shim on fly.

1 Like

Yep its back up now.

Where I’m at now is that It gets stuck on “DETECTING” but only for the gjaldon/phoenix-static step. Regardless of the order I run them in or if I run them one at a time, or if I try heroku:18 or heroku:20

The hashnuke elixir build pack has no problems detecting and starts the build. It’s extra weird because the detect scripts for both are identical.

The phoenix-static is in the heroku buildpacks:search listing and I downloaded the files the shim downloads just to confirm its not some different version, and it’s identical.

Here are the logs

**❯** fly deploy
**Deploying fermi**
==> Validating app configuration
--> Validating app configuration done
**Services**
TCP 80/443 ⇢ 8080
==> Building image with Buildpacks
18: Pulling from heroku/buildpacks
Digest: sha256:c21a2b9b84990087e17d4a761d7c6520043fbf1bdccf55a1d767b090539834e1
Status: Image is up to date for heroku/buildpacks:18
18: Pulling from heroku/pack
Digest: sha256:90b2e6eeb926bf7bc23e671f0b96a1e8dbbf9f2f2691b890805fbe487ef7b8c2
Status: Image is up to date for heroku/pack:18
Downloading from https://cnb-shim.herokuapp.com/v1/hashnuke/elixir
1.89 MB/-1 B
Downloading from https://cnb-shim.herokuapp.com/v1/gjaldon/phoenix-static
1.88 MB/-1 B
===> DETECTING
err: gjaldon/phoenix-static@0.1 (126)
**ERROR:** No buildpack groups passed detection.
**ERROR:** failed to detect: buildpack(s) failed with err
Error executing lifecycle: failed with status code: 101

(Also note the 1.98MB / -1mb downloaded heh)

You probably don’t need the Phoenix Static buildpack. Can you try without it?

I mean I have to build the assets which phoenix live view depend on :stuck_out_tongue: and in other buildpack based deploy systems I also need to use them.

Right! I’m fairly sure recent HashNuke Elixir buildpack versions do everything you need. I’ve had success with just that one buildpack on most Phoenix apps.

It definitely does not, you might be building locally before deploying? Your Dockerfile downloads node and builds it but the hashnuke does not heroku-buildpack-elixir/compile at master · HashNuke/heroku-buildpack-elixir · GitHub . Maybe you are using releases and building them locally before deploying which would work? But even in that case you’d want to use a different buildpack designed for them GitHub - chrismcg/heroku-buildpack-elixir-mix-release: A Heroku buildpack for use with Elixir 1.9+ releases.

Been deploying phoenix to heroku for a long time, and its why we have a whole guide devoted to it because it’s so finicky :P.

Nonetheless I tried it out just to see and now it doesn’t appear to have the environment variables set? I have attached a fly postgres to my fermi app, but the DATABASE_URL doesn’t appear to be set during build, when I add a dummy DATABASE_URL to my fly.toml it still yells at me.

MAYBE I need to take another stab at the dockerfile.

Argh yes. We literally have someone starting next week to help make this nicer, for what it’s worth. It is fraught with peril because I’m pretty new at Elixir. :slight_smile:

This is a decent guide with a Dockerfile if it helps: How to deploy a Phoenix application with Fly.io

The build doesn’t have access to the same secrets as the running VM. You can stub them out in your fly.toml though:

[build]
  builder = "heroku/buildpacks:20"
  buildpacks = ["https://cnb-shim.herokuapp.com/v1/hashnuke/elixir" ]
  [build.args]
    DATABASE_URL="none"
    SECRET_KEY_BASE="none"

Ohh build.args.

Thank you! Congrats on the hire, looking forward to seeing whom you picked up. There was a lot of chatter about the job. Though maybe I shouldn’t do their job for them :P.

1 Like

You should see the list of things we need to do. They’ll appreciate whatever you do today. :slight_smile:

Well if they need help testing the buildpacks and I’m not busy then I’ll be glad to assist.

Howdy @jason1! I joined Fly to help out with the Elixir support. I think the Fly infrastructure is really exciting for running Elixir apps on and I’m looking forward to helping others see the benefits for themselves.

Sorry you’ve been having such a rough time with it. It took me some time (and extra help) getting my first couple Elixir apps deployed on Fly. I’m glad you’ve stuck with it! I’d love to help you get it working. I just started work on a new official guide for getting a new Elixir app deployed so me helping you helps me! So <buzzword>synergy</buzzword>! :slight_smile:

I’m working on the Docker approach first. Feel free to DM me and we’ll get you up and running.

4 Likes

@jason1 I created an initial release of the Elixir guide for deploying on Fly. I’d love any feedback (problems/successes) you have with it so I can make it better. Hope it helps!

https://fly.io/docs/getting-started/elixir/

1 Like

This is good!

It’s kind of weird but couldn’t you make a build pack that takes the elixir/erlang/node version config and then uses the above dockerfile?

Basically now that I have this working I’m just going to copy/paste the Dockerfile, Migrations and entrypoint.sh between projects and changing the versions. :stuck_out_tongue: feels like fly could make elixir a first class citizen this way.

Congrats on the new role @brainlid and thanks for the guide! This is exciting - love the podcast and nice to see the Elixir world progress :slight_smile:

I just tried following the steps and hit a couple of problems, curious if you can help out:

When I do fly postgres create I have to choose a region other than the one I chose for the app, otherwise I get “Error Can’t create volume, application is already using 1 of 1 zones in fra” . I chose fra for the app itself (delicate-resonance-7851 in case that’s useful and I’m calling the db delicate-db) and am only able to proceed if I choose e.g. ams or cdg.

1 Like

You are right, the goal is to make Elixir more a first-class experience. Starting with the Dockerfile approach for now. I do have some updates coming today. Including changes to make getting an SSH connection with an IEx shell into a running node working.

@maciej will you try a DB in fra again? Our database was missing some disk capacity so it didn’t think it could give you enough volumes for a pg cluster there.