Detection

migetpacks detects Bun when any of these signals are present:
Bun detection runs after backend frameworks (Ruby, Python, Go, etc.) but before Node.js. If your project has both a bun.lock and a Gemfile, it will be detected as Ruby with Bun available as a secondary buildpack.

Version Detection

Bun version is resolved in this order:

Build Process

migetpacks generates a multi-stage Dockerfile optimized for Bun:

Entry Point Detection

The entry point is automatically detected in this order:
  1. .ts/.js file referenced in scripts.start of package.json
  2. Common file patterns: index.ts, server.ts, app.ts, main.ts, src/index.ts, src/server.ts, index.js, server.js
  3. Falls back to index.ts

Build Script

If package.json contains a "build" script, bun run build is automatically executed after dependency installation. You can override this with the BUILD_COMMAND environment variable.

Lockfile Format

Bun supports two lockfile formats:
  • bun.lock (text-based, newer format)
  • bun.lockb (binary, legacy format)
Both are automatically detected and copied during the build.

Run Command

The default run command is determined in this order: The entry point is detected automatically (see Entry Point Detection above).

Caching

Docker Layer Caching

Dependencies are installed in a separate layer before source code is copied. bun install is only re-run when package.json or bun.lock/bun.lockb 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

Bun is supported with Docker Hardened Images (requires version 1.3.6 or later).
DHI images for Bun are only available starting from version 1.3.6. If your project uses an older version, migetpacks will fall back to the standard oven/bun images.
The -dev variant includes a shell for building. The runtime image is distroless with no shell, providing a minimal attack surface.

Example

With Custom Options