mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
vendor: update compose-go to v2.0.2
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
74
vendor/github.com/compose-spec/compose-go/v2/cli/options.go
generated
vendored
74
vendor/github.com/compose-spec/compose-go/v2/cli/options.go
generated
vendored
@ -217,7 +217,10 @@ func WithLoadOptions(loadOptions ...func(*loader.Options)) ProjectOptionsFn {
|
||||
// profiles specified via the COMPOSE_PROFILES environment variable otherwise.
|
||||
func WithDefaultProfiles(profile ...string) ProjectOptionsFn {
|
||||
if len(profile) == 0 {
|
||||
profile = strings.Split(os.Getenv(consts.ComposeProfiles), ",")
|
||||
for _, s := range strings.Split(os.Getenv(consts.ComposeProfiles), ",") {
|
||||
profile = append(profile, strings.TrimSpace(s))
|
||||
}
|
||||
|
||||
}
|
||||
return WithProfiles(profile)
|
||||
}
|
||||
@ -379,7 +382,7 @@ var DefaultFileNames = []string{"compose.yaml", "compose.yml", "docker-compose.y
|
||||
// DefaultOverrideFileNames defines the Compose override file names for auto-discovery (in order of preference)
|
||||
var DefaultOverrideFileNames = []string{"compose.override.yml", "compose.override.yaml", "docker-compose.override.yml", "docker-compose.override.yaml"}
|
||||
|
||||
func (o ProjectOptions) GetWorkingDir() (string, error) {
|
||||
func (o *ProjectOptions) GetWorkingDir() (string, error) {
|
||||
if o.WorkingDir != "" {
|
||||
return filepath.Abs(o.WorkingDir)
|
||||
}
|
||||
@ -395,7 +398,7 @@ func (o ProjectOptions) GetWorkingDir() (string, error) {
|
||||
return os.Getwd()
|
||||
}
|
||||
|
||||
func (o ProjectOptions) GeConfigFiles() ([]types.ConfigFile, error) {
|
||||
func (o *ProjectOptions) GeConfigFiles() ([]types.ConfigFile, error) {
|
||||
configPaths, err := o.getConfigPaths()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -427,39 +430,66 @@ func (o ProjectOptions) GeConfigFiles() ([]types.ConfigFile, error) {
|
||||
return configs, err
|
||||
}
|
||||
|
||||
// ProjectFromOptions load a compose project based on command line options
|
||||
func ProjectFromOptions(ctx context.Context, options *ProjectOptions) (*types.Project, error) {
|
||||
configs, err := options.GeConfigFiles()
|
||||
// LoadProject loads compose file according to options and bind to types.Project go structs
|
||||
func (o *ProjectOptions) LoadProject(ctx context.Context) (*types.Project, error) {
|
||||
configDetails, err := o.prepare()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
workingDir, err := options.GetWorkingDir()
|
||||
project, err := loader.LoadWithContext(ctx, configDetails, o.loadOptions...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
options.loadOptions = append(options.loadOptions,
|
||||
withNamePrecedenceLoad(workingDir, options),
|
||||
withConvertWindowsPaths(options),
|
||||
withListeners(options))
|
||||
|
||||
project, err := loader.LoadWithContext(ctx, types.ConfigDetails{
|
||||
ConfigFiles: configs,
|
||||
WorkingDir: workingDir,
|
||||
Environment: options.Environment,
|
||||
}, options.loadOptions...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, config := range configs {
|
||||
for _, config := range configDetails.ConfigFiles {
|
||||
project.ComposeFiles = append(project.ComposeFiles, config.Filename)
|
||||
}
|
||||
|
||||
return project, nil
|
||||
}
|
||||
|
||||
// LoadModel loads compose file according to options and returns a raw (yaml tree) model
|
||||
func (o *ProjectOptions) LoadModel(ctx context.Context) (map[string]any, error) {
|
||||
configDetails, err := o.prepare()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return loader.LoadModelWithContext(ctx, configDetails, o.loadOptions...)
|
||||
}
|
||||
|
||||
// prepare converts ProjectOptions into loader's types.ConfigDetails and configures default load options
|
||||
func (o *ProjectOptions) prepare() (types.ConfigDetails, error) {
|
||||
configs, err := o.GeConfigFiles()
|
||||
if err != nil {
|
||||
return types.ConfigDetails{}, err
|
||||
}
|
||||
|
||||
workingDir, err := o.GetWorkingDir()
|
||||
if err != nil {
|
||||
return types.ConfigDetails{}, err
|
||||
}
|
||||
|
||||
configDetails := types.ConfigDetails{
|
||||
ConfigFiles: configs,
|
||||
WorkingDir: workingDir,
|
||||
Environment: o.Environment,
|
||||
}
|
||||
|
||||
o.loadOptions = append(o.loadOptions,
|
||||
withNamePrecedenceLoad(workingDir, o),
|
||||
withConvertWindowsPaths(o),
|
||||
withListeners(o))
|
||||
return configDetails, nil
|
||||
}
|
||||
|
||||
// ProjectFromOptions load a compose project based on command line options
|
||||
// Deprecated: use ProjectOptions.LoadProject or ProjectOptions.LoadModel
|
||||
func ProjectFromOptions(ctx context.Context, options *ProjectOptions) (*types.Project, error) {
|
||||
return options.LoadProject(ctx)
|
||||
}
|
||||
|
||||
func withNamePrecedenceLoad(absWorkingDir string, options *ProjectOptions) func(*loader.Options) {
|
||||
return func(opts *loader.Options) {
|
||||
if options.Name != "" {
|
||||
|
Reference in New Issue
Block a user