Search code examples
dockerelixirconfigelixir-mix

Dependency cannot see its config during compilation


I'm trying to package an app in docker container. It has a dependency on authable hex package.

When running:

docker build --tag "testing:0.1" --file Dockerfile .

... I get the following compilation error:

== Compilation error on file lib/authable/repo.ex ==
** (ArgumentError) missing :adapter configuration in config :authable, Authable.Repo
    lib/ecto/repo/supervisor.ex:50: Ecto.Repo.Supervisor.compile_config/2
    lib/authable/repo.ex:6: (module)
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6

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

The error indicates the Authable was not able to read & initialize its repo config during compilation:

  1. authable/repo.ex
  2. config.exs

I feel like there's something simple that I'm missing, but I can't figure our what it is.

A simple repo to reproduce the issue is here – https://github.com/gmile/test_authable_docker.

Update. Made it clear that the error occurs only when compiling during docker (e.g. everything is fine when compiling on host macOS).


Solution

  • The issue here is with your Dockerfile, where the config/config.exs is not yet available when trying to run mix deps.compile.

    Original Dockerfile content:

    # Install and compile project dependencies
    COPY mix.* ./
    
    RUN mix deps.get
    RUN mix deps.compile
    RUN mix ecto.create
    RUN mix ecto.migrate -r Authable.Repo
    
    # Add project sources
    COPY . .
    

    Changing this to copying the sources before doing mix compile solves this issue:

    ....
    RUN mix deps.get
    
    # Add project sources
    COPY . .
    
    RUN mix deps.compile
    ...