From 1ea4496e95190a5eacb6b798dd64fd4071b843d9 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 3 Jan 2026 15:55:24 -0600 Subject: [PATCH] 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 --- Dockerfile | 12 +++++++++--- k8s/Dockerfile | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index a3537981..efbb28d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/k8s/Dockerfile b/k8s/Dockerfile index a3537981..efbb28d3 100644 --- a/k8s/Dockerfile +++ b/k8s/Dockerfile @@ -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