【问题标题】:Dependency cannot see its config during compilation依赖在编译期间看不到它的配置
【发布时间】:2017-09-20 11:42:30
【问题描述】:

我正在尝试将应用程序打包到 docker 容器中。它依赖于authable hex 包。

运行时:

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

...我收到以下编译错误:

== 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"

错误表明 Authable 在编译期间无法读取和初始化其repo 配置:

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

我觉得我缺少一些简单的东西,但我无法弄清楚它是什么。

这里有一个简单的 repo 来重现这个问题——https://github.com/gmile/test_authable_docker

更新。明确指出只有在 docker 期间编译时才会出现错误(例如,在主机 macOS 上编译时一切正常)。

【问题讨论】:

  • 你的项目对我来说编译得很好。
  • @JustinWood 你试过编译一个 docker 容器吗?

标签: docker elixir config elixir-mix


【解决方案1】:

这里的问题在于您的 Dockerfile,在尝试运行 mix deps.compile 时,config/config.exs 尚不可用。

原始 Dockerfile 内容:

# 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 . .

在执行mix compile 之前将其更改为复制源可解决此问题:

....
RUN mix deps.get

# Add project sources
COPY . .

RUN mix deps.compile
...

【讨论】:

  • 谢谢你,纳文!这是我的一个愚蠢的错误
  • 我认为只需在mix deps.compile 之前添加ADD config/config.exs ./config/ 就足够了,这样您就不必在每次项目源文件更改时重新编译所有依赖项
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-01
  • 2016-05-18
  • 1970-01-01
  • 2015-08-19
  • 2011-09-29
  • 1970-01-01
  • 2012-03-16
相关资源
最近更新 更多