From 98c5337c1221affc14adc474919a04b909fe9d84 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 20 Aug 2024 14:51:32 +0100 Subject: [PATCH] Warmup yarn and bundle caches in dev image (#832) Uses a multi-stage build with bind mount to avoid adding the discourse repo itself to the layers --- image/discourse_dev/Dockerfile | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/image/discourse_dev/Dockerfile b/image/discourse_dev/Dockerfile index 7afb7ef..2f34598 100644 --- a/image/discourse_dev/Dockerfile +++ b/image/discourse_dev/Dockerfile @@ -1,6 +1,15 @@ # NAME: discourse/discourse_dev # VERSION: release -FROM discourse/base:slim + +ARG from_tag=slim + +FROM discourse/base:$from_tag AS repo-fetcher +WORKDIR /repo +RUN chown discourse . +USER discourse +RUN git clone https://github.com/discourse/discourse . --depth 1 + +FROM discourse/base:$from_tag #LABEL maintainer="Sam Saffron \"https://twitter.com/samsaffron\"" @@ -49,3 +58,18 @@ RUN wget -qO /tmp/mailhog https://github.com/mailhog/MailHog/releases/download/v && mv /tmp/mailhog /usr/local/bin/mailhog\ && chmod +x /usr/local/bin/mailhog\ && rm -rf /tmp/* + +USER discourse + +# Warm global bundle cache, then delete the compressed `cache/` versions (`/gem/` are enough) +RUN --mount=type=bind,src=/repo,from=repo-fetcher,target=/tmp/discourse-clone,readwrite \ + cd /tmp/discourse-clone \ + && bundle install --deployment \ + && rm -rf /home/discourse/.bundle/gems/ruby/*/cache/* + +# Warm global yarn cache +RUN --mount=type=bind,src=/repo,from=repo-fetcher,target=/tmp/discourse-clone,readwrite \ + cd /tmp/discourse-clone \ + && yarn install + +USER root -- 2.25.1