| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- FROM ruby:2.6.3-alpine AS base
- ARG BUNDLE_JOBS=${nproc}
- ARG BUNDLE_RETRY=5
- ARG BUILD_PACKAGES="build-base git"
- ARG DEV_PACKAGES="postgresql-dev yarn"
- ARG RUBY_PACKAGES="tzdata"
- RUN apk update && \
- apk add --no-cache $BUILD_PACKAGES $DEV_PACKAGES $RUBY_PACKAGES
- RUN mkdir /app
- WORKDIR /app
- ################################################################################
- FROM base AS builder
- # Copying the Gemfile separately allows the image to be cached.
- # These steps are not rerun unless the Gemfile or Gemfile.lock is changed.
- COPY Gemfile Gemfile.lock /app/
- RUN BUNDLE_JOBS=$BUNDLE_JOBS BUNDLE_RETRY=$BUNDLE_RETRY bundle install
- # Again, copy seperately so we can cache this step.
- # There is no "--no-cache" option like NPM, and won't make sense to add one with
- # upcoming yarn versions: https://github.com/yarnpkg/rfcs/pull/53
- COPY package.json yarn.lock /app/
- RUN yarn install && yarn cache clean
- # Copy our app over now
- COPY bin/ /app/bin
- COPY Rakefile /app/
- COPY .rspec .ruby-version tsconfig.json babel.config.js postcss.config.js \
- .browserslistrc .prettierrc.js .rubocop.yml .eslintrc.js .eslintignore /app/
- COPY vendor/ /app/vendor
- COPY config.ru /app/config.ru
- COPY config/ /app/config
- COPY config/database.yml.docker /app/config/database.yml
- COPY public/ /app/public
- COPY storage/ /app/storage
- COPY lib/ /app/lib
- COPY db/ /app/db
- COPY app/ /app/app
- # Compile our assets, moving unneeded directories out of way for the prod image
- # after compilation has completed.
- RUN rm -rf tmp/cache log && \
- mkdir -p /var/cache/app/app && \
- mv node_modules /var/cache/app
- ################################################################################
- FROM base AS dev
- COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
- COPY --from=builder /app/ /app/
- COPY --from=builder /var/cache/app/ /app/
- COPY spec/ /app/spec
- # Watchman is required for relay-compiler to run in watch mode
- COPY --from=icalialabs/watchman /usr/local/bin/watchman* /usr/local/bin/
- RUN mkdir -p /usr/local/var/run/watchman && \
- touch /usr/local/var/run/watchman/.not-empty
- ################################################################################
- FROM base AS prod
- # FIXME: Not production ready
- ENV RAILS_ENV=production
- # Install only required gems for production, and remove any uneccesary build
- # packages
- RUN BUNDLE_JOBS=$BUNDLE_JOBS BUNDLE_RETRY=$BUNDLE_RETRY bundle install --without development test && \
- apk rm $BUILD_PACKAGES $DEV_PACKAGES
- COPY --from=builder /app/ /app/
- RUN rails assets:precompile && \
- rm -rf /app/app/assets && \
- rm -rf /app/app/javascript
- # Run the server
- EXPOSE 3000
- CMD ["rails", "server", "-p", "3000"]
|