You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

12 months ago
  1. # syntax = docker/dockerfile:1
  2. # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
  3. ARG RUBY_VERSION=3.1.2
  4. FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
  5. # Rails app lives here
  6. WORKDIR /rails
  7. # Set production environment
  8. ENV RAILS_ENV="production" \
  9. BUNDLE_DEPLOYMENT="1" \
  10. BUNDLE_PATH="/usr/local/bundle" \
  11. BUNDLE_WITHOUT="development"
  12. # Throw-away build stage to reduce size of final image
  13. FROM base as build
  14. # Install packages needed to build gems
  15. RUN apt-get update -qq && \
  16. apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config
  17. # Install application gems
  18. COPY Gemfile Gemfile.lock ./
  19. RUN bundle install && \
  20. rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
  21. bundle exec bootsnap precompile --gemfile
  22. # Copy application code
  23. COPY . .
  24. # Precompile bootsnap code for faster boot times
  25. RUN bundle exec bootsnap precompile app/ lib/
  26. # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
  27. RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
  28. # Final stage for app image
  29. FROM base
  30. # Install packages needed for deployment
  31. RUN apt-get update -qq && \
  32. apt-get install --no-install-recommends -y curl libvips postgresql-client && \
  33. rm -rf /var/lib/apt/lists /var/cache/apt/archives
  34. # Copy built artifacts: gems, application
  35. COPY --from=build /usr/local/bundle /usr/local/bundle
  36. COPY --from=build /rails /rails
  37. # Run and own only the runtime files as a non-root user for security
  38. RUN useradd rails --create-home --shell /bin/bash && \
  39. chown -R rails:rails db log storage tmp
  40. USER rails:rails
  41. # Entrypoint prepares the database.
  42. ENTRYPOINT ["/rails/bin/docker-entrypoint"]
  43. # Start the server by default, this can be overwritten at runtime
  44. EXPOSE 3000
  45. CMD ["./bin/rails", "server"]