Guest User

Untitled

a guest
Oct 27th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. # syntax=docker/dockerfile:1
  2. # check=error=true
  3.  
  4. # This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
  5. # docker build -t jumpstart .
  6. # docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name jumpstart jumpstart
  7.  
  8. # For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
  9.  
  10. # Make sure RUBY_VERSION matches the Ruby version in .ruby-version
  11. ARG RUBY_VERSION=3.3
  12. FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim AS base
  13.  
  14.  
  15.  
  16. # Rails app lives here
  17. WORKDIR /rails
  18.  
  19. # Install base packages
  20. RUN apt-get update -qq && \
  21. apt-get install --no-install-recommends -y curl wget libjemalloc2 libvips sqlite3 postgresql-client && \
  22. rm -rf /var/lib/apt/lists /var/cache/apt/archives
  23.  
  24.  
  25. # Install dependencies for Chrome
  26. RUN apt-get update -qq && \
  27. apt-get install --no-install-recommends -y \
  28. wget \
  29. gnupg2 \
  30. ca-certificates
  31.  
  32. # Add Google Chrome repository and install Chrome properly
  33. RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && \
  34. echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && \
  35. apt-get update -qq && \
  36. apt-get install -y google-chrome-stable && \
  37. rm -rf /var/lib/apt/lists/*
  38.  
  39. # Update the PATH to use the properly installed Chrome
  40. ENV CHROME_PATH=/usr/bin/google-chrome
  41. ENV PATH="${PATH}:/usr/bin"
  42.  
  43. # Set environment variables
  44. ENV PATH="${PATH}:/opt/chrome/opt/google/chrome"
  45.  
  46.  
  47. # Set production environment
  48. ENV RAILS_ENV="production" \
  49. BUNDLE_DEPLOYMENT="1" \
  50. BUNDLE_PATH="/usr/local/bundle" \
  51. BUNDLE_WITHOUT="development"
  52.  
  53. # Throw-away build stage to reduce size of final image
  54. FROM base AS build
  55.  
  56. # Install packages needed to build gems and node modules
  57. RUN apt-get update -qq && \
  58. apt-get install --no-install-recommends -y build-essential git libpq-dev node-gyp pkg-config python-is-python3 imagemagick libvips libvips-dev libvips-tools poppler-utils && \
  59. rm -rf /var/lib/apt/lists /var/cache/apt/archives
  60.  
  61. # Install JavaScript dependencies
  62. ARG NODE_VERSION=20.17.0
  63. ARG YARN_VERSION=1.22.22
  64. ENV PATH=/usr/local/node/bin:$PATH
  65. RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
  66. /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
  67. npm install -g yarn@$YARN_VERSION && \
  68. rm -rf /tmp/node-build-master
  69.  
  70. # Install application gems
  71. COPY Gemfile Gemfile.jumpstart Gemfile.lock ./.ruby-version ./
  72. COPY ./lib/jumpstart/ ./lib/jumpstart/
  73. COPY ./config/jumpstart.yml* ./config/jumpstart.yml
  74. RUN bundle install && \
  75. rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
  76. bundle exec bootsnap precompile --gemfile
  77.  
  78. RUN gem install foreman
  79.  
  80. # Install node modules
  81. COPY package.json yarn.lock ./
  82. RUN yarn install --frozen-lockfile
  83.  
  84. # Copy application code
  85. COPY . .
  86.  
  87. # Precompile bootsnap code for faster boot times
  88. RUN bundle exec bootsnap precompile app/ lib/
  89.  
  90. # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
  91. RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
  92.  
  93.  
  94. # Final stage for app image
  95. FROM base
  96.  
  97. # Copy built artifacts: gems, application
  98. COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
  99. COPY --from=build /rails /rails
  100.  
  101. # Run and own only the runtime files as a non-root user for security
  102. RUN groupadd --system --gid 1000 rails && \
  103. useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
  104. chown -R rails:rails db log storage tmp
  105. USER 1000:1000
  106.  
  107. # Entrypoint prepares the database.
  108. ENTRYPOINT ["./bin/docker-entrypoint"]
  109.  
  110. # Start the server by default, this can be overwritten at runtime
  111. EXPOSE 3000
  112. CMD ["./bin/rails", "server"]
  113. #CMD ["foreman", "start"]
  114.  
Advertisement
Add Comment
Please, Sign In to add comment