Dockerfile 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 the docker configuration to the correct location
  21. COPY config/database.yml.docker config/database.yml
  22. # Compile our assets, moving unneeded directories out of way for the prod image
  23. # after compilation has completed.
  24. RUN rails assets:precompile && \
  25. rm -rf tmp/cache log && \
  26. mkdir -p /var/cache/app/app && \
  27. mv node_modules spec /var/cache/app && \
  28. mv app/assets /var/cache/app/app
  29. ################################################################################
  30. FROM base AS dev
  31. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  32. COPY --from=builder /app/ /app/
  33. COPY --from=builder /var/cache/app/ /app/
  34. ################################################################################
  35. # We want a tiny image, so don't start from base
  36. FROM ruby:2.6.3-alpine AS prod
  37. ENV RAILS_ENV=production
  38. RUN apk add --update --no-cache $RUBY_PACKAGES
  39. # (Re)install only dependencies we need for prod instead of copying everything
  40. # from the builder
  41. RUN bundle install --jobs 4 --retry 5 --without development test
  42. # Grab the app with all compiled assets and docker configuration from builder
  43. COPY --from=builder /app/ /app/
  44. # Run the server
  45. EXPOSE 3000
  46. CMD ["rails", "server", "-b", "0.0.0.0"]