Guest User

Untitled

a guest
Mar 28th, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.65 KB | None | 0 0
  1. # syntax=docker/dockerfile:1
  2. # check=error=true
  3.  
  4. # Make sure RUBY_VERSION matches the Ruby version in .ruby-version
  5. ARG RUBY_VERSION=3.0.5
  6. FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
  7.  
  8. # Rails app lives here
  9. WORKDIR /rails
  10.  
  11. # Install base packages
  12. RUN apt-get update -qq && \
  13.     apt-get install --no-install-recommends -y curl libjemalloc2 libvips libpq-dev && \
  14.     rm -rf /var/lib/apt/lists /var/cache/apt/archives
  15.  
  16. # Set production environment
  17. ENV RAILS_ENV="production" \
  18.     BUNDLE_DEPLOYMENT="1" \
  19.     BUNDLE_PATH="/usr/local/bundle" \
  20.     BUNDLE_WITHOUT="development"
  21.  
  22. # Throw-away build stage to reduce size of final image
  23. FROM base AS build
  24.  
  25. # Install packages needed to build gems
  26. RUN apt-get update -qq && \
  27.     apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config && \
  28.     rm -rf /var/lib/apt/lists /var/cache/apt/archives
  29.  
  30. # Install application gems
  31. COPY Gemfile Gemfile.lock ./
  32. RUN gem install bundler:2.4.19 && \
  33.     bundle install && \
  34.     rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
  35.     bundle exec bootsnap precompile --gemfile
  36.  
  37. # Copy application code
  38. COPY . .
  39.  
  40. # Final stage for app image
  41. FROM base
  42.  
  43. # Copy built artifacts: gems, application
  44. COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
  45. COPY --from=build /rails /rails
  46.  
  47. # Run and own only the runtime files as a non-root user for security
  48. RUN groupadd --system --gid 1000 rails && \
  49.     useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
  50.     chown -R rails:rails db log storage tmp
  51. USER 1000:1000
  52.  
  53. # Entrypoint prepares the database.
  54. ENTRYPOINT ["/rails/bin/docker-entrypoint"]
  55.  
Advertisement
Add Comment
Please, Sign In to add comment