Dockerfile 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # Add git to clone Rspec repositories and build-base to compile nokogiri gem
  6. # Additionally, we need to set timezone information
  7. RUN apk update && apk add --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 log 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 spec/ /app/spec/
  36. # (Re)install the missing development dependencies
  37. RUN bundle install --jobs 4 --retry 5 --with development test && \
  38. yarn install
  39. ################################################################################
  40. # We want a tiny image, so don't start from base
  41. FROM ruby:2.6.3-alpine AS prod
  42. ENV RAILS_ENV=production
  43. RUN apk add --update --no-cache $RUBY_PACKAGES
  44. # Grab everything from the builder
  45. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  46. COPY --from=builder /app/ /app/
  47. # Run the server
  48. EXPOSE 3000
  49. CMD ["rails", "server", "-b", "0.0.0.0"]