# syntax=docker/dockerfile:1.4
# Fast app image — gems come from deps base (custom/dena-deps:1).
# Rebuild deps when Gemfile.lock changes:  docker build -f Dockerfile.deps -t custom/dena-deps:1 .
ARG DEPS_IMAGE=custom/dena-deps:1
FROM ${DEPS_IMAGE} AS base

ARG RAILS_ENV=production
ENV RAILS_ENV=${RAILS_ENV} \
    APP_HOME=/home/app

USER app
WORKDIR $APP_HOME

COPY --chown=app:app . .

RUN echo "# This file was overridden by default during docker image build." > Gemfile.plugin \
 && ruby ./bin/init_config \
 && chmod +x ./bin/logger \
 && bundle exec rake tmp:create

EXPOSE 3000
CMD ["bundle", "exec", "puma", "--config", "config/puma.rb"]

FROM base

COPY --chown=app:app Gemfile.plugin Gemfile.lock $APP_HOME/

RUN bundle install --path /opt/vendor/bundle --jobs $(nproc)
