Skip to content

Commit

Permalink
use listener to collect include metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof authored and glours committed Feb 15, 2024
1 parent 26a5dd3 commit 9ba7b1e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 32 deletions.
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

0 comments on commit 9ba7b1e

Please sign in to comment.