Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use listener to collect include metadata #576

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions loader/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ func ApplyInclude(ctx context.Context, configDetails types.ConfigDetails, model
return err
}
for _, r := range includeConfig {
for _, listener := range options.Listeners {
listener("include", map[string]any{
"path": r.Path,
"workingdir": configDetails.WorkingDir,
})
}

for i, p := range r.Path {
for _, loader := range options.ResourceLoaders {
if loader.Accept(p) {
Expand Down
6 changes: 0 additions & 6 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,6 @@ func load(ctx context.Context, configDetails types.ConfigDetails, opts *Options,
}
loaded = append(loaded, mainFile)

includeRefs := make(map[string][]types.IncludeConfig)

dict, err := loadYamlModel(ctx, configDetails, opts, &cycleTracker{}, nil)
if err != nil {
return nil, err
Expand All @@ -496,10 +494,6 @@ func load(ctx context.Context, configDetails types.ConfigDetails, opts *Options,
return nil, err
}

if len(includeRefs) != 0 {
project.IncludeReferences = includeRefs
}

if !opts.SkipNormalization {
err := Normalize(project)
if err != nil {
Expand Down
19 changes: 0 additions & 19 deletions loader/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,6 @@ func ResolveRelativePaths(project *types.Project) error {
return err
}
project.ComposeFiles = absComposeFiles

// don't coerce a nil map to an empty map
if project.IncludeReferences != nil {
absIncludes := make(map[string][]types.IncludeConfig, len(project.IncludeReferences))
for filename, config := range project.IncludeReferences {
filename = absPath(project.WorkingDir, filename)
absConfigs := make([]types.IncludeConfig, len(config))
for i, c := range config {
absConfigs[i] = types.IncludeConfig{
Path: resolvePaths(project.WorkingDir, c.Path),
ProjectDirectory: absPath(project.WorkingDir, c.ProjectDirectory),
EnvFile: resolvePaths(project.WorkingDir, c.EnvFile),
}
}
absIncludes[filename] = absConfigs
}
project.IncludeReferences = absIncludes
}

return nil
}

Expand Down
9 changes: 2 additions & 7 deletions types/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,8 @@ type Project struct {
Configs Configs `yaml:"configs,omitempty" json:"configs,omitempty"`
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"` // https://github.com/golang/go/issues/6213

// IncludeReferences is keyed by Compose YAML filename and contains config for
// other Compose YAML files it directly triggered a load of via `include`.
//
// Note: this is
IncludeReferences map[string][]IncludeConfig `yaml:"-" json:"-"`
ComposeFiles []string `yaml:"-" json:"-"`
Environment Mapping `yaml:"-" json:"-"`
ComposeFiles []string `yaml:"-" json:"-"`
Environment Mapping `yaml:"-" json:"-"`

// DisabledServices track services which have been disable as profile is not active
DisabledServices Services `yaml:"-" json:"-"`
Expand Down