content: # syntax = docker/dockerfile:1
  
  # docker build -t my-app .
  # docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY=<value from config/master.key> my-app
  # Make sure RUBY_VERSION matches the Ruby version in .ruby-version
  ARG RUBY_VERSION=3.3.6
  ARG DISTRO_NAME=bookworm
  
  FROM ruby:$RUBY_VERSION-slim-$DISTRO_NAME AS base
  
  ARG DISTRO_NAME
  
  # Rails app lives here
  WORKDIR /rails
  
  # Install the correct version of bundler
  RUN gem install bundler:2.5.16
  
  # Install base packages
  RUN apt-get update -qq && \
      apt-get install --no-install-recommends -y curl libjemalloc2 libvips gnupg2 less build-essential git pkg-config jq vim mkcert libnss3-tools && \
      rm -rf /var/lib/apt/lists /var/cache/apt/archives
  
  # Install PostgreSQL dependencies
  ARG PG_MAJOR
  RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
      gpg --dearmor -o /usr/share/keyrings/postgres-archive-keyring.gpg \
      && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/postgres-archive-keyring.gpg] https://apt.postgresql.org/pub/repos/apt/" \
      $DISTRO_NAME-pgdg main $PG_MAJOR | tee /etc/apt/sources.list.d/postgres.list > /dev/null
  RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt,sharing=locked \
    --mount=type=tmpfs,target=/var/log \
    apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
    DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
      libpq-dev \
      postgresql-client-$PG_MAJOR
  
  # Set dev environment
  ENV RAILS_ENV="development" \
      BUNDLE_DEPLOYMENT="1" \
      BUNDLE_PATH="/usr/local/bundle" \
      BUNDLE_JOBS=4 \
      BUNDLE_RETRY=3
  
  # Copy application code
  COPY . .
  RUN bundle install
  