Dockerfile 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. FROM ruby:2.6.3-alpine AS base
  2. ARG BUILD_PACKAGES="build-base git"
  3. ARG DEV_PACKAGES="postgresql-dev nodejs yarn"
  4. ARG RUBY_PACKAGES="tzdata"
  5. # Add git to clone Rspec repositories and build-base to compile nokogiri gem
  6. # Additionally, we need to set timezone information
  7. RUN apk add --update --no-cache $BUILD_PACKAGES $DEV_PACKAGES $RUBY_PACKAGES
  8. # Make an app directory, just like Heroku.
  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 install --jobs 4 --retry 5 --without development test
  17. # Again, copy seperately so we can cache this step.
  18. COPY package.json yarn.lock /app/
  19. RUN yarn install
  20. # Copy our app over now
  21. COPY . /app
  22. # And compile our assets, removing unneeded node_modules directory afterwards
  23. RUN rails assets:precompile && \
  24. rm -rf node_modules tmp/cache app/assets vendor/assets spec
  25. # Copy the docker configurations over
  26. COPY config/database.yml.docker config/database.yml
  27. ################################################################################
  28. FROM base AS dev
  29. ENV RAILS_ENV=development
  30. # We want to include all of our dependencies, so grab what we have already
  31. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  32. COPY --from=builder /app/ /app/
  33. # Re-add items removed from the builder
  34. COPY app/assets/ /app/app/assets/
  35. COPY vendor/assets/ /app/vendor/assets/
  36. COPY spec/ /app/spec/
  37. # (Re)install the missing development dependencies
  38. RUN bundle install --jobs 4 --retry 5 --with development test && \
  39. yarn install
  40. ################################################################################
  41. # We want a tiny image, so don't start from base
  42. FROM ruby:2.6.3-alpine AS prod
  43. ENV RAILS_ENV=production
  44. RUN apk add --update --no-cache $RUBY_PACKAGES
  45. # Grab everything from the builder
  46. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  47. COPY --from=builder /app/ /app/
  48. # Run the server
  49. EXPOSE 3000
  50. CMD ["rails", "server", "-b", "0.0.0.0"]