Dockerfile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 . /app
  20. COPY bin/ /app/bin
  21. COPY .rspec .ruby-version Rakefile /app/
  22. COPY vendor/ /app/vendor
  23. COPY config.ru /app/config.ru
  24. COPY config/ /app/config
  25. #COPY config/database.yml.docker /app/config/database.yml
  26. COPY public/ /app/public
  27. COPY db/ /app/db
  28. COPY app/assets/ /app/app/assets
  29. COPY app/javascript/ /app/app/javascript
  30. COPY lib/ /app/lib
  31. #COPY app/ /app/app
  32. #COPY spec/ /app/spec
  33. # Copy the docker configuration to the correct location
  34. #COPY config/database.yml.docker config/database.yml
  35. # Compile our assets, moving unneeded directories out of way for the prod image
  36. # after compilation has completed.
  37. RUN rails assets:precompile --trace && \
  38. rm -rf tmp/cache log && \
  39. mkdir -p /var/cache/app/app && \
  40. mv node_modules /var/cache/app && \
  41. mv app/assets /var/cache/app/app && \
  42. mv app/javascript /var/cache/app/app
  43. ################################################################################
  44. FROM base AS dev
  45. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  46. COPY --from=builder /app/ /app/
  47. COPY --from=builder /var/cache/app/ /app/
  48. COPY lib/ /app/lib
  49. COPY app/ /app/app
  50. COPY spec /app/spec
  51. ################################################################################
  52. FROM base AS prod
  53. ENV RAILS_ENV=production
  54. # Install only required gems for production, and remove any uneccesary build
  55. # packages
  56. RUN bundle install --jobs 4 --retry 5 --without development test && \
  57. apk rm $BUILD_PACKAGES $DEV_PACKAGES
  58. COPY bin/ /app/bin
  59. COPY .rspec .ruby-version Rakefile /app/
  60. COPY vendor/ /app/vendor
  61. COPY config.ru /app/config.ru
  62. COPY config/ /app/config
  63. COPY config/database.yml.docker /app/config/database.yml
  64. COPY public/ /app/public
  65. COPY db/ /app/db
  66. COPY lib/ /app/lib
  67. COPY app/ /app/app
  68. COPY --from=builder public/ /app/public
  69. # Run the server
  70. EXPOSE 3000
  71. CMD ["rails", "server", "-b", "0.0.0.0"]