Dockerfile 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. FROM ruby:2.6.3-alpine AS base
  2. ARG BUNDLE_JOBS=${nproc}
  3. ARG BUNDLE_RETRY=5
  4. ARG BUILD_PACKAGES="build-base git"
  5. ARG DEV_PACKAGES="postgresql-dev yarn"
  6. ARG RUBY_PACKAGES="tzdata"
  7. RUN apk update && \
  8. apk add --no-cache $BUILD_PACKAGES $DEV_PACKAGES $RUBY_PACKAGES
  9. RUN mkdir /app
  10. WORKDIR /app
  11. ################################################################################
  12. FROM base AS builder
  13. # Copying the Gemfile separately allows the image to be cached.
  14. # These steps are not rerun unless the Gemfile or Gemfile.lock is changed.
  15. COPY Gemfile Gemfile.lock /app/
  16. RUN BUNDLE_JOBS=$BUNDLE_JOBS BUNDLE_RETRY=$BUNDLE_RETRY bundle install
  17. # Again, copy seperately so we can cache this step.
  18. # There is no "--no-cache" option like NPM, and won't make sense to add one with
  19. # upcoming yarn versions: https://github.com/yarnpkg/rfcs/pull/53
  20. COPY package.json yarn.lock /app/
  21. RUN yarn install && yarn cache clean
  22. # Copy our app over now
  23. COPY bin/ /app/bin
  24. COPY Rakefile /app/
  25. COPY .rspec .ruby-version tsconfig.json babel.config.js postcss.config.js \
  26. .browserslistrc .prettierrc.js .rubocop.yml .eslintrc.js /app/
  27. COPY vendor/ /app/vendor
  28. COPY config.ru /app/config.ru
  29. COPY config/ /app/config
  30. COPY config/database.yml.docker /app/config/database.yml
  31. COPY public/ /app/public
  32. COPY storage/ /app/storage
  33. COPY lib/ /app/lib
  34. COPY db/ /app/db
  35. COPY app/ /app/app
  36. # Compile our assets, moving unneeded directories out of way for the prod image
  37. # after compilation has completed.
  38. RUN rm -rf tmp/cache log && \
  39. mkdir -p /var/cache/app/app && \
  40. mv node_modules /var/cache/app
  41. ################################################################################
  42. FROM base AS dev
  43. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  44. COPY --from=builder /app/ /app/
  45. COPY --from=builder /var/cache/app/ /app/
  46. COPY spec/ /app/spec
  47. # Watchman is required for relay-compiler to run in watch mode
  48. COPY --from=icalialabs/watchman /usr/local/bin/watchman* /usr/local/bin/
  49. RUN mkdir -p /usr/local/var/run/watchman && \
  50. touch /usr/local/var/run/watchman/.not-empty
  51. ################################################################################
  52. FROM base AS prod
  53. # FIXME: Not production ready
  54. ENV RAILS_ENV=production
  55. # Install only required gems for production, and remove any uneccesary build
  56. # packages
  57. RUN BUNDLE_JOBS=$BUNDLE_JOBS BUNDLE_RETRY=$BUNDLE_RETRY bundle install --without development test && \
  58. apk rm $BUILD_PACKAGES $DEV_PACKAGES
  59. COPY --from=builder /app/ /app/
  60. RUN rails assets:precompile && \
  61. rm -rf /app/app/assets && \
  62. rm -rf /app/app/javascript
  63. # Run the server
  64. EXPOSE 3000
  65. CMD ["rails", "server", "-p", "3000"]