Dockerfile 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 .rspec Rakefile .ruby-version /app/
  25. COPY vendor/ /app/vendor
  26. COPY config.ru /app/config.ru
  27. COPY config/ /app/config
  28. COPY config/database.yml.docker /app/config/database.yml
  29. COPY public/ /app/public
  30. COPY storage/ /app/storage
  31. COPY lib/ /app/lib
  32. COPY db/ /app/db
  33. COPY app/assets/ /app/app/assets
  34. COPY app/javascript/ /app/app/javascript
  35. # Compile our assets, moving unneeded directories out of way for the prod image
  36. # after compilation has completed.
  37. RUN rm -rf tmp/cache log && \
  38. mkdir -p /var/cache/app/app && \
  39. mv node_modules /var/cache/app
  40. ################################################################################
  41. FROM base AS dev
  42. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  43. COPY --from=builder /app/ /app/
  44. COPY --from=builder /var/cache/app/ /app/
  45. COPY spec /app/spec
  46. # Watchman is required for relay-compiler to run in watch mode
  47. COPY --from=icalialabs/watchman /usr/local/bin/watchman* /usr/local/bin/
  48. RUN mkdir -p /usr/local/var/run/watchman && \
  49. touch /usr/local/var/run/watchman/.not-empty
  50. ################################################################################
  51. FROM base AS prod
  52. # FIXME: Not production ready
  53. ENV RAILS_ENV=production
  54. # Install only required gems for production, and remove any uneccesary build
  55. # packages
  56. RUN BUNDLE_JOBS=$BUNDLE_JOBS BUNDLE_RETRY=$BUNDLE_RETRY bundle install --without development test && \
  57. apk rm $BUILD_PACKAGES $DEV_PACKAGES
  58. COPY --from=builder /app/ /app/
  59. RUN rails assets:precompile && \
  60. rm -rf /app/app/assets && \
  61. rm -rf /app/app/javascript
  62. # Run the server
  63. EXPOSE 3000
  64. CMD ["rails", "server", "-p", "3000"]