22# check=error=true
33
44# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
5- # docker build -t test_postgresql .
6- # docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name test_postgresql test_postgresql
5+ # docker build -t demo .
6+ # docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name demo demo
77
88# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
99
1010# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
1111ARG RUBY_VERSION=xxx
12- FROM docker.io/library/ ruby:$RUBY_VERSION-slim AS base
12+ FROM ruby:$RUBY_VERSION-slim AS base
1313
1414# Rails app lives here
1515WORKDIR /rails
1616
17+ # Update gems and bundler
18+ RUN gem update --system --no-document && \
19+ gem install -N bundler
20+
1721# Install base packages
1822RUN apt-get update -qq && \
19- apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client && \
23+ apt-get install --no-install-recommends -y curl libjemalloc2 postgresql-client && \
2024 rm -rf /var/lib/apt/lists /var/cache/apt/archives
2125
2226# Set production environment
23- ENV RAILS_ENV="production" \
24- BUNDLE_DEPLOYMENT="1" \
27+ ENV BUNDLE_DEPLOYMENT="1" \
2528 BUNDLE_PATH="/usr/local/bundle" \
26- BUNDLE_WITHOUT="development"
29+ BUNDLE_WITHOUT="development:test" \
30+ RAILS_ENV="production"
31+
2732
2833# Throw-away build stage to reduce size of final image
2934FROM base AS build
3035
3136# Install packages needed to build gems
3237RUN apt-get update -qq && \
33- apt-get install --no-install-recommends -y build-essential git libpq-dev libyaml-dev pkg-config && \
38+ apt-get install --no-install-recommends -y build-essential libpq-dev libyaml-dev && \
3439 rm -rf /var/lib/apt/lists /var/cache/apt/archives
3540
3641# Install application gems
37- COPY Gemfile Gemfile.lock vendor ./
38-
42+ COPY Gemfile Gemfile.lock ./
3943RUN bundle install && \
4044 rm -rf ~/.bundle/ "${BUNDLE_PATH}" /ruby/*/cache "${BUNDLE_PATH}" /ruby/*/bundler/gems/*/.git && \
4145 bundle exec bootsnap precompile --gemfile
@@ -50,20 +54,21 @@ RUN bundle exec bootsnap precompile app/ lib/
5054RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
5155
5256
53-
54-
5557# Final stage for app image
5658FROM base
5759
60+
5861# Copy built artifacts: gems, application
5962COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
6063COPY --from=build /rails /rails
6164
6265# Run and own only the runtime files as a non-root user for security
63- RUN groupadd --system --gid 1000 rails && \
64- useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
66+ ARG UID=xxx \
67+ GID=1000
68+ RUN groupadd -f -g $GID rails && \
69+ useradd -u $UID -g $GID rails --create-home --shell /bin/bash && \
6570 chown -R rails:rails db log storage tmp
66- USER 1000:1000
71+ USER rails:rails
6772
6873# Entrypoint prepares the database.
6974ENTRYPOINT ["/rails/bin/docker-entrypoint" ]
0 commit comments