Documentation
¶
Index ¶
- func ApplyExtends(ctx context.Context, dict map[string]any, opts *Options, tracker *cycleTracker, ...) error
- func ApplyInclude(ctx context.Context, workingDir string, environment types.Mapping, ...) error
- func InvalidProjectNameErr(v string) error
- func LoadConfigFiles(ctx context.Context, configFiles []string, workingDir string, ...) (*types.ConfigDetails, error)
- func LoadModelWithContext(ctx context.Context, configDetails types.ConfigDetails, ...) (map[string]any, error)
- func LoadWithContext(ctx context.Context, configDetails types.ConfigDetails, ...) (*types.Project, error)
- func ModelToProject(dict map[string]interface{}, opts *Options, configDetails types.ConfigDetails) (*types.Project, error)
- func Normalize(dict map[string]any, env types.Mapping) (map[string]any, error)
- func NormalizeProjectName(s string) string
- func OmitEmpty(yaml map[string]any) map[string]any
- func ResolveEnvironment(dict map[string]any, environment types.Mapping)
- func ResolveRelativePaths(project *types.Project) error
- func Transform(source interface{}, target interface{}) error
- func WithDiscardEnvFiles(opts *Options)
- func WithProfiles(profiles []string) func(*Options)
- func WithSelectedServices(services []string) func(*Options)
- func WithSkipValidation(opts *Options)
- func WithSupportedAttributes(supported []tree.Path, report func([]UnsupportedAttribute)) func(*Options)
- func WithUnsupportedAttributesCheck(patterns []UnsupportedAttributePattern, report func([]UnsupportedAttribute)) func(*Options)
- func WithoutUnnecessaryResources(opts *Options)
- type Listener
- type NoopPostProcessor
- type Options
- type PostProcessor
- type ResetProcessor
- type ResourceLoader
- type UnsupportedAttribute
- type UnsupportedAttributePattern
- type UnsupportedAttributesCheck
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyExtends ¶
func ApplyInclude ¶
func InvalidProjectNameErr ¶
func LoadConfigFiles ¶ added in v2.4.0
func LoadConfigFiles(ctx context.Context, configFiles []string, workingDir string, options ...func(*Options)) (*types.ConfigDetails, error)
LoadConfigFiles ingests config files with ResourceLoader and returns config details with paths to local copies
func LoadModelWithContext ¶
func LoadModelWithContext(ctx context.Context, configDetails types.ConfigDetails, options ...func(*Options)) (map[string]any, error)
LoadModelWithContext reads a ConfigDetails and returns a fully loaded configuration as a yaml dictionary
func LoadWithContext ¶
func LoadWithContext(ctx context.Context, configDetails types.ConfigDetails, options ...func(*Options)) (*types.Project, error)
LoadWithContext reads a ConfigDetails and returns a fully loaded configuration as a compose-go Project
func ModelToProject ¶ added in v2.8.0
func ModelToProject(dict map[string]interface{}, opts *Options, configDetails types.ConfigDetails) (*types.Project, error)
ModelToProject binds a canonical yaml dict into compose-go structs
func Normalize ¶
Normalize compose project by moving deprecated attributes to their canonical position and injecting implicit defaults
func NormalizeProjectName ¶
func ResolveEnvironment ¶ added in v2.1.4
ResolveEnvironment update the environment variables for the format {- VAR} (without interpolation)
func ResolveRelativePaths ¶
ResolveRelativePaths resolves relative paths based on project WorkingDirectory
func Transform ¶
func Transform(source interface{}, target interface{}) error
Transform converts the source into the target struct with compose types transformer and the specified transformers if any.
func WithDiscardEnvFiles ¶
func WithDiscardEnvFiles(opts *Options)
WithDiscardEnvFiles sets the Options to discard the `env_file` section after resolving to the `environment` section
func WithProfiles ¶
WithProfiles sets profiles to be activated
func WithSelectedServices ¶ added in v2.12.0
WithSelectedServices restricts the loaded project to the given services and their dependencies. An empty slice means "all services". When set, services not in the list are dropped from the project before environment resolution: their `env_file` and `label_file` entries will not be loaded from disk.
func WithSkipValidation ¶
func WithSkipValidation(opts *Options)
WithSkipValidation sets the Options to skip validation when loading sections
func WithSupportedAttributes ¶ added in v2.16.0
func WithSupportedAttributes(supported []tree.Path, report func([]UnsupportedAttribute)) func(*Options)
WithSupportedAttributes declares the attribute paths the caller's runtime implements: every attribute of the loaded model matching none of them is reported, alongside any WithUnsupportedAttributesCheck findings, through the same report callback (report may be nil when the other option already set one). Extension keys (x-*) are never reported.
This is the fail-closed side of the check: built by removing the unimplemented paths from schema.AttributePaths, it keeps reporting every newly-specified attribute until the runtime deliberately wires it in.
func WithUnsupportedAttributesCheck ¶ added in v2.16.0
func WithUnsupportedAttributesCheck(patterns []UnsupportedAttributePattern, report func([]UnsupportedAttribute)) func(*Options)
WithUnsupportedAttributesCheck registers a set of UnsupportedAttributePattern to be evaluated against the loaded model. report is invoked once, after loading, with every match found (possibly empty). Composable with WithSupportedAttributes: both feed the same walk and report.
func WithoutUnnecessaryResources ¶ added in v2.12.0
func WithoutUnnecessaryResources(opts *Options)
WithoutUnnecessaryResources drops networks/volumes/secrets/configs/models that are not referenced by services remaining after selection.
Types ¶
type NoopPostProcessor ¶ added in v2.9.1
type NoopPostProcessor struct{}
func (NoopPostProcessor) Apply ¶ added in v2.9.1
func (NoopPostProcessor) Apply(interface{}) error
type Options ¶
type Options struct {
// Skip schema validation
SkipValidation bool
// Skip interpolation
SkipInterpolation bool
// Skip normalization
SkipNormalization bool
// Resolve path
ResolvePaths bool
// Convert Windows path
ConvertWindowsPaths bool
// Skip consistency check
SkipConsistencyCheck bool
// Skip extends
SkipExtends bool
// SkipInclude will ignore `include` and only load model from file(s) set by ConfigDetails
SkipInclude bool
// SkipResolveEnvironment will ignore computing `environment` for services
SkipResolveEnvironment bool
// SkipResolveLabels will ignore resolving `label_file` into `labels` for services.
// When set, service `labels` may be incomplete: `label_file` entries are left unresolved,
// so callers must not treat `labels` as authoritative.
SkipResolveLabels bool
// SkipDefaultValues will ignore missing required attributes
SkipDefaultValues bool
// Interpolation options
Interpolate *interp.Options
// Profiles set profiles to enable
Profiles []string
// SelectedServices restricts the project model to these services (and their dependencies)
// after parsing. An empty slice means "all services". When set, services not in the list
// are dropped from the project before environment resolution, so their env_file / label_file
// entries are not loaded.
SelectedServices []string
// PruneUnnecessaryResources drops networks/volumes/secrets/configs/models that are not
// referenced by active services after service selection.
PruneUnnecessaryResources bool
// ResourceLoaders manages support for remote resources
ResourceLoaders []ResourceLoader
// KnownExtensions manages x-* attribute we know and the corresponding go structs
KnownExtensions map[string]any
// Metada for telemetry
Listeners []Listener
// MaxNodeVisits caps total YAML node visits during reset/override resolution.
// Zero means use the default. Useful for very large compose files that exceed the default cap.
MaxNodeVisits int
// UnsupportedAttributesCheck detects caller-supplied patterns identifying
// compose-file attributes not honored by the caller's runtime. See
// WithUnsupportedAttributesCheck.
UnsupportedAttributesCheck *UnsupportedAttributesCheck
// contains filtered or unexported fields
}
Options supported by Load
func ToOptions ¶ added in v2.8.0
func ToOptions(configDetails *types.ConfigDetails, options []func(*Options)) *Options
func (Options) GetProjectName ¶
func (*Options) ProcessEvent ¶
Invoke all listeners for an event
func (Options) RemoteResourceLoaders ¶
func (o Options) RemoteResourceLoaders() []ResourceLoader
RemoteResourceLoaders excludes localResourceLoader from ResourceLoaders
func (*Options) SetProjectName ¶
func (*Options) SetWorkingDirExplicit ¶ added in v2.16.0
SetWorkingDirExplicit records whether the working dir passed to LoadConfigFiles was explicitly requested by the caller (e.g. --project-directory) rather than defaulted (e.g. the current directory). A remote resource loader (git, oci) must not override an explicit working dir with the directory of its downloaded copy.
type PostProcessor ¶
type PostProcessor interface {
// Apply changes to compose model based on recorder metadata
Apply(interface{}) error
}
PostProcessor is used to tweak compose model based on metadata extracted during yaml Unmarshal phase that hardly can be implemented using go-yaml and mapstructure
type ResetProcessor ¶
type ResetProcessor struct {
// contains filtered or unexported fields
}
func (*ResetProcessor) Apply ¶
func (p *ResetProcessor) Apply(target any) error
Apply finds the go attributes matching recorded paths and reset them to zero value
func (*ResetProcessor) UnmarshalYAML ¶
func (p *ResetProcessor) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implement yaml.Unmarshaler
type ResourceLoader ¶
type ResourceLoader interface {
// Accept returns `true` is the resource reference matches ResourceLoader supported protocol(s)
Accept(path string) bool
// Load returns the path to a local copy of remote resource identified by `path`.
Load(ctx context.Context, path string) (string, error)
// Dir computes path to resource"s parent folder, made relative if possible
Dir(path string) string
}
ResourceLoader is a plugable remote resource resolver
type UnsupportedAttribute ¶ added in v2.16.0
type UnsupportedAttribute struct {
// Path locates the match in the loaded model, e.g. "services.web.deploy.mode".
Path tree.Path
// Value is whatever Path resolved to: a scalar, a map, or a list item,
// depending on the depth the matching pattern targeted.
Value any
}
UnsupportedAttribute is a single instance of a caller-supplied UnsupportedAttributePattern matching the loaded compose model.
type UnsupportedAttributePattern ¶ added in v2.16.0
type UnsupportedAttributePattern struct {
// Path is a tree.Path pattern (may use tree.PathMatchAll) identifying
// the node to inspect.
Path tree.Path
// Detect reports whether the value found at Path is unsupported. Nil
// means presence alone is unsupported. Detect may target an
// intermediate map node (not just a scalar leaf) to inspect sibling
// fields, e.g. matching a whole `ports` entry to flag only `mode: host`.
//
// Once any pattern's Path matches a node, the walk stops descending into
// that node's children regardless of what Detect returns: a pattern
// targeting a child of an already-matched node will never be evaluated
// for that occurrence.
Detect func(value any) bool
}
UnsupportedAttributePattern identifies a compose-file attribute that is schema-valid but not honored by the caller's runtime. compose-go does not know what any given runtime supports: the list of patterns is supplied by the caller.
type UnsupportedAttributesCheck ¶ added in v2.16.0
type UnsupportedAttributesCheck struct {
Patterns []UnsupportedAttributePattern
Supported []tree.Path
Report func([]UnsupportedAttribute)
}
UnsupportedAttributesCheck bundles the detection rules with the callback invoked once, after loading, with every match found (possibly empty).
Detection combines two complementary rule sets over one walk:
- Patterns is a denylist: attributes the caller knows it does not honor, with optional value predicates for cases like `ports[].mode: host`.
- Supported is an allowlist: when non-empty, every attribute matching none of its paths is reported too. It makes the screening fail-closed — an attribute the specification gains later is reported until the runtime deliberately declares it. schema.AttributePaths returns the full specification inventory to build it from (remove what the runtime does not implement); extension keys (x-*) are never reported by this rule set.