2019-12-31 12:53:18 +00:00
|
|
|
# pre-build stage
|
2020-11-20 10:08:13 +00:00
|
|
|
FROM ruby:2.7.2-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 \
|
2020-02-03 08:17:32 +00:00
|
|
|
git \
|
2019-12-31 12:53:18 +00:00
|
|
|
&& 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 \
|
2020-05-08 06:43:23 +00:00
|
|
|
bundle config set without 'development test'; bundle install -j 4 -r 3; \
|
2019-12-05 11:12:46 +00:00
|
|
|
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 \
|
2020-03-22 15:08:49 +00:00
|
|
|
SECRET_KEY_BASE=precompile_placeholder RAILS_LOG_TO_STDOUT=enabled bundle exec rake assets:precompile; \
|
2019-12-31 12:53:18 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# final build stage
|
2020-11-20 10:08:13 +00:00
|
|
|
FROM ruby:2.7.2-alpine
|
2019-12-31 12:53:18 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-05-08 06:43:23 +00:00
|
|
|
# Remove unnecessary files
|
2020-04-05 06:41:50 +00:00
|
|
|
RUN rm -rf /gems/ruby/2.7.0/cache/*.gem \
|
|
|
|
&& find /gems/ruby/2.7.0/gems/ -name "*.c" -delete \
|
|
|
|
&& find /gems/ruby/2.7.0/gems/ -name "*.o" -delete
|
2019-12-31 12:53:18 +00:00
|
|
|
|
2020-04-30 16:02:34 +00:00
|
|
|
# creating a log directory so that image wont fail when RAILS_LOG_TO_STDOUT is false
|
|
|
|
# https://github.com/chatwoot/chatwoot/issues/701
|
|
|
|
RUN mkdir -p /app/log
|
|
|
|
|
2019-12-31 12:53:18 +00:00
|
|
|
WORKDIR /app
|