From 27ab09e3436b895861d6870cddd21a6c33e24cb3 Mon Sep 17 00:00:00 2001 From: Felix Eckhofer <felix@eckhofer.com> Date: Thu, 13 Mar 2025 10:49:09 +0100 Subject: [PATCH] Switch back to -slim image for final stage to decrease image size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This requires us to duplicate environment variables. The commit also disables --reproducible mode for kaniko – our images are not reproducible in the first place (because we run apt-update) and using the option leads to weird dates being shown for the images. Closes #58 --- .gitlab-ci.yml | 1 - Dockerfile | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3d0dcd5..4634060 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,7 +24,6 @@ docker-image: --context "${CI_PROJECT_DIR}" --dockerfile "${CI_PROJECT_DIR}/Dockerfile" --destination "${DOCKER_IMAGE_NAME}" - --reproducible rules: - if: $CI_COMMIT_BRANCH exists: diff --git a/Dockerfile b/Dockerfile index c1c0afb..0272d2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,10 @@ # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile # renovate: datasource=docker depName=registry.docker.com/library/ruby ARG RUBY_VERSION=3.4.2 -FROM registry.docker.com/library/ruby:$RUBY_VERSION AS base + +# ################################################################### +# Throw-away build stage to reduce size of final image +FROM registry.docker.com/library/ruby:$RUBY_VERSION AS build # Rails app lives here WORKDIR /rails @@ -14,10 +17,6 @@ ENV RAILS_ENV="production" \ BUNDLE_PATH="/usr/local/bundle" \ BUNDLE_WITHOUT="development" - -# Throw-away build stage to reduce size of final image -FROM base AS build - # Install packages needed to build gems RUN apt-get update -qq && \ apt-get install --no-install-recommends -y build-essential git libvips pkg-config @@ -38,8 +37,18 @@ RUN bundle exec bootsnap precompile app/ lib/ RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile +# ################################################################### # Final stage for app image -FROM base +FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim + +# Rails app lives here +WORKDIR /rails + +# Set production environment +ENV RAILS_ENV="production" \ + BUNDLE_DEPLOYMENT="1" \ + BUNDLE_PATH="/usr/local/bundle" \ + BUNDLE_WITHOUT="development" # Install packages needed for deployment RUN apt-get update -qq && \ -- GitLab