Files
katenary/parser/main.go
Patrice Ferlet 4ded4d4e09 Set the compose file list using overrides
This is a hack to force the compose package to read all files provided
with the -c flag.
2024-04-03 22:08:01 +02:00

34 lines
947 B
Go

// Parser package is a wrapper around compose-go to parse compose files.
package parser
import (
"github.com/compose-spec/compose-go/cli"
"github.com/compose-spec/compose-go/types"
)
// Parse compose files and return a project. The project is parsed with dotenv, osenv and profiles.
func Parse(profiles []string, dockerComposeFile ...string) (*types.Project, error) {
cli.DefaultOverrideFileNames = append(cli.DefaultOverrideFileNames, "compose.katenary.yaml")
if len(dockerComposeFile) == 0 {
cli.DefaultOverrideFileNames = append(cli.DefaultOverrideFileNames, dockerComposeFile...)
}
options, err := cli.NewProjectOptions(nil,
cli.WithProfiles(profiles),
cli.WithDefaultConfigPath,
cli.WithOsEnv,
cli.WithDotEnv,
cli.WithNormalization(true),
cli.WithInterpolation(true),
cli.WithResolvedPaths(false),
//cli.WithResolvedPaths(true),
)
if err != nil {
return nil, err
}
return cli.ProjectFromOptions(options)
}