phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.44k stars 2.88k forks source link

Unable to deploy application on Dokku #2332

Closed Loschcode closed 7 years ago

Loschcode commented 7 years ago

Environment

* connection 1.0.4 (Hex package) (mix)
  locked at 1.0.4 (connection) a1cae722
  ok
* gettext 0.13.1 (Hex package) (mix)
  locked at 0.13.1 (gettext) 5e0daf4e
  ok
* ranch 1.3.2 (Hex package) (rebar3)
  locked at 1.3.2 (ranch) e4965a14
  ok
* poolboy 1.5.1 (Hex package) (rebar)
  locked at 1.5.1 (poolboy) 6b461639
  ok
* decimal 1.3.1 (Hex package) (mix)
  locked at 1.3.1 (decimal) 157b3ced
  ok
* poison 2.2.0 (Hex package) (mix)
  locked at 2.2.0 (poison) 4763b69a
  ok
* db_connection 1.1.2 (Hex package) (mix)
  locked at 1.1.2 (db_connection) 2865c2a4
  ok
* phoenix_pubsub 1.0.1 (Hex package) (mix)
  locked at 1.0.1 (phoenix_pubsub) c10ddf62
  ok
* cowlib 1.0.2 (Hex package) (rebar3)
  locked at 1.0.2 (cowlib) 9d769a1d
  ok
* cowboy 1.1.2 (Hex package) (rebar3)
  locked at 1.1.2 (cowboy) 61ac29ea
  ok
* mime 1.1.0 (Hex package) (mix)
  locked at 1.1.0 (mime) 01c1d6f4
  ok
* plug 1.3.5 (Hex package) (mix)
  locked at 1.3.5 (plug) 7503bfcd
  ok
* phoenix 1.2.4 (Hex package) (mix)
  locked at 1.2.4 (phoenix) 4172479b
  ok
* postgrex 0.13.2 (Hex package) (mix)
  locked at 0.13.2 (postgrex) 2b88168f
  ok
* ecto 2.1.4 (Hex package) (mix)
  locked at 2.1.4 (ecto) d1ba9328
  ok
* phoenix_ecto 3.2.3 (Hex package) (mix)
  locked at 3.2.3 (phoenix_ecto) 450c7498
  ok

Expected behavior

When deploying on my Dokku application on DigitalOcean, it should just work. The application is fresh and I wrote literally nothing in it to troubleshoot the problem.

Actual behavior

After trying to push with git push dokku it goes through the process until it crashes with Postgrex.

       Compiling 42 files (.ex)
remote: warning: behaviour Postgrex.SuperExtension is undefined
remote:   lib/postgrex/extensions/array.ex:1
remote:
remote: warning: behaviour Postgrex.SuperExtension is undefined
remote:   lib/postgrex/extensions/range.ex:1
remote:
remote: warning: behaviour Postgrex.SuperExtension is undefined
remote:   lib/postgrex/extensions/record.ex:1
remote:
remote: warning: function Postgrex.TypeModule.define/3 is undefined (module Postgrex.TypeModule is not available)
remote:   lib/postgrex/types.ex:260
remote:
remote: warning: function Postgrex.TypeManager.get/2 is undefined (module Postgrex.TypeManager is not available)
remote:   lib/postgrex/protocol.ex:621
remote:
       Generated postgrex app
