# TurboVault Production Dockerfile # Multi-stage build for optimized image size # Stage 1: Build environment 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 \ nodejs \ npm \ git \ curl && \ rm -rf /var/lib/apt/lists/* # Set working directory WORKDIR /app # Install gems COPY Gemfile Gemfile.lock ./ RUN bundle config set --local deployment 'true' && \ bundle config set --local without 'development test' && \ bundle install --jobs 4 --retry 3 # Copy application code COPY . . # Precompile assets RUN bundle exec rails assets:precompile # Stage 2: Runtime environment FROM ruby:3.3-slim # Install runtime dependencies RUN apt-get update -qq && \ apt-get install -y --no-install-recommends \ libpq5 \ curl \ ca-certificates && \ rm -rf /var/lib/apt/lists/* # Create app user RUN groupadd -r app && useradd -r -g app app # Set working directory WORKDIR /app # Copy gems from builder COPY --from=builder /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"]