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 demo .
6- # docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name demo demo
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
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 ruby:$RUBY_VERSION-slim AS base
12+ FROM docker.io/library/ 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-
2117# Install base packages
2218RUN apt-get update -qq && \
23- apt-get install --no-install-recommends -y curl libjemalloc2 postgresql-client && \
19+ apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client && \
2420 rm -rf /var/lib/apt/lists /var/cache/apt/archives
2521
2622# Set production environment
27- ENV BUNDLE_DEPLOYMENT="1" \
23+ ENV RAILS_ENV="production" \
24+ BUNDLE_DEPLOYMENT="1" \
2825 BUNDLE_PATH="/usr/local/bundle" \
29- BUNDLE_WITHOUT="development:test" \
30- RAILS_ENV="production"
31-
26+ BUNDLE_WITHOUT="development"
3227
3328# Throw-away build stage to reduce size of final image
3429FROM base AS build
3530
3631# Install packages needed to build gems
3732RUN apt-get update -qq && \
38- apt-get install --no-install-recommends -y build-essential libpq-dev libyaml-dev && \
33+ apt-get install --no-install-recommends -y build-essential git libpq-dev libyaml-dev pkg-config && \
3934 rm -rf /var/lib/apt/lists /var/cache/apt/archives
4035
4136# Install application gems
42- COPY Gemfile Gemfile.lock ./
37+ COPY Gemfile Gemfile.lock vendor ./
38+
4339RUN bundle install && \
4440 rm -rf ~/.bundle/ "${BUNDLE_PATH}" /ruby/*/cache "${BUNDLE_PATH}" /ruby/*/bundler/gems/*/.git && \
4541 bundle exec bootsnap precompile --gemfile
@@ -54,21 +50,20 @@ RUN bundle exec bootsnap precompile app/ lib/
5450RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
5551
5652
53+
54+
5755# Final stage for app image
5856FROM base
5957
60-
6158# Copy built artifacts: gems, application
6259COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
6360COPY --from=build /rails /rails
6461
6562# Run and own only the runtime files as a non-root user for security
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 && \
63+ RUN groupadd --system --gid 1000 rails && \
64+ useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
7065 chown -R rails:rails db log storage tmp
71- USER rails:rails
66+ USER 1000:1000
7267
7368# Entrypoint prepares the database.
7469ENTRYPOINT ["/rails/bin/docker-entrypoint" ]
0 commit comments