# syntax = docker/dockerfile:1 # Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile ARG RUBY_VERSION=3.3.0 FROM ruby:$RUBY_VERSION-slim as base # The plug-app code lives here WORKDIR /plug-app # Set production environment ARG RAILS_ENV="production" ENV RAILS_ENV=${RAILS_ENV} \ BUNDLE_WITHOUT="staging:development:test" \ BUNDLE_DEPLOYMENT="1" # Update gems and bundler RUN gem update --system --no-document && \ gem install -N bundler # Throw-away build stages to reduce size of final image FROM base as prebuild # Install packages needed to build gems RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \ --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \ apt-get update -qq && \ apt-get install --no-install-recommends -y build-essential curl git libpq-dev libvips pkg-config python-is-python3 ca-certificates iptables iproute2 FROM prebuild as build # Install application gems COPY --link Gemfile Gemfile.lock .ruby-version ./ RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \ bundle config set app_config .bundle && \ bundle config set path /srv/vendor && \ bundle install && \ bundle exec bootsnap precompile --gemfile && \ bundle clean && \ mkdir -p vendor && \ bundle config set path vendor && \ cp -ar /srv/vendor . # Copy application code COPY --link . . # Precompile bootsnap code for faster boot times RUN bundle exec bootsnap precompile app/ lib/ # Adjust binfiles to set current working directory RUN grep -l '#!/usr/bin/env ruby' /plug-app/bin/* | xargs sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' # Final stage for app image FROM base # Install packages needed for deployment RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \ --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \ apt-get update -qq && \ apt-get install --no-install-recommends -y imagemagick libvips postgresql-client sudo git # Copy built artifacts: gems, application COPY --from=build /usr/local/bundle /usr/local/bundle COPY --from=build /plug-app /plug-app # Deployment options ENV RAILS_LOG_TO_STDOUT="1" \ RAILS_SERVE_STATIC_FILES="true" \ RUBY_YJIT_ENABLE="1" \ LD_PRELOAD=${LD_PRELOAD_PATH} \ MALLOC_CONF="dirty_decay_ms:1000,narenas:2,background_thread:true" # Entrypoint sets up the container. ENTRYPOINT ["/plug-app/bin/docker-entrypoint"] # Start the server by default, this can be overwritten at runtime EXPOSE 3000 CMD ["./bin/rails", "server"]