# TurboVault Production Dockerfile # Multi-stage build for optimized image size # Stage 1: Builder - Full environment with all gems FROM ruby:3.3-slim AS builder # Install build dependencies RUN apt-get update -qq && \ apt-get install -y --no-install-recommends \ build-essential \ libpq-dev \ libyaml-dev \ nodejs \ npm \ git \ curl && \ rm -rf /var/lib/apt/lists/* WORKDIR /app # Install ALL gems first (needed for asset compilation) COPY Gemfile Gemfile.lock ./ RUN bundle install --jobs 4 --retry 3 # Copy application code COPY . . # Precompile assets ENV RAILS_ENV=production \ NODE_ENV=production \ SECRET_KEY_BASE=dummy RUN bundle exec rails assets:precompile # Stage 2: Production gems only FROM ruby:3.3-slim AS gems # Install build dependencies (needed to install gems with native extensions) RUN apt-get update -qq && \ apt-get install -y --no-install-recommends \ build-essential \ libpq-dev \ libyaml-dev && \ rm -rf /var/lib/apt/lists/* WORKDIR /app # Install ONLY production gems COPY Gemfile Gemfile.lock ./ RUN bundle config set --local without 'development test' && \ bundle install --jobs 4 --retry 3 # Stage 3: Runtime - Minimal final image FROM ruby:3.3-slim # Install ONLY runtime dependencies (no build tools!) RUN apt-get update -qq && \ apt-get install -y --no-install-recommends \ libpq5 \ libyaml-0-2 \ curl \ ca-certificates && \ rm -rf /var/lib/apt/lists/* # Create app user RUN groupadd -r app && useradd -r -g app app WORKDIR /app # Copy production gems from gems stage COPY --from=gems /usr/local/bundle /usr/local/bundle # Copy application code COPY --chown=app:app . . # Copy precompiled assets from builder COPY --from=builder --chown=app:app /app/public /app/public # Create necessary directories RUN mkdir -p tmp/pids tmp/cache tmp/sockets log && \ chown -R app:app tmp log # Switch to app user USER app # Expose port EXPOSE 3000 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ CMD curl -f http://localhost:3000/up || exit 1 # Start Rails server CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", "3000"]