2019-12-31 12:53:18 +00:00
|
|
|
# pre-build stage
|
2022-05-27 12:03:24 +00:00
|
|
|
FROM ruby:3.0.4-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"
|
|
|
|
|
2022-06-07 14:19:32 +00:00
|
|
|
RUN apk add --no-cache \
|
2019-12-31 12:53:18 +00:00
|
|
|
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 ./
|
|
|
|
|
2021-09-28 15:19:50 +00:00
|
|
|
# natively compile grpc and protobuf to support alpine musl (dialogflow-docker workflow)
|
|
|
|
# https://github.com/googleapis/google-cloud-ruby/issues/13306
|
2022-02-23 17:57:19 +00:00
|
|
|
# adding xz as nokogiri was failing to build libxml
|
|
|
|
# https://github.com/chatwoot/chatwoot/issues/4045
|
|
|
|
RUN apk add --no-cache musl ruby-full ruby-dev gcc make musl-dev openssl openssl-dev g++ linux-headers xz
|
2021-09-28 15:19:50 +00:00
|
|
|
RUN bundle config set --local force_ruby_platform true
|
|
|
|
|
2019-12-05 11:12:46 +00:00
|
|
|
# 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
|
2022-05-27 12:03:24 +00:00
|
|
|
FROM ruby:3.0.4-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}
|
|
|
|
|
2021-09-28 15:19:50 +00:00
|
|
|
ARG BUNDLE_FORCE_RUBY_PLATFORM=1
|
|
|
|
ENV BUNDLE_FORCE_RUBY_PLATFORM ${BUNDLE_FORCE_RUBY_PLATFORM}
|
|
|
|
|
2019-12-31 12:53:18 +00:00
|
|
|
ARG RAILS_ENV=production
|
|
|
|
ENV RAILS_ENV ${RAILS_ENV}
|
|
|
|
ENV BUNDLE_PATH="/gems"
|
|
|
|
|
2022-06-07 14:19:32 +00:00
|
|
|
RUN apk add --no-cache \
|
2019-12-31 12:53:18 +00:00
|
|
|
openssl \
|
|
|
|
tzdata \
|
|
|
|
postgresql-client \
|
2020-01-07 17:29:17 +00:00
|
|
|
imagemagick \
|
2021-08-25 09:21:35 +00:00
|
|
|
git \
|
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 \
|
2022-06-07 14:19:32 +00:00
|
|
|
apk add --no-cache 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
|