Dockerfile 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. RUN mkdir /app
  40. WORKDIR /app
  41. # (Re)install only dependencies we need for prod instead of copying everything
  42. # from the builder
  43. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  44. # Grab the app with all compiled assets and docker configuration from builder
  45. COPY --from=builder /app/ /app/
  46. # Run the server
  47. EXPOSE 3000
  48. CMD ["rails", "server", "-b", "0.0.0.0"]