Dockerfile 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 && apk add --no-cache $BUILD_PACKAGES $DEV_PACKAGES $RUBY_PACKAGES
  6. RUN mkdir /app
  7. WORKDIR /app
  8. ################################################################################
  9. FROM base AS builder
  10. # Copying the Gemfile separately allows the image to be cached.
  11. # These steps are not rerun unless the Gemfile or Gemfile.lock is changed.
  12. COPY Gemfile Gemfile.lock /app/
  13. RUN bundle install --jobs 4 --retry 5
  14. # Again, copy seperately so we can cache this step.
  15. COPY package.json yarn.lock /app/
  16. RUN yarn install && yarn cache clean
  17. # Copy our app over now
  18. COPY . /app
  19. # Copy the docker configuration to the correct location
  20. COPY config/database.yml.docker config/database.yml
  21. # Compile our assets, moving unneeded directories out of way for the prod image
  22. # after compilation has completed.
  23. RUN rails assets:precompile && \
  24. rm -rf tmp/cache log && \
  25. mkdir -p /var/cache/app/app && \
  26. mv node_modules spec /var/cache/app && \
  27. mv app/assets /var/cache/app/app
  28. ################################################################################
  29. FROM base AS dev
  30. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  31. COPY --from=builder /app/ /app/
  32. COPY --from=builder /var/cache/app/ /app/
  33. ################################################################################
  34. # We want a tiny image, so don't start from base
  35. FROM ruby:2.6.3-alpine AS prod
  36. ENV RAILS_ENV=production
  37. RUN apk add --update --no-cache $RUBY_PACKAGES
  38. # (Re)install only dependencies we need for prod instead of copying everything
  39. # from the builder
  40. RUN bundle install --jobs 4 --retry 5 --without development test
  41. # Grab the app with all compiled assets and docker configuration from builder
  42. COPY --from=builder /app/ /app/
  43. # Run the server
  44. EXPOSE 3000
  45. CMD ["rails", "server", "-b", "0.0.0.0"]