Dockerfile 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. FROM ruby:2.6.3-alpine AS base
  2. ARG BUILD_PACKAGES="build-base git"
  3. ARG DEV_PACKAGES="postgresql-dev nodejs 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 add --update --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 vendor/assets spec
  25. # Copy the docker configurations over
  26. COPY config/database.yml.docker config/database.yml
  27. ################################################################################
  28. # We want a tiny image, so don't start from base
  29. FROM ruby:2.6.3-alpine AS prod
  30. ENV RAILS_ENV=production
  31. RUN apk add --update --no-cache $RUBY_PACKAGES
  32. # Grab everything from the builder
  33. COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
  34. COPY --from=builder /app/ /app/
  35. # Run the server
  36. EXPOSE 3000
  37. CMD ["rails", "server", "-b", "0.0.0.0"]