Detection

migetpacks detects Rust when any of these files are present in your project root:
  • Cargo.toml
  • Cargo.lock

Version Detection

Rust version is resolved in this order:

Build Process

migetpacks generates a multi-stage Dockerfile with an optimized dependency caching strategy:

Dependency Caching Strategy

Rust’s dependency caching uses a “dummy source” technique:
  1. Copy Cargo.toml and Cargo.lock
  2. Create a minimal fn main() {} source file
  3. Run cargo build --release to compile all dependencies
  4. Remove the dummy source
  5. Copy the real source code
  6. Touch src/main.rs to invalidate only the application crate
  7. Rebuild — only the application code recompiles
This ensures that dependency compilation is cached across builds when only source code changes.

Binary Detection

The binary name is automatically detected from Cargo.toml:
  1. [[bin]] section name field
  2. [package] section name field
  3. Falls back to app

Workspace Projects

For workspace projects (when [workspace] is present in Cargo.toml), all workspace member Cargo.toml files are copied for proper dependency resolution.

Static Assets

If your project contains static/, public/, assets/, templates/, dist/, or build/ directories, they are automatically copied alongside the binary to the runtime image.

Run Command

The default run command is determined in this order:
Procfile commands referencing ./target/release/binary are automatically translated to ./app since the binary is copied to the application root during build.

Runtime Environment

The following environment variables are set in the runtime container:

Caching

Docker Layer Caching

The dummy-source technique ensures that cargo build --release for dependencies is cached when only source code changes. A full dependency rebuild only happens when Cargo.toml or Cargo.lock is modified.

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

Rust is fully supported with Docker Hardened Images.
The -dev variant includes a shell and build tools (cargo, rustc). The runtime image is distroless with no shell, providing a minimal attack surface. Since Rust produces static binaries, the distroless runtime works without any special handling.

Example

With Custom Options

Workspace Project