2023-12-06 15:24:02 +01:00
|
|
|
// 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) {
|
|
|
|
|
2024-04-03 21:35:04 +02:00
|
|
|
cli.DefaultOverrideFileNames = append(cli.DefaultOverrideFileNames, "compose.katenary.yaml")
|
2023-12-06 15:24:02 +01:00
|
|
|
|
2024-04-03 22:08:01 +02:00
|
|
|
if len(dockerComposeFile) == 0 {
|
|
|
|
cli.DefaultOverrideFileNames = append(cli.DefaultOverrideFileNames, dockerComposeFile...)
|
|
|
|
}
|
|
|
|
|
2023-12-06 15:24:02 +01:00
|
|
|
options, err := cli.NewProjectOptions(nil,
|
|
|
|
cli.WithProfiles(profiles),
|
|
|
|
cli.WithDefaultConfigPath,
|
|
|
|
cli.WithOsEnv,
|
|
|
|
cli.WithDotEnv,
|
|
|
|
cli.WithNormalization(true),
|
|
|
|
cli.WithInterpolation(true),
|
2024-04-03 14:15:50 +02:00
|
|
|
cli.WithResolvedPaths(false),
|
2024-04-03 21:35:04 +02:00
|
|
|
|
2023-12-06 15:24:02 +01:00
|
|
|
//cli.WithResolvedPaths(true),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return cli.ProjectFromOptions(options)
|
|
|
|
}
|