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. mv app/javascript /var/cache/app/app
  30. ################################################################################
  31. FROM base AS dev
  32. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  33. COPY --from=builder /app/ /app/
  34. COPY --from=builder /var/cache/app/ /app/
  35. ################################################################################
  36. FROM base AS prod
  37. ENV RAILS_ENV=production
  38. # Install only required gems for production, and remove any uneccesary build
  39. # packages
  40. RUN bundle install --jobs 4 --retry 5 --without development test && \
  41. apk rm $BUILD_PACKAGES $DEV_PACKAGES
  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"]