From 3632cc33d9e8f447414930150f682b34b4dc326b Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Thu, 26 Sep 2024 13:18:23 +0200 Subject: [PATCH] feat: do multi stage build Signed-off-by: Robert Waffen --- Dockerfile | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1f0a19bc..e6e34653 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:3.3.5-slim-bookworm +FROM ruby:3.3.5-slim-bookworm AS builder RUN apt update && apt install -y \ g++ \ @@ -17,19 +17,30 @@ RUN apt update && apt install -y \ tzdata \ && rm -rf /var/lib/apt/lists/* -ENV APP_HOME /hdm -ENV RAILS_ENV production -ENV HDM_PORT 3000 -ENV HDM_HOST 0.0.0.0 +ENV APP_HOME=/hdm +WORKDIR $APP_HOME + +COPY . $APP_HOME +COPY config/hdm.yml.template $APP_HOME/config/hdm.yml + +RUN bundle check || (bundle config set --local without 'development test release' && bundle install) + +############################################################################### + +FROM ruby:3.3.5-slim-bookworm + +ENV APP_HOME=/hdm +ENV RAILS_ENV=production +ENV HDM_PORT=3000 +ENV HDM_HOST=0.0.0.0 ENV RUBYOPT="--yjit" EXPOSE $HDM_PORT WORKDIR $APP_HOME -COPY . $APP_HOME -COPY config/hdm.yml.template $APP_HOME/config/hdm.yml - -RUN bundle check || (bundle config set --local without 'development test' && bundle install) +# copy only the needed files from the builder image +COPY --from=builder /usr/local/bundle /usr/local/bundle +COPY --from=builder $APP_HOME $APP_HOME CMD ["sh", "-c", "/hdm/bin/entry.sh ${HDM_PORT} ${HDM_HOST}"]