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:
parent
f050fb0eea
commit
1ea4496e95
2 changed files with 18 additions and 6 deletions
12
Dockerfile
12
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue