Dockerfile 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. FROM ruby:2.6.3-alpine AS base
  2. ARG BUILD_PACKAGES="build-base git"
  3. ARG DEV_PACKAGES="postgresql-dev yarn"
  4. ARG RUBY_PACKAGES="tzdata"
  5. RUN apk update && \
  6. apk add --no-cache $BUILD_PACKAGES $DEV_PACKAGES $RUBY_PACKAGES
  7. RUN mkdir /app
  8. WORKDIR /app
  9. ################################################################################
  10. FROM base AS builder
  11. # Copying the Gemfile separately allows the image to be cached.
  12. # These steps are not rerun unless the Gemfile or Gemfile.lock is changed.
  13. COPY Gemfile Gemfile.lock /app/
  14. RUN bundle install --jobs 4 --retry 5
  15. # Again, copy seperately so we can cache this step.
  16. COPY package.json yarn.lock /app/
  17. RUN yarn install && yarn cache clean
  18. # Copy our app over now
  19. COPY bin/ /app/bin
  20. COPY .rspec Rakefile /app/
  21. COPY vendor/ /app/vendor
  22. COPY config.ru /app/config.ru
  23. COPY config/ /app/config
  24. COPY config/database.yml.docker /app/config/database.yml
  25. COPY public/ /app/public
  26. COPY db/ /app/db
  27. COPY app/assets/ /app/app/assets
  28. COPY app/javascript/ /app/app/javascript
  29. COPY lib/ /app/lib
  30. # Compile our assets, moving unneeded directories out of way for the prod image
  31. # after compilation has completed.
  32. RUN rails assets:precompile --trace && \
  33. rm -rf tmp/cache log && \
  34. mkdir -p /var/cache/app/app && \
  35. mv node_modules /var/cache/app && \
  36. mv app/assets /var/cache/app/app && \
  37. mv app/javascript /var/cache/app/app
  38. ################################################################################
  39. FROM base AS dev
  40. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  41. COPY --from=builder /app/ /app/
  42. COPY --from=builder /var/cache/app/ /app/
  43. COPY app/ /app/app
  44. COPY spec /app/spec
  45. ################################################################################
  46. FROM base AS prod
  47. ENV RAILS_ENV=production
  48. # Install only required gems for production, and remove any uneccesary build
  49. # packages
  50. RUN bundle install --jobs 4 --retry 5 --without development test && \
  51. apk rm $BUILD_PACKAGES $DEV_PACKAGES
  52. COPY bin/ /app/bin
  53. COPY .rspec .ruby-version Rakefile /app/
  54. COPY vendor/ /app/vendor
  55. COPY config.ru /app/config.ru
  56. COPY config/ /app/config
  57. COPY config/database.yml.docker /app/config/database.yml
  58. COPY public/ /app/public
  59. COPY db/ /app/db
  60. COPY lib/ /app/lib
  61. COPY app/ /app/app
  62. COPY --from=builder public/ /app/public
  63. # Run the server
  64. EXPOSE 3000
  65. CMD ["rails", "server", "-b", "0.0.0.0"]