mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-10 05:27:07 +08:00
update github.com/compose-spec/compose-go to v1.3.0
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
79
vendor/github.com/compose-spec/compose-go/loader/loader.go
generated
vendored
79
vendor/github.com/compose-spec/compose-go/loader/loader.go
generated
vendored
@ -17,10 +17,11 @@
|
||||
package loader
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
paths "path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
@ -42,6 +43,11 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultSeparator = "-"
|
||||
CompatibilitySeparator = "_"
|
||||
)
|
||||
|
||||
// Options supported by Load
|
||||
type Options struct {
|
||||
// Skip schema validation
|
||||
@ -66,6 +72,8 @@ type Options struct {
|
||||
projectName string
|
||||
// Indicates when the projectName was imperatively set or guessed from path
|
||||
projectNameImperativelySet bool
|
||||
// Set separator used for naming resources
|
||||
Separator string
|
||||
}
|
||||
|
||||
func (o *Options) SetProjectName(name string, imperativelySet bool) {
|
||||
@ -154,12 +162,15 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.
|
||||
LookupValue: configDetails.LookupEnv,
|
||||
TypeCastMapping: interpolateTypeCastMapping,
|
||||
},
|
||||
Separator: DefaultSeparator,
|
||||
}
|
||||
|
||||
for _, op := range options {
|
||||
op(opts)
|
||||
}
|
||||
|
||||
projectName := projectName(configDetails, opts)
|
||||
|
||||
var configs []*types.Config
|
||||
for i, file := range configDetails.ConfigFiles {
|
||||
configDict := file.Config
|
||||
@ -207,15 +218,6 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.
|
||||
s.EnvFile = newEnvFiles
|
||||
}
|
||||
|
||||
projectName, projectNameImperativelySet := opts.GetProjectName()
|
||||
model.Name = NormalizeProjectName(model.Name)
|
||||
if !projectNameImperativelySet && model.Name != "" {
|
||||
projectName = model.Name
|
||||
}
|
||||
|
||||
if projectName != "" {
|
||||
configDetails.Environment[consts.ComposeProjectName] = projectName
|
||||
}
|
||||
project := &types.Project{
|
||||
Name: projectName,
|
||||
WorkingDir: configDetails.WorkingDir,
|
||||
@ -229,7 +231,7 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.
|
||||
}
|
||||
|
||||
if !opts.SkipNormalization {
|
||||
err = normalize(project, opts.ResolvePaths)
|
||||
err = normalize(project, opts.ResolvePaths, opts.Separator)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -245,6 +247,30 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.
|
||||
return project, nil
|
||||
}
|
||||
|
||||
func projectName(details types.ConfigDetails, opts *Options) string {
|
||||
projectName, projectNameImperativelySet := opts.GetProjectName()
|
||||
var pjNameFromConfigFile string
|
||||
|
||||
for _, configFile := range details.ConfigFiles {
|
||||
yml, err := ParseYAML(configFile.Content)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if val, ok := yml["name"]; ok && val != "" {
|
||||
pjNameFromConfigFile = yml["name"].(string)
|
||||
}
|
||||
}
|
||||
pjNameFromConfigFile = NormalizeProjectName(pjNameFromConfigFile)
|
||||
if !projectNameImperativelySet && pjNameFromConfigFile != "" {
|
||||
projectName = pjNameFromConfigFile
|
||||
}
|
||||
|
||||
if _, ok := details.Environment[consts.ComposeProjectName]; !ok && projectName != "" {
|
||||
details.Environment[consts.ComposeProjectName] = projectName
|
||||
}
|
||||
return projectName
|
||||
}
|
||||
|
||||
func NormalizeProjectName(s string) string {
|
||||
r := regexp.MustCompile("[a-z0-9_-]")
|
||||
s = strings.ToLower(s)
|
||||
@ -507,12 +533,12 @@ func loadServiceWithExtends(filename, name string, servicesDict map[string]inter
|
||||
// Resolve the path to the imported file, and load it.
|
||||
baseFilePath := absPath(workingDir, *file)
|
||||
|
||||
bytes, err := ioutil.ReadFile(baseFilePath)
|
||||
b, err := os.ReadFile(baseFilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
baseFile, err := parseConfig(bytes, opts)
|
||||
baseFile, err := parseConfig(b, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -606,14 +632,25 @@ func resolveEnvironment(serviceConfig *types.ServiceConfig, workingDir string, l
|
||||
environment := types.MappingWithEquals{}
|
||||
|
||||
if len(serviceConfig.EnvFile) > 0 {
|
||||
if serviceConfig.Environment == nil {
|
||||
serviceConfig.Environment = types.MappingWithEquals{}
|
||||
}
|
||||
for _, envFile := range serviceConfig.EnvFile {
|
||||
filePath := absPath(workingDir, envFile)
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
fileVars, err := dotenv.ParseWithLookup(file, dotenv.LookupFn(lookupEnv))
|
||||
|
||||
b, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Do not defer to avoid it inside a loop
|
||||
file.Close() //nolint:errcheck
|
||||
|
||||
fileVars, err := dotenv.ParseWithLookup(bytes.NewBuffer(b), dotenv.LookupFn(lookupEnv))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -639,7 +676,7 @@ func resolveVolumePath(volume types.ServiceVolumeConfig, workingDir string, look
|
||||
// Note that this is not required for Docker for Windows when specifying
|
||||
// a local Windows path, because Docker for Windows translates the Windows
|
||||
// path into a valid path within the VM.
|
||||
if !path.IsAbs(filePath) && !isAbs(filePath) {
|
||||
if !paths.IsAbs(filePath) && !isAbs(filePath) {
|
||||
filePath = absPath(workingDir, filePath)
|
||||
}
|
||||
volume.Source = filePath
|
||||
@ -793,10 +830,8 @@ func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfi
|
||||
logrus.Warnf("%[1]s %[2]s: %[1]s.external.name is deprecated in favor of %[1]s.name", objType, name)
|
||||
obj.Name = obj.External.Name
|
||||
obj.External.Name = ""
|
||||
} else {
|
||||
if obj.Name == "" {
|
||||
obj.Name = name
|
||||
}
|
||||
} else if obj.Name == "" {
|
||||
obj.Name = name
|
||||
}
|
||||
// if not "external: true"
|
||||
case obj.Driver != "":
|
||||
@ -928,7 +963,7 @@ func cleanTarget(target string) string {
|
||||
if target == "" {
|
||||
return ""
|
||||
}
|
||||
return path.Clean(target)
|
||||
return paths.Clean(target)
|
||||
}
|
||||
|
||||
var transformBuildConfig TransformerFunc = func(data interface{}) (interface{}, error) {
|
||||
|
Reference in New Issue
Block a user