Skip to content

feat(generate): compose resource limits + multi-arch platform (spec 18) - #99

Merged
gustavobertoi merged 1 commit into
mainfrom
feat/resource-limits-multiarch
Jul 1, 2026
Merged

feat(generate): compose resource limits + multi-arch platform (spec 18)#99
gustavobertoi merged 1 commit into
mainfrom
feat/resource-limits-multiarch

Conversation

@gustavobertoi

Copy link
Copy Markdown
Contributor

What

Implements the generation slice of spec 18 (resource limits + multi-arch): lower a per-service resources block and a platform: selector into the typed compose model, for both project stacks and the shared stack.

config (internal/config)

  • Service.Resources *Resources + Service.Platform, and the same on SharedSvc (shared limits declared in workspace.yaml shared.<svc>.resources).
  • Resources{ cpus, memoryMB, memoryReserveMB, pidsLimit }.
  • New cpus (positive float) and platform (os/arch[/variant]) validators with file-scoped error messages.
  • Service.EffectiveMemoryMB() / SharedSvc.EffectiveMemoryMB(): memoryMB stays the budget hint and is treated as shorthand for resources.memoryMB.

generate (internal/generate)

  • applyResources dual-writes limits from one canonical byte value: deploy.resources.limits.{cpus,memory,pids} + reservations.memory and the legacy top-level cpus/mem_limit/pids_limit, so both deploy-aware and non-deploy readers agree and compose-go/v2's cross-field consistency check passes.
  • Memory rendered as a fixed mebibyte→bytes string (768M → 805306368) for byte-stable, deterministic output.
  • platform: emitted verbatim (config overrides any template value).
  • A service with no limits emits no deploy block (no spurious diff).

profile

  • CheckBudget now sums the effective memory limit.

Why

Stops unbounded containers eating a laptop's RAM and makes the arch selector declarative — the thin generation layer of spec 18 over the existing deterministic compose pipeline.

How tested

  • CGO_ENABLED=0 go build ./... + all four release cross-builds (darwin/linux × amd64/arm64) — CGO-free holds.
  • CGO_ENABLED=1 go test ./internal/... (all pass), incl. new table-driven tests: dual-write block + agreeing bytes, platform passthrough, no-limits→no-deploy, shared limits, bytesFromMB, config parse/validation, EffectiveMemoryMB, CheckBudget.
  • gofmt -l clean, go vet ./..., make determinism green (goldens regenerated and eyeballed).

Scope note: the doctor host.ram/host.vmsize/arch.emulation probes and up --platform/emulation-warning plumbing are the "full ~1.5w" slice of spec 18 and are intentionally out of scope for this generation-focused PR.

🤖 Generated with Claude Code

Lower a per-service resources block and a platform selector into the typed
compose model (spec 18), for BOTH project and shared stacks.

- config: add Service/SharedSvc.Resources{cpus,memoryMB,memoryReserveMB,
  pidsLimit} + Platform, with cpus/platform validators and Service/SharedSvc
  EffectiveMemoryMB(). memoryMB stays the budget hint and is shorthand for
  resources.memoryMB.
- generate: applyResources dual-writes limits from one canonical byte value
  (deploy.resources.limits.* AND legacy top-level cpus/mem_limit/pids_limit)
  so compose-go/v2 cross-field consistency passes; emits platform; a service
  with no limits emits no deploy block (no spurious diff). Bytes rendered as
  a fixed mebibyte->bytes string (768M -> 805306368) for determinism.
- profile: CheckBudget sums the effective memory limit.
- goldens regenerated; new table-driven tests in config + generate.

Tested: CGO_ENABLED=0 go build ./... + all four release cross-builds,
CGO_ENABLED=1 go test ./internal/..., gofmt -l clean, go vet, make determinism.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gustavobertoi
gustavobertoi merged commit 27f7cc7 into main Jul 1, 2026
4 checks passed
@gustavobertoi
gustavobertoi deleted the feat/resource-limits-multiarch branch July 1, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant