shanesveller/docker-phoenix-framework

guardian compatibility

maslenkov opened this issue · 3 comments

Guardian require config.exs or prod.exs on compilation step.
In current Dockerfile we have:

ONBUILD COPY mix.* /usr/src/app/
ONBUILD RUN mix do deps.get --only prod
# phoenix and phoenix_html JS dependencies are included from Hex packages
ONBUILD COPY package.json /usr/src/app/
ONBUILD RUN npm install
ONBUILD RUN mix deps.compile --only prod

ONBUILD COPY . /usr/src/app/
ONBUILD RUN mix compile

As you can see config/* does not exists before we run mix deps.compile. So we get error:

== Compilation error on file lib/guardian.ex ==
** (RuntimeError) Guardian is not configured
    lib/guardian.ex:26: (module)
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6

could not compile dependency :guardian, "mix compile" failed. You can recompile this dependency with "mix deps.compile guardian", update it with "mix deps.update guardian" or clean it with "mix deps.clean guardian"
The command '/bin/sh -c mix deps.compile --only prod' returned a non-zero code: 1

I suggest to change this Dockerfile's lines to:

 ONBUILD COPY . /usr/src/app/
 ONBUILD RUN mix do deps.get --only prod
 ONBUILD RUN npm install
 ONBUILD RUN mix deps.compile --only prod
 ONBUILD RUN mix compile

After this updates build works successfully.

timka commented

@shanesveller I'm wondering what was your intention for copying step-by-step

https://hub.docker.com/r/maslenkov/phoenix-framework/ tag 1.2.5.1 already contains this updates.

@timka @maslenkov COPYing your entire project contents prior to installing Mix/NPM dependencies will completely invalidate the Docker layer cache for every single code change to your project, even README, gitignore, etc. The current order in this Dockerfile is a deliberate effort to ensure that NPM/Mix deps are only re-installed specifically when those dependencies are changed, while normal code/documentation changes within your project will not require that step unless you're introducing a new or updated dependency. I am satisfied that this is the appropriate behavior for my use-case.