Add BuildKit cache mounts to speed up Docker builds

- Cache Hex packages across builds
- Cache Mix archives across builds
- Cache npm packages for asset tooling
- Speeds up dependency installation significantly
This commit is contained in:
Graham McIntire 2026-01-03 15:55:24 -06:00
parent f050fb0eea
commit 1ea4496e95
No known key found for this signature in database
2 changed files with 18 additions and 6 deletions

View file

@ -40,16 +40,22 @@ ENV MIX_ENV="prod"
# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN --mount=type=cache,target=/root/.hex \
--mount=type=cache,target=/root/.mix \
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 config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile
RUN --mount=type=cache,target=/root/.hex \
--mount=type=cache,target=/root/.mix \
mix deps.compile
RUN mix assets.setup
RUN --mount=type=cache,target=/root/.mix \
--mount=type=cache,target=/root/.npm \
mix assets.setup
COPY priv priv

View file

@ -40,16 +40,22 @@ ENV MIX_ENV="prod"
# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN --mount=type=cache,target=/root/.hex \
--mount=type=cache,target=/root/.mix \
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 config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile
RUN --mount=type=cache,target=/root/.hex \
--mount=type=cache,target=/root/.mix \
mix deps.compile
RUN mix assets.setup
RUN --mount=type=cache,target=/root/.mix \
--mount=type=cache,target=/root/.npm \
mix assets.setup
COPY priv priv