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.0.5
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
43
vendor/github.com/compose-spec/compose-go/loader/normalize.go
generated
vendored
43
vendor/github.com/compose-spec/compose-go/loader/normalize.go
generated
vendored
@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
// normalize compose project by moving deprecated attributes to their canonical position and injecting implicit defaults
|
||||
func normalize(project *types.Project) error {
|
||||
func normalize(project *types.Project, resolvePaths bool) error {
|
||||
absWorkingDir, err := filepath.Abs(project.WorkingDir)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -41,6 +41,10 @@ func normalize(project *types.Project) error {
|
||||
}
|
||||
project.ComposeFiles = absComposeFiles
|
||||
|
||||
if project.Networks == nil {
|
||||
project.Networks = make(map[string]types.NetworkConfig)
|
||||
}
|
||||
|
||||
// If not declared explicitly, Compose model involves an implicit "default" network
|
||||
if _, ok := project.Networks["default"]; !ok {
|
||||
project.Networks["default"] = types.NetworkConfig{}
|
||||
@ -72,8 +76,9 @@ func normalize(project *types.Project) error {
|
||||
}
|
||||
localContext := absPath(project.WorkingDir, s.Build.Context)
|
||||
if _, err := os.Stat(localContext); err == nil {
|
||||
s.Build.Context = localContext
|
||||
s.Build.Dockerfile = absPath(localContext, s.Build.Dockerfile)
|
||||
if resolvePaths {
|
||||
s.Build.Context = localContext
|
||||
}
|
||||
} else {
|
||||
// might be a remote http/git context. Unfortunately supported "remote" syntax is highly ambiguous
|
||||
// in moby/moby and not defined by compose-spec, so let's assume runtime will check
|
||||
@ -82,17 +87,22 @@ func normalize(project *types.Project) error {
|
||||
}
|
||||
s.Environment = s.Environment.Resolve(fn)
|
||||
|
||||
err := relocateLogDriver(s)
|
||||
err := relocateLogDriver(&s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = relocateLogOpt(s)
|
||||
err = relocateLogOpt(&s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = relocateDockerfile(s)
|
||||
err = relocateDockerfile(&s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = relocateScale(&s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -105,6 +115,21 @@ func normalize(project *types.Project) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func relocateScale(s *types.ServiceConfig) error {
|
||||
scale := uint64(s.Scale)
|
||||
if scale != 1 {
|
||||
logrus.Warn("`scale` is deprecated. Use the `deploy.replicas` element")
|
||||
if s.Deploy == nil {
|
||||
s.Deploy = &types.DeployConfig{}
|
||||
}
|
||||
if s.Deploy.Replicas != nil && *s.Deploy.Replicas != scale {
|
||||
return errors.Wrap(errdefs.ErrInvalid, "can't use both 'scale' (deprecated) and 'deploy.replicas'")
|
||||
}
|
||||
s.Deploy.Replicas = &scale
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func absComposeFiles(composeFiles []string) ([]string, error) {
|
||||
absComposeFiles := make([]string, len(composeFiles))
|
||||
for i, composeFile := range composeFiles {
|
||||
@ -191,7 +216,7 @@ func relocateExternalName(project *types.Project) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func relocateLogOpt(s types.ServiceConfig) error {
|
||||
func relocateLogOpt(s *types.ServiceConfig) error {
|
||||
if len(s.LogOpt) != 0 {
|
||||
logrus.Warn("`log_opts` is deprecated. Use the `logging` element")
|
||||
if s.Logging == nil {
|
||||
@ -208,7 +233,7 @@ func relocateLogOpt(s types.ServiceConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func relocateLogDriver(s types.ServiceConfig) error {
|
||||
func relocateLogDriver(s *types.ServiceConfig) error {
|
||||
if s.LogDriver != "" {
|
||||
logrus.Warn("`log_driver` is deprecated. Use the `logging` element")
|
||||
if s.Logging == nil {
|
||||
@ -223,7 +248,7 @@ func relocateLogDriver(s types.ServiceConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func relocateDockerfile(s types.ServiceConfig) error {
|
||||
func relocateDockerfile(s *types.ServiceConfig) error {
|
||||
if s.Dockerfile != "" {
|
||||
logrus.Warn("`dockerfile` is deprecated. Use the `build` element")
|
||||
if s.Build == nil {
|
||||
|
Reference in New Issue
Block a user