Detection

migetpacks detects Ruby when any of these files are present in your project root:
  • Gemfile
  • Rakefile
  • config.ru

Version Detection

Ruby version is resolved in this order: The ruby- prefix is automatically stripped (e.g., ruby-3.2.0 becomes 3.2.0).

Build Process

migetpacks generates a multi-stage Dockerfile with bundler layer caching:

Dependency Detection

migetpacks inspects your Gemfile and Gemfile.lock to install the correct system libraries: Additionally, tzdata and ca-certificates are always installed in the runtime image.

Bundler Version

The bundler version is automatically detected from Gemfile.lock (the BUNDLED WITH section) and installed in the builder stage.

Local Gems

If your Gemfile references local gems with path: options, those directories are automatically copied before bundle install to ensure they are available during gem resolution.

Rails Asset Precompilation

If your project has a Rakefile and either app/assets/ or app/javascript/ directories, migetpacks automatically:
  1. Sets RAILS_ENV=production, SECRET_KEY_BASE_DUMMY=1, and a dummy DATABASE_URL
  2. Runs bundle exec rake assets:precompile
  3. Runs bundle exec rake assets:clean

Runtime Cleanup

The following are removed from the final image:
  • .git/, .github/
  • test/, tests/, spec/, features/
  • .rspec, .rubocop*
  • vendor/bundle/ruby/*/cache/

Run Command

The default run command is determined in this order:

Runtime Environment

The following environment variables are set in the runtime container:

Caching

Docker Layer Caching

Gems are installed in a separate layer before source code is copied. bundle install is only re-run when Gemfile or Gemfile.lock changes.

BuildKit Cache Mounts

When BUILD_CACHE_DIR is configured, BuildKit cache mounts are used:

Registry Cache

Use CACHE_IMAGE to push/pull BuildKit inline cache layers to a registry for cross-build caching.

DHI Support

Ruby is fully supported with Docker Hardened Images.

DHI-Specific Behavior

The DHI runtime is distroless (no shell, no apt-get), which requires special handling: Native gem libraries are copied from the builder stage:
Process commands are transformed since shebangs do not work in distroless:
  • ./bin/rails server becomes ruby bin/rails server
  • bundle exec commands work because bundler is installed as a gem
BUNDLER_VERSION is explicitly set in the environment to prevent bundler from attempting auto-switching (which fails without /usr/bin/env).
Shell-dependent features like .profile.d scripts and shell variable expansion (${PORT:-5000}) are not available in DHI runtime images. Use environment variables directly.

Multi-Buildpack

Ruby applications commonly use Node.js for asset compilation. When package.json is detected alongside a Ruby project, Node.js is automatically added as a secondary buildpack:
See the Multi-Buildpack guide for more details.

Example

With Custom Options