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:
Graham McIntire 2026-04-01 10:32:56 -05:00
parent 95907c90d3
commit 7e65327e84
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59
2 changed files with 22 additions and 12 deletions

View file

@ -44,3 +44,8 @@ erl_crash.dump
/assets/node_modules/ /assets/node_modules/
/priv/static/assets/ /priv/static/assets/
/priv/static/cache_manifest.json /priv/static/cache_manifest.json
# Analysis outputs and plans (not needed in container)
/docs/analysis_output*.txt
/docs/plans/
/.worktrees/

View file

@ -59,33 +59,38 @@ RUN mix local.hex --force \
# set build ENV # set build ENV
ENV MIX_ENV="prod" ENV MIX_ENV="prod"
# install mix dependencies # install mix dependencies (changes only when mix.exs/mix.lock change)
COPY mix.exs mix.lock ./ COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV RUN mix deps.get --only $MIX_ENV
RUN mkdir config
# copy compile-time config files before we compile dependencies # copy compile-time config before compiling deps
# to ensure any relevant config change will trigger the dependencies RUN mkdir config
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/ COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile RUN mix deps.compile
# install esbuild + tailwind binaries (cached until mix.exs changes)
RUN mix assets.setup 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 lib lib
COPY algo.md algo.md
# Compile the release
RUN mix compile RUN mix compile
# copy assets and build (JS/CSS changes don't require recompilation)
COPY assets assets COPY assets assets
# compile assets
RUN mix assets.deploy 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 config/runtime.exs config/
COPY rel rel COPY rel rel