Dockerfile60 lines · 1221 chars # Stage 1: builder - install dependencies and build assets from source
FROM ruby:3.2-alpine AS builder
# Install build and asset tooling
RUN apk add --no-cache \
build-base \
git \
nodejs \
npm \
yarn \
libxml2-dev \
libxslt-dev \
zlib-dev \
yaml-dev \
bash
# Ensure a known Bundler version
RUN gem install bundler -v '2.4.22'
WORKDIR /app
# Copy the entire repository so Gemfile, gemspec, lib/ files are available for Bundler
COPY . .
# Install Ruby dependencies
RUN bundle install --jobs 4 --retry 3
# Install JS dependencies
RUN yarn install --frozen-lockfile
# Build frontend assets (Rollup)
RUN yarn build
# Stage 2: runtime - lean image with prebuilt assets and gems
FROM ruby:3.2-alpine
# Runtime dependencies (no dev/build tools)
RUN apk add --no-cache \
bash \
curl \
libxml2 \
libxslt \
zlib
WORKDIR /app
# Copy gems and application from builder
COPY --from=builder /usr/local/bundle /usr/local/bundle
COPY --from=builder /app /app
# Ensure assets directories exist for smoke tests
RUN mkdir -p /app/public/assets /app/public/packs
ENV RAILS_ENV=production
EXPOSE 3000
# Run Rails server by default
CMD ["bash", "-lc", "bundle exec rails server -b 0.0.0.0 -p 3000"]