# syntax=docker/dockerfile:1

FROM ruby:3.3.7-slim

WORKDIR /rails

# docker-compose.yml overrides RAILS_ENV=development for local dev.
ENV RAILS_ENV=production \
    BUNDLE_PATH=/usr/local/bundle

RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y \
      build-essential \
      default-libmysqlclient-dev \
      default-mysql-client \
      git \
      libyaml-dev \
      curl && \
    rm -rf /var/lib/apt/lists/*

COPY Gemfile Gemfile.lock ./
RUN bundle config set --local deployment 'true' && \
    bundle config set --local without 'development:test' && \
    bundle install && \
    bundle exec ruby -e "require 'rotp'; abort('rotp gem missing — check Gemfile.lock') unless defined?(::ROTP)"

COPY . .
RUN chmod +x bin/docker-entrypoint bin/prepare-aiven-ssl bin/rails bin/rake

EXPOSE 3000

ENTRYPOINT ["./bin/docker-entrypoint"]
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