==> ecto
       Compiling 67 files (.ex)
       Compiling lib/ecto/query/builder/lock.ex (it's taking more than 10s)
       Compiling lib/ecto/repo/queryable.ex (it's taking more than 10s)
       Compiling lib/ecto/query/inspect.ex (it's taking more than 10s)
       Compiling lib/ecto/query/builder/filter.ex (it's taking more than 10s)
       Compiling lib/ecto/repo/preloader.ex (it's taking more than 10s)
       Compiling lib/ecto/repo/schema.ex (it's taking more than 10s)
       Compiling lib/ecto/embedded.ex (it's taking more than 10s)
       Compiling lib/ecto/migration/schema_migration.ex (it's taking more than 10s)
       Compiling lib/ecto/query/builder/preload.ex (it's taking more than 10s)
       Compiling lib/ecto/adapters/postgres/connection.ex (it's taking more than 10s)

== Compilation error on file lib/ecto/adapters/postgres/connection.ex ==
       ** (UndefinedFunctionError) function Postgrex.TypeModule.define/3 is undefined (module Postgrex.TypeModule is not available)
       Postgrex.TypeModule.define(Ecto.Adapters.Postgres.TypeModule, [Ecto.Adapters.Postgres.Date, Ecto.Adapters.Postgres.Time, Ecto.Adapters.Postgres.Timestamp, Ecto.Adapters.Postgres.TimestampTZ], [json: Poison])
       lib/ecto/adapters/postgres/connection.ex:2: (file)
       (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

remote: could not compile dependency :ecto, "mix compile" failed. You can recompile this dependency with "mix deps.compile ecto", update it with "mix deps.update ecto" or clean it with "mix deps.clean ecto"
To pantouflesdokku:justpushit-api
 ! [remote rejected] master -> master (pre-receive hook declined)

I'm out of solution, it's been several days now and it's literally a fresh new project without anything in it. I just configured the database properly taking inspiration from my own working projects on Dokku.

chrismccord commented 7 years ago

You included the versions you have on your local OS X, but what elixir and Erlang versions are installed on the dokku server?

Loschcode commented 7 years ago

The Dokku server is configured as follow

# Erlang version
erlang_version=19.0

# Elixir version
elixir_version=1.4.0

# Rebar version
rebar_version=(tag 2.2.0)

# Do dependencies have to be built from scratch on every deploy?
always_build_deps=false

# post_compile="mix ecto.migrate"
josevalim commented 7 years ago

@Loschcode there is something broken in your postgrex package. Postgrex 0.13.2 has 62 files but your compiler above says it has only 42. Or it is trying to use a previously cached version and that somehow is causing a failure or the dependency is somehow corrupt/broken.

I would temporarily set the config to true below hoping it will force a full recompilation without reusing caches.

always_build_deps=false

Loschcode commented 7 years ago

Sadly, it didn't change the error, I'm trying to understand why it doesn't compile properly but can't find out why

       Compiling 42 files (.ex)
chrismccord commented 7 years ago

@Loschcode to be clear, you set always_build_deps=true, right?

Loschcode commented 7 years ago

Yes it's what I just did, it didn't change the error

ericmj commented 7 years ago

How does Dokku build Elixir projects, is there a buildpack?

Loschcode commented 7 years ago

Yes, I use this buildpack

https://github.com/HashNuke/heroku-buildpack-elixir

It should work, I already used it for a released project ...

ericmj commented 7 years ago

It seems like you are using an outdated version of the buildpack or your config is outdated. The options rebar_version and always_build_deps do not exist on that buildpack.

Loschcode commented 7 years ago

You're right, I changed it to the following

# Erlang version
erlang_version=19.0

# Elixir version
elixir_version=1.4.0

# Always rebuild from scratch on every deploy?
always_rebuild=true

But it didn't change the error with Postgrex, it keeps failing 😞

Loschcode commented 7 years ago

By downgrading the version of Postgrex to 0.13.0 the compilation succeeded (0.13.1 did not)

==> postgrex
       Compiling 61 files (.ex)
       Compiling lib/postgrex/default_types.ex (it's taking more than 10s)
       Generated postgrex app

But that's getting weirder and weirder as it crashes for another reason now

==> plug
       Compiling 44 files (.ex)

== Compilation error on file lib/plug/debugger.ex ==
       ** (File.Error) could not read file "lib/plug/templates/debugger.html.eex": no such file or directory
       (elixir) lib/file.ex:244: File.read!/1
       lib/eex.ex:181: EEx.compile_file/2
       lib/plug/debugger.ex:168: (module)
       (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6

remote: could not compile dependency :plug, "mix compile" failed. You can recompile this dependency with "mix deps.compile plug", update it with "mix deps.update plug" or clean it with "mix deps.clean plug"

My deps look like that

  defp deps do
    [{:phoenix, "~> 1.2.4"},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_ecto, "~> 3.0"},
     {:postgrex, "0.13.0"},
     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"}]
  end

Maybe the fact I changed Postgrex version make the following dependencies crash ?

josevalim commented 7 years ago

@Loschcode there is definitely something messed up in your deployment pipeline as it is now missing a file from another dependency. I don't know what is the cause but it is definitely something unrelated to Phoenix. Is there any chance this current machine is borked?

Loschcode commented 7 years ago

Well if you say so I can try to make everything from scratch including server, git and project and see what happens, it's extremely disturbing because I don't recall anything wrong in what I did 😞

I'll do that and if it works, then issue closed I guess.

Other than that, my local machine is working clean, the local version is working as well, but the server I use seems to act funny with this specific repo ; i'll try to find out.

josevalim commented 7 years ago

@Loschcode maybe in dokku you can start a whole new project? If possible, maybe try that and make sure to start with the latest buildpack.

petermm commented 7 years ago

this is clearly a heroku-buildpack-elixir issue. related https://github.com/HashNuke/heroku-buildpack-elixir/issues/88

  1. try "mix deps.clean --all && mix deps.get" in the precompile hook
  2. try bumping elixir version (to force rebuild)
  3. try bumping erlang version (to force rebuild)
ericmj commented 7 years ago

this is clearly a heroku-buildpack-elixir issue

It's more likely it's a dokku issue or an issue with the machine it's running on since the buildpack has been working without issue on heroku from some time. The buildpack was made for heroku and I don't think it has been tested on dokku by the maintainers of the buildpack.

josevalim commented 7 years ago

Closing this until we can pinpoint it is a Phoenix issue.