Files

68 lines
1.9 KiB
Docker
Raw Permalink Normal View History

2026-05-18 13:17:28 -04:00
# syntax = docker/dockerfile:1
2026-09-16 12:41:44 -04:00
# 1. Base Stage: Common dependencies
2026-05-18 13:17:28 -04:00
ARG RUBY_VERSION=3.3.1
2026-09-16 12:41:44 -04:00
FROM ruby:$RUBY_VERSION-slim as base
2026-05-18 13:17:28 -04:00
2026-09-16 12:41:44 -04:00
WORKDIR /rails
2026-05-18 13:17:28 -04:00
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
2026-09-16 12:41:44 -04:00
BUNDLE_WITHOUT="development:test"
2026-05-18 13:17:28 -04:00
2026-09-16 12:41:44 -04:00
# Install base packages (libvips for Active Storage, curl for healthchecks)
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y \
build-essential \
curl \
git \
libvips \
freetds-bin \
freetds-dev \
libjemalloc2 \
ruby-dev \
dos2unix && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# 2. Build Stage: Gems and Assets
FROM base as build
2026-05-18 13:17:28 -04:00
2026-09-16 12:41:44 -04:00
# Install packages needed to build gems and precompile assets
2026-05-18 13:17:28 -04:00
RUN apt-get update -qq && \
2026-09-16 12:41:44 -04:00
apt-get install --no-install-recommends -y build-essential pkg-config less && \
2026-05-18 13:17:28 -04:00
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Install application gems
2026-09-16 12:41:44 -04:00
RUN bundle config set --local frozen false
2026-05-18 13:17:28 -04:00
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile
# Copy application code
COPY . .
2026-09-16 12:41:44 -04:00
RUN bundle exec bootsnap precompile app/
2026-05-18 13:17:28 -04:00
2026-09-16 12:41:44 -04:00
# 3. Final Stage: Lean Runtime
2026-05-18 13:17:28 -04:00
FROM base
2026-09-16 12:41:44 -04:00
# Copy built artifacts: gems and precompiled assets
# COPY --from=build /rails/public /rails/public
# COPY --from=build /rails/app/javascript /rails/app/javascript
# COPY --from=build /rails/config/importmap.rb /rails/config/importmap.rb
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails
2026-05-18 13:17:28 -04:00
2026-09-16 12:41:44 -04:00
# Run as a non-privileged user for security
RUN useradd -ms /bin/bash rails
RUN chown -R rails:rails /rails
USER rails:rails
2026-05-18 13:17:28 -04:00
# Entrypoint prepares the database.
2026-09-16 12:41:44 -04:00
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
2026-05-18 13:17:28 -04:00
2026-09-16 12:41:44 -04:00
# Start the server
EXPOSE 3005
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]