Skip to content

Commit 3487b65

Browse files
committed
Collapse fake multi-stage build into single stage
The "build" stage was the final stage in the Dockerfile, so the multi-stage split did nothing — all build tools ended up in the published image anyway. Merge both stages into one and combine the apt-get installs into a single RUN to reduce layers. https://claude.ai/code/session_01GgxFojxadiw6FgKrketpn3
1 parent b59a8d6 commit 3487b65

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

ruby/Dockerfile

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
ARG RUBY_VERSION
2-
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
2+
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim
33

44
# The app lives here
55
WORKDIR /app
66

7-
# Install base packages
7+
# Install base packages and packages needed to build gems
88
RUN apt-get update -qq \
99
&& apt-get install --no-install-recommends -y \
10+
build-essential \
1011
curl \
12+
git \
13+
libpq-dev \
14+
libyaml-dev \
15+
pkg-config \
1116
postgresql-client \
1217
&& rm -rf /var/lib/apt/lists /var/cache/apt/archives
1318

14-
# Non-root user for runtime stages (USER not set here so build stage keeps root)
19+
# Non-root user for downstream runtime stages
1520
RUN useradd --system --uid 1000 app && chown app:app /app
1621

1722
# Set production environment
@@ -20,18 +25,5 @@ ENV BUNDLE_DEPLOYMENT="1" \
2025
BUNDLE_CACHE_PATH="/usr/local/bundle/cache" \
2126
BUNDLE_WITHOUT="development"
2227

23-
# Throw-away build stage to reduce size of final image
24-
FROM base as build
25-
26-
# Install packages needed to build gems
27-
RUN apt-get update -qq \
28-
&& apt-get install --no-install-recommends -y \
29-
build-essential \
30-
git \
31-
libpq-dev \
32-
libyaml-dev \
33-
pkg-config \
34-
&& rm -rf /var/lib/apt/lists /var/cache/apt/archives
35-
3628
# This can be overwritten at runtime
3729
CMD ["ruby", "-v"]

0 commit comments

Comments
 (0)