Skip to content

Commit

Permalink
Remove package litter after each install to shrink layer sizes (#51792)
Browse files Browse the repository at this point in the history
* Remove package litter after each install to shrink layer sizes

* Need a refresh on the index when the cache is gone
  • Loading branch information
dhh committed May 12, 2024
1 parent 3af5c07 commit d539810
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions railties/lib/rails/generators/rails/app/templates/Dockerfile.tt
Expand Up @@ -12,7 +12,8 @@ WORKDIR /rails

# Install base packages
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y <%= dockerfile_base_packages.join(" ") %>
apt-get install --no-install-recommends -y <%= dockerfile_base_packages.join(" ") %> && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Set production environment
ENV RAILS_ENV="production" \
Expand All @@ -24,7 +25,9 @@ ENV RAILS_ENV="production" \
FROM base as build

# Install packages needed to build gems<%= using_node? ? " and node modules" : "" %>
RUN apt-get install --no-install-recommends -y <%= dockerfile_build_packages.join(" ") %>
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y <%= dockerfile_build_packages.join(" ") %> && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

<% if using_node? -%>
# Install JavaScript dependencies
Expand Down Expand Up @@ -88,9 +91,6 @@ RUN rm -rf node_modules
# Final stage for app image
FROM base

# Clean up installation packages to reduce image size
RUN rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails
Expand Down

0 comments on commit d539810

Please sign in to comment.