# syntax=docker/dockerfile:1# check=error=true# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:# docker build -t sample .# docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name sample sample# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html# Make sure RUBY_VERSION matches the Ruby version in .ruby-versionARG RUBY_VERSION=3.4.2FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base# Rails app lives hereWORKDIR /rails# Install base packagesRUN apt-get update -qq && \ apt-get install --no-install-recommends -y curl default-mysql-client libjemalloc2 libvips && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives# Set production environmentENV RAILS_ENV="development" \ BUNDLE_PATH="/usr/local/bundle"# Throw-away build stage to reduce size of final imageFROM base AS build# Install packages needed to build gemsRUN apt-get update -qq && \ apt-get install --no-install-recommends -y build-essential default-libmysqlclient-dev git pkg-config libyaml-dev && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives# Install application gemsCOPY Gemfile Gemfile.lock ./RUN gem install bundler -v '2.6.5' && \ bundle install && \ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ bundle exec bootsnap precompile --gemfile# Copy application codeCOPY . .# Precompile bootsnap code for faster boot timesRUN bundle exec bootsnap precompile app/ lib/# Precompiling assets for production without requiring secret RAILS_MASTER_KEYRUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile# Final stage for app imageFROM base# Copy built artifacts: gems, applicationCOPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"COPY --from=build /rails /rails# Run and own only the runtime files as a non-root user for securityRUN groupadd --system --gid 1000 rails && \ useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ chown -R rails:rails db log storage tmpUSER 1000:1000# Entrypoint prepares the database.ENTRYPOINT ["/rails/bin/docker-entrypoint"]# Start server via Thruster by default, this can be overwritten at runtimeEXPOSE 80CMD ["./bin/thrust", "./bin/rails", "server"]