Dockerfile 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # syntax=docker/dockerfile:1
  2. # check=error=true
  3. # This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
  4. # docker build -t depot .
  5. # docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name depot depot
  6. # For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
  7. # Make sure RUBY_VERSION matches the Ruby version in .ruby-version
  8. ARG RUBY_VERSION=3.4.6
  9. FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
  10. # Rails app lives here
  11. WORKDIR /rails
  12. # Install base packages
  13. RUN apt-get update -qq && \
  14. apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \
  15. rm -rf /var/lib/apt/lists /var/cache/apt/archives
  16. # Set production environment
  17. ENV RAILS_ENV="production" \
  18. BUNDLE_DEPLOYMENT="1" \
  19. BUNDLE_PATH="/usr/local/bundle" \
  20. BUNDLE_WITHOUT="development"
  21. # Throw-away build stage to reduce size of final image
  22. FROM base AS build
  23. # Install packages needed to build gems
  24. RUN apt-get update -qq && \
  25. apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config && \
  26. rm -rf /var/lib/apt/lists /var/cache/apt/archives
  27. # Install application gems
  28. COPY Gemfile Gemfile.lock ./
  29. RUN bundle install && \
  30. rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
  31. bundle exec bootsnap precompile --gemfile
  32. # Copy application code
  33. COPY . .
  34. # Precompile bootsnap code for faster boot times
  35. RUN bundle exec bootsnap precompile app/ lib/
  36. # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
  37. RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
  38. # Final stage for app image
  39. FROM base
  40. # Copy built artifacts: gems, application
  41. COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
  42. COPY --from=build /rails /rails
  43. # Run and own only the runtime files as a non-root user for security
  44. RUN groupadd --system --gid 1000 rails && \
  45. useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
  46. chown -R rails:rails db log storage tmp
  47. USER 1000:1000
  48. # Entrypoint prepares the database.
  49. ENTRYPOINT ["/rails/bin/docker-entrypoint"]
  50. # Start server via Thruster by default, this can be overwritten at runtime
  51. EXPOSE 80
  52. CMD ["./bin/thrust", "./bin/rails", "server"]