2019-12-31 12:53:18 +00:00
|
|
|
# pre-build stage
|
2021-08-03 14:41:52 +00:00
|
|
|
FROM ruby:3.0.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
|
|
|
|
|
|
|
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
|
|
|
|
2021-08-12 09:40:02 +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-05 11:12:46 +00:00
|
|
|
# generate production assets if production environment
|
|
|
|
RUN if [ "$RAILS_ENV" = "production" ]; then \
|
2021-08-12 09:40:02 +00:00
|
|
|
SECRET_KEY_BASE=precompile_placeholder RAILS_LOG_TO_STDOUT=enabled bundle exec rake assets:precompile \
|
|
|
|
&& rm -rf spec node_modules tmp/cache; \
|
2019-12-31 12:53:18 +00:00
|
|
|
fi
|
|
|
|
|
2021-08-12 09:40:02 +00:00
|
|
|
# Remove unnecessary files
|
|
|
|
RUN rm -rf /gems/ruby/3.0.0/cache/*.gem \
|
|
|
|
&& find /gems/ruby/3.0.0/gems/ \( -name "*.c" -o -name "*.o" \) -delete
|
|
|
|
|
2019-12-31 12:53:18 +00:00
|
|
|
# final build stage
|
2021-08-03 14:41:52 +00:00
|
|
|
FROM ruby:3.0.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
|
|
|
|
|
2021-08-12 09:40:02 +00:00
|
|
|
RUN if [ "$RAILS_ENV" != "production" ]; then \
|
|
|
|
apk add nodejs yarn; \
|
2019-12-31 12:53:18 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
COPY --from=pre-builder /gems/ /gems/
|
|
|
|
COPY --from=pre-builder /app /app
|
|
|
|
|
|
|
|
WORKDIR /app
|
2021-08-12 09:40:02 +00:00
|
|
|
|
|
|
|
EXPOSE 3000
|