Help us shape the future of Go! Take the 2026 Go Developer Survey

engine

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package engine wraps compose-go (v2.11.0). It is the ONLY package in cenvkit that imports compose-go; everything else consumes the plain-Go Result/ProjectView.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Flatten

func Flatten(base map[string]string, files []string, expand bool) (map[string]string, error)

Flatten resolves an ordered Layer-1 file list into a merged KEY=VALUE map, last-wins across files. It is the SINGLE expansion primitive (spec §5c, MF4): env-debug's interpolation env and the populator (cenvkit run/env) both route through it, so the same chain yields identical ${VAR} values everywhere.

It returns ONLY the parsed FILE values — base is consulted SOLELY as a ${VAR} lookup source (matching dotenv.GetEnvFromFile, which exposes the full base to every file immediately), and is NOT copied into the result. The caller owns the final overlay: e.g. the populator's shell-wins merge (internal/envmap) and env-debug's interpEnv overlay both add base/shell keys themselves. Keeping base out of the result is what makes `cenvkit env` emit only chain-derived keys.

  • expand=true → dotenv.GetEnvFromFile(base, files): in-file ${VAR}/${VAR:-def} resolve against base + already-accumulated chain values, exactly as `docker compose` reads its env files (compose-go's own primitive).
  • expand=false → per-file ParseOrderedLiteral folded last-wins: values verbatim, ${...} left UNexpanded (no third literal reader — reuses the --overview one).

files MUST contain only existing paths: GetEnvFromFile ERRORS (does not skip) on a missing file (dotenv/env.go:36), so callers feed it chain.Resolve's existence-filtered list only (MF2). base may be nil.

func HasComposeFile

func HasComposeFile(dir, composeFileEnv string) bool

HasComposeFile is the single-COMPOSE_FILE-value convenience form (still interpolates ${CENVKIT_ENV} when the value carries it AND the caller seeds CENVKIT_ENV — prefer HasComposeFileEnv from cmd code, which threads the full env).

func HasComposeFileEnv

func HasComposeFileEnv(dir string, env []string) bool

HasComposeFileEnv is the seam-correct gate: it takes the FULL seed env (the chain's Vars) so ${CENVKIT_ENV} interpolation and COMPOSE_PATH_SEPARATOR are honored, and shares resolveComposeFiles with Resolve so gate and loader cannot drift. When false, callers skip Layer-2 entirely (chain-only mode, spec §13 G4).

func ParseOrderedLiteral

func ParseOrderedLiteral(path string) ([]provenance.OverviewEntry, error)

ParseOrderedLiteral reads a dotenv-style file into ORDERED, LITERAL entries for the --overview lens AND the populator's --no-expand path (internal/envmap folds the ordered entries into a last-wins map). compose-go's dotenv parser cannot be reused here: it returns an unordered map AND expands ${...} (verified v2.11.0, plan §0). This is a thin stdlib-only line reader (keeps the engine seam — no extra compose-go surface). It mirrors dotenv's KEY tokenization (skip blank/#-comment lines; strip a leading `export `; split on the first `=`; key charset [A-Za-z0-9_.-]) but takes the VALUE verbatim — NO ${...} expansion and NO escape processing — except it strips one matching surrounding quote pair, and for an UNQUOTED value trims a trailing " # comment" + trailing space (mirrors dotenv parser.go:157-159; decision D-B).

Types

type Engine

type Engine interface {
	Resolve(ctx context.Context, in Input) (Result, error)
	Provenance(ctx context.Context, in ProvInput) (provenance.Report, error)
}

Engine is the seam. One real impl over compose-go; trivially fakeable in tests.

func New

func New() Engine

New returns the compose-go-backed Engine, pinned to v2.11.0.

type Input

type Input struct {
	ProjectDir  string   // absolute working dir
	ConfigFiles []string // explicit -f; empty => COMPOSE_FILE / default discovery
	Env         []string // chain.Result.Vars — seeds interpolation
	Profiles    []string // active profiles (M3)
}

Input describes one Layer-2 resolution request.

type ProjectView

type ProjectView struct {
	WorkingDir string
	Services   map[string][]string // service -> existing resolved env_file abs paths
}

ProjectView is a compose-go-free projection so internal/provenance and cmd never import compose-go.

type ProvFile

type ProvFile struct{ Path, Layer string } // Layer: "layer1" | "layer2"

ProvFile is one ordered COMPOSE_ENV_FILES entry tagged with its chain layer.

type ProvInput

type ProvInput struct {
	ProjectDir  string
	ConfigFiles []string // explicit -f; empty => resolveComposeFiles
	Env         []string // chain Vars "K=V" (interpolation + mapping source)
	Profiles    []string
	EnvFiles    []ProvFile // ordered merged COMPOSE_ENV_FILES (for A attribution)
	WantLayers  bool       // populate Report.Layers (the raw ordered --overview lens); off by default to keep other modes' JSON unchanged (D-A)
}

ProvInput describes one provenance request: the ordered merged env files (for chain attribution A), the chain Vars (interpolation + mapping source), and the compose config selection (for per-service env C + ${VAR} effects B-lite).

type Result

type Result struct {
	EnvFiles []string // absolute, existing, active-only, deterministically ordered, deduped
	Project  ProjectView
}

Result is the active Layer-2 env_file set, deduped & ordered, ready to append after Layer-1 into COMPOSE_ENV_FILES.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL