Skip to content

Feature Request: Add compression level configuration option #1597

@iwata

Description

@iwata

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 | best

And/or a CLI flag:

ko build --compression-level=9 ./cmd/app

Alternatives Considered

  1. Use smaller base images: Already using distroless/chainguard static (~2-3MB)
  2. Strip binaries: Already using -s -w ldflags
  3. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions