Deployment and DevOps
52.1 Packaging and Running
# Dockerfile (multi-stage)
FROM ruby:3.4-slim AS build
WORKDIR /app
RUN apt-get update && apt-get install -y build-essential libpq-dev
COPY Gemfile Gemfile.lock ./
RUN bundle config set --local without "development test" && bundle install --jobs 4
COPY . .
FROM ruby:3.4-slim
WORKDIR /app
RUN apt-get update && apt-get install -y libpq5 libjemalloc2 && rm -rf /var/lib/apt/lists/*
ENV LD_PRELOAD=libjemalloc.so.2 RUBY_YJIT_ENABLE=1 MALLOC_ARENA_MAX=2
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /app /app
RUN useradd -m app && chown -R app /app
USER app
EXPOSE 3000
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]52.2 Deployment Options
Docker-based deploys to any server (the Rails 8 default) Heroku, Render, Fly.io, Railway Classic SSH-based deploys Containers at scale
AWS Elastic Beanstalk / ECS, Google Cloud Run AWS Lambda (Ruby runtime)
52.3 Operations
Process management: systemd, Foreman (Procfile), Overmind.
Configuration via environment variables (12-factor). Use dotenv for development.
Logging (structured JSON with lograge/semantic_logger), error tracking (Sentry, Honeybadger, Rollbar, AppSignal), metrics (Prometheus via yabeda), OpenTelemetry (opentelemetry-ruby).
CI: GitHub Actions (ruby/setup-ruby with a bundler cache), matrix testing across Ruby versions, RuboCop and Brakeman steps.
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
bundler-cache: true
- run: bundle exec rubocop
- run: bundle exec rspec