diff --git a/Dockerfile b/Dockerfile index 0a9f2cd..98eb6d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,9 +19,10 @@ FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base WORKDIR /rails # Install base packages -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y curl libjemalloc2 libvips libpq-dev nodejs telnet imagemagick && \ - rm -rf /var/lib/apt/lists /var/cache/apt/archives +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt update -qq && apt-get --no-install-recommends install -y curl libjemalloc2 libvips libpq-dev nodejs telnet imagemagick && \ + rm -rf /var/lib/apt/lists /var/cache/apt/archives # Set production environment ENV RAILS_ENV="production" \ @@ -33,9 +34,10 @@ ENV RAILS_ENV="production" \ FROM base AS build # Install packages needed to build gems and node modules -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y build-essential git libyaml-dev node-gyp pkg-config python-is-python3 && \ - rm -rf /var/lib/apt/lists /var/cache/apt/archives +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt update -qq && apt-get --no-install-recommends install -y build-essential git libyaml-dev node-gyp pkg-config python-is-python3 && \ + rm -rf /var/lib/apt/lists /var/cache/apt/archives # Install JavaScript dependencies ARG NODE_VERSION=22.16.0 @@ -48,13 +50,16 @@ RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz # Install application gems COPY Gemfile Gemfile.lock ./ -RUN bundle install && \ +RUN --mount=type=cache,target=/root/.gem \ + bundle install && \ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ bundle exec bootsnap precompile --gemfile # Install node modules COPY package.json yarn.lock ./ -RUN yarn install --immutable +ENV YARN_CACHE_FOLDER=/root/.yarn-cache +RUN --mount=type=cache,target=/root/.yarn-cache \ + yarn install --immutable # Copy application code COPY . . @@ -65,7 +70,6 @@ RUN bundle exec bootsnap precompile app/ lib/ # Precompiling assets for production without requiring secret RAILS_MASTER_KEY RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile - RUN rm -rf node_modules