railwayapp / nixpacks

App source + Nix packages + Docker = Image
https://nixpacks.com
MIT License
2.33k stars 222 forks source link

Elixir nixpack shouldn't run migrations in build step #1078

Open bianchidotdev opened 3 months ago

bianchidotdev commented 3 months ago

Is there an existing issue for this?

Describe the bug

The default elixir buildpack tries to run migrations during the docker build. I might be missing some common use case, but I can't imagine wanting to run migrations during the image building. I checked a few other languages, and they don't seem to have similar behavior.

To reproduce

Create a new phoenix app (assuming elixir and phoenix are installed):

mix phx.new hello
cd hello
nixpacks build ./

# output
 => ERROR [12/14] RUN  mix ecto.migrate                                                                                            0.5s
------
 > [12/14] RUN  mix ecto.migrate:
0.211 warning: the VM is running with native name encoding of latin1 which may cause Elixir to malfunction as it expects utf8. Please ensure your locale is set to UTF-8 (which can be verified by running "locale" in your shell)
0.473 ** (RuntimeError) environment variable DATABASE_URL is missing.
0.473 For example: ecto://USER:PASS@HOST/DATABASE
0.473
0.473     /app/config/runtime.exs:26: (file)
0.473     (stdlib 4.3.1.2) erl_eval.erl:748: :erl_eval.do_apply/7
0.473     (stdlib 4.3.1.2) erl_eval.erl:492: :erl_eval.expr/6
0.473     (stdlib 4.3.1.2) erl_eval.erl:136: :erl_eval.exprs/6
0.473     (elixir 1.14.5) lib/code.ex:425: Code.validated_eval_string/3
------
Dockerfile:27
--------------------
  25 |     RUN  mix compile
  26 |     RUN  mix assets.deploy
  27 | >>> RUN  mix ecto.migrate
  28 |     RUN  mix run priv/repo/seeds.exs
  29 |
--------------------
ERROR: failed to solve: process "/bin/bash -ol pipefail -c mix ecto.migrate" did not complete successfully: exit code: 1
Error: Docker build failed

The following nixpacks.toml fixes this:

[phases.build]
cmds = ["mix compile", "mix assets.deploy"]

Expected behavior

Don't run migrations and seeds during the build step. Maybe not at all. Python ran migrations in the start step which might make sense, but I'm not sure what the best behavior is.

Environment

Mac OS Sonoma 14.4 Nixpacks v1.21.2

jiangplus commented 1 month ago

I run into the same issue. Migrations shouldn't be run on docker build.