-
Notifications
You must be signed in to change notification settings - Fork 434
Open
Description
Summary
Add a configuration option to control the gzip compression level for container image layers.
Motivation
Currently, ko uses gzip.BestSpeed (level 1) for layer compression via go-containerregistry. While this provides the fastest build times, it results in larger image sizes compared to higher compression levels.
In our production use case, we observed:
- Docker build (multi-stage): ~30MB
- ko build: ~33MB (~10% larger)
For users who prioritize image size over build speed (e.g., for bandwidth-constrained environments or storage costs), having the option to use higher compression levels would be valuable.
Proposed Solution
Add a compression or compressionLevel option to .ko.yaml:
# Option 1: Simple level (1-9)
compression:
level: 9 # 1=BestSpeed, 9=BestCompression
# Option 2: Named presets
compression: best # speed | default | bestAnd/or a CLI flag:
ko build --compression-level=9 ./cmd/appAlternatives Considered
- Use smaller base images: Already using distroless/chainguard static (~2-3MB)
- Strip binaries: Already using
-s -wldflags - Upstream change in go-containerregistry: Would affect all users, not configurable
Additional Context
- This could be implemented by passing compression options to
tarball.LayerFromOpener()or similar - Default behavior should remain unchanged (BestSpeed) for backward compatibility
- Trade-off documentation would be helpful (build time vs image size)
Metadata
Metadata
Assignees
Labels
No labels