bryanhuntesl
Order of copying files in Dockerfile (cache invalidation of built deps)
Hi,
I have the following order of copying/invalidation in my Dockerfile:
COPY config/config.exs config/config.exs
COPY config/prod.exs config/prod.exs
RUN mix deps.compile
This was based upon an unfounded belief that the config.exs/prod.exs could influence compile time options in deps - as built by mix deps.compile.
It’s been pointed out to me that my assumption is incorrect, they only affect the building of artefacts in lib and test.
Is this true? Is it worth invalidating the built dependencies every time I change the config files?
Marked As Solved
NobbZ
Of course those changes can affect the compilation result of your dependencies, though compiletime configuration like that is frowned upon for libraries.
Also Liked
bryanhuntesl
Thanks @1player - yep I’ve never been a fan of umbrella apps and when it comes to containerisation things get even more complicated due to the multiple locations where one can unnecessarily invalidate the build.
@1player - looking at the configuration you’ve shared (many thanks) I would also recommend :
- setting the ENV variable MIX_ENV=prod and only copying the config/config.exs and config/prod.exs into the image - this will save your image from being invalidated by tweaks to the test.exs and develop.exs file
- set WORKDIR at the very start of the image build, to something like /app/build - makes it less verbose and reduces cognitive overhead for later maintainers.







