Optimize Dockerfile layer caching
Move COPY priv after mix compile so ML model retraining doesn't bust the compile cache. Create empty priv dirs before compile for :code.priv_dir. Move algo.md after compile. Add docs/plans and analysis outputs to .dockerignore.
This commit is contained in:
parent
95907c90d3
commit
7e65327e84
2 changed files with 22 additions and 12 deletions
|
|
@ -44,3 +44,8 @@ erl_crash.dump
|
|||
/assets/node_modules/
|
||||
/priv/static/assets/
|
||||
/priv/static/cache_manifest.json
|
||||
|
||||
# Analysis outputs and plans (not needed in container)
|
||||
/docs/analysis_output*.txt
|
||||
/docs/plans/
|
||||
/.worktrees/
|
||||
|
|
|
|||
29
Dockerfile
29
Dockerfile
|
|
@ -59,33 +59,38 @@ RUN mix local.hex --force \
|
|||
# set build ENV
|
||||
ENV MIX_ENV="prod"
|
||||
|
||||
# install mix dependencies
|
||||
# install mix dependencies (changes only when mix.exs/mix.lock change)
|
||||
COPY mix.exs mix.lock ./
|
||||
RUN mix deps.get --only $MIX_ENV
|
||||
RUN mkdir config
|
||||
|
||||
# copy compile-time config files before we compile dependencies
|
||||
# to ensure any relevant config change will trigger the dependencies
|
||||
# to be re-compiled.
|
||||
# copy compile-time config before compiling deps
|
||||
RUN mkdir config
|
||||
COPY config/config.exs config/${MIX_ENV}.exs config/
|
||||
RUN mix deps.compile
|
||||
|
||||
# install esbuild + tailwind binaries (cached until mix.exs changes)
|
||||
RUN mix assets.setup
|
||||
|
||||
COPY priv priv
|
||||
# create priv dir so :code.priv_dir works at compile time
|
||||
# (actual contents copied after compile to avoid cache busting)
|
||||
RUN mkdir -p priv/models priv/static
|
||||
|
||||
# copy application code and compile
|
||||
COPY lib lib
|
||||
COPY algo.md algo.md
|
||||
|
||||
# Compile the release
|
||||
RUN mix compile
|
||||
|
||||
# copy assets and build (JS/CSS changes don't require recompilation)
|
||||
COPY assets assets
|
||||
|
||||
# compile assets
|
||||
RUN mix assets.deploy
|
||||
|
||||
# Changes to config/runtime.exs don't require recompiling the code
|
||||
# copy priv contents (migrations, ML model, static files)
|
||||
# after compile so model retraining doesn't bust the compile cache
|
||||
COPY priv priv
|
||||
|
||||
# algo.md is runtime documentation, not compiled
|
||||
COPY algo.md algo.md
|
||||
|
||||
# runtime config doesn't require recompilation
|
||||
COPY config/runtime.exs config/
|
||||
|
||||
COPY rel rel
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue