From c408c04bb0e9f5e29c224b8186be68aa3163ee7f Mon Sep 17 00:00:00 2001
From: setop <setop@zoocoop.com>
Date: Sun, 4 Jul 2021 21:19:16 +0000
Subject: [PATCH] make build faster using buildlkit - use annotation for
 buildkit - cache yarn packages - compile before copying assets to allow
 parallel build of phases

to use it, run
`DOCKER_BUILDKIT=1 docker image build -f docker/production/Dockerfile .`
---
 docker/production/Dockerfile | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/docker/production/Dockerfile b/docker/production/Dockerfile
index 46447aaf8..4f561c108 100644
--- a/docker/production/Dockerfile
+++ b/docker/production/Dockerfile
@@ -1,11 +1,13 @@
+# syntax=docker/dockerfile:1.2
+
 # First build the application assets
 FROM node:16-alpine as assets
 
 RUN apk add --no-cache python3 build-base libwebp-tools bash imagemagick ncurses
 WORKDIR /build
 COPY js .
-RUN yarn install \
-    && yarn run build
+RUN --mount=type=cache,target=/root/.cache yarn install
+RUN yarn run build
 
 # Then, build the application binary
 FROM elixir:1.12-alpine AS builder
@@ -24,6 +26,9 @@ COPY config/config.exs config/prod.exs ./config/
 COPY config/docker.exs ./config/runtime.exs
 COPY rel ./rel
 COPY support ./support
+
+RUN mix compile
+
 COPY --from=assets ./priv/static ./priv/static
 
 RUN mix phx.digest \