2019-12-31 12:53:18 +00:00
|
|
|
# pre-build stage
|
|
|
|
FROM ruby:2.6.5-alpine AS pre-builder
|
2019-11-23 19:57:39 +00:00
|
|
|
|
2019-12-05 11:12:46 +00:00
|
|
|
# ARG default to production settings
|
|
|
|
# For development docker-compose file overrides ARGS
|
|
|
|
ARG BUNDLE_WITHOUT="development:test"
|
|
|
|
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
|
2019-12-31 12:53:18 +00:00
|
|
|
ENV BUNDLER_VERSION=2.1.2
|
2019-12-05 11:12:46 +00:00
|
|
|
|
|
|
|
ARG RAILS_SERVE_STATIC_FILES=true
|
|
|
|
ENV RAILS_SERVE_STATIC_FILES ${RAILS_SERVE_STATIC_FILES}
|
|
|
|
|
|
|
|
ARG RAILS_ENV=production
|
|
|
|
ENV RAILS_ENV ${RAILS_ENV}
|
|
|
|
|
2019-12-31 12:53:18 +00:00
|
|
|
ENV BUNDLE_PATH="/gems"
|
|
|
|
|
|
|
|
RUN apk update \
|
|
|
|
&& apk add \
|
|
|
|
openssl \
|
|
|
|
tar \
|
|
|
|
build-base \
|
|
|
|
tzdata \
|
|
|
|
postgresql-dev \
|
2019-12-22 17:23:18 +00:00
|
|
|
postgresql-client \
|
2019-12-31 12:53:18 +00:00
|
|
|
nodejs \
|
|
|
|
yarn \
|
|
|
|
&& mkdir -p /var/app \
|
|
|
|
&& gem install bundler
|
2019-11-23 19:57:39 +00:00
|
|
|
|
|
|
|
RUN mkdir -p /app
|
|
|
|
WORKDIR /app
|
|
|
|
|
2019-12-05 11:12:46 +00:00
|
|
|
COPY Gemfile Gemfile.lock ./
|
|
|
|
|
|
|
|
# Do not install development or test gems in production
|
|
|
|
RUN if [ "$RAILS_ENV" = "production" ]; then \
|
|
|
|
bundle install -j 4 -r 3 --without development test; \
|
|
|
|
else bundle install -j 4 -r 3; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
COPY package.json yarn.lock ./
|
|
|
|
RUN yarn install
|
|
|
|
|
|
|
|
COPY . /app
|
2019-11-28 18:04:21 +00:00
|
|
|
|
2019-12-05 11:12:46 +00:00
|
|
|
# generate production assets if production environment
|
|
|
|
RUN if [ "$RAILS_ENV" = "production" ]; then \
|
|
|
|
SECRET_KEY_BASE=precompile_placeholder bundle exec rake assets:precompile; \
|
2019-12-31 12:53:18 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# final build stage
|
|
|
|
FROM ruby:2.6.5-alpine
|
|
|
|
|
|
|
|
ARG BUNDLE_WITHOUT="development:test"
|
|
|
|
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
|
|
|
|
ENV BUNDLER_VERSION=2.1.2
|
|
|
|
|
|
|
|
ARG EXECJS_RUNTIME="Disabled"
|
|
|
|
ENV EXECJS_RUNTIME ${EXECJS_RUNTIME}
|
|
|
|
|
|
|
|
ARG RAILS_SERVE_STATIC_FILES=true
|
|
|
|
ENV RAILS_SERVE_STATIC_FILES ${RAILS_SERVE_STATIC_FILES}
|
|
|
|
|
|
|
|
ARG RAILS_ENV=production
|
|
|
|
ENV RAILS_ENV ${RAILS_ENV}
|
|
|
|
ENV BUNDLE_PATH="/gems"
|
|
|
|
|
|
|
|
RUN apk add --update --no-cache \
|
|
|
|
openssl \
|
|
|
|
tzdata \
|
|
|
|
postgresql-client \
|
2020-01-07 17:29:17 +00:00
|
|
|
imagemagick \
|
2019-12-31 12:53:18 +00:00
|
|
|
&& gem install bundler
|
|
|
|
|
|
|
|
RUN if [ "$RAILS_ENV" = "production" ]; then \
|
|
|
|
rm -rf spec node_modules app/assets vendor/assets tmp/cache; \
|
|
|
|
else apk add nodejs yarn; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
COPY --from=pre-builder /gems/ /gems/
|
|
|
|
COPY --from=pre-builder /app /app
|
|
|
|
|
|
|
|
# Remove unecessary files
|
|
|
|
RUN rm -rf /gems/ruby/2.6.0/cache/*.gem \
|
|
|
|
&& find /gems/ruby/2.6.0/gems/ -name "*.c" -delete \
|
|
|
|
&& find /gems/ruby/2.6.0/gems/ -name "*.o" -delete
|
|
|
|
|
|
|
|
WORKDIR /app
|