ぼざクリ タグ広場 https://hub.nizika.monster
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.
 
 
 
 
 
 

70 lines
2.2 KiB

  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 backend .
  5. # docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name backend backend
  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.2.2
  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 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. # Final stage for app image
  37. FROM base
  38. # Copy built artifacts: gems, application
  39. COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
  40. COPY --from=build /rails /rails
  41. # Run and own only the runtime files as a non-root user for security
  42. RUN groupadd --system --gid 1000 rails && \
  43. useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
  44. chown -R rails:rails db log storage tmp
  45. USER 1000:1000
  46. # Entrypoint prepares the database.
  47. ENTRYPOINT ["/rails/bin/docker-entrypoint"]
  48. # Start server via Thruster by default, this can be overwritten at runtime
  49. EXPOSE 80
  50. CMD ["./bin/thrust", "./bin/rails", "server"]