FROM ruby:3.1

ENV BUILD_PACKAGES="apt-utils build-essential curl less nodejs sudo wget zsh libmariadb-dev libserialport-dev cron"

# throw errors if Gemfile has been modified since Gemfile.lock
RUN \
  bundle config --global frozen 1
 

WORKDIR /usr/src/app

COPY Gemfile Gemfile.lock ./

RUN \
  apt-get update -qq && \
  apt-get install -y $BUILD_PACKAGES && \
  # Fix bundler version BEFORE bundle install
  gem install bundler -v "$(grep -A 1 'BUNDLED WITH' Gemfile.lock | tail -n 1)" && \
  bundle install && \
  rm -rf /var/lib/apt/lists/*

# Copy cron file (if you use /etc/cron.d style)
COPY reportcron /etc/cron.d/reportcron
RUN chmod 0644 /etc/cron.d/reportcron && touch /var/log/cron.log

# Add entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

