mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
bake: compose parser should only error if there are neither build nor image fields
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
@ -2,6 +2,7 @@ package bake
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/docker/cli/cli/compose/loader"
|
||||
composetypes "github.com/docker/cli/cli/compose/types"
|
||||
@ -28,6 +29,7 @@ func ParseCompose(dt []byte) (*Config, error) {
|
||||
}
|
||||
|
||||
var c Config
|
||||
var zeroBuildConfig composetypes.BuildConfig
|
||||
if len(cfg.Services) > 0 {
|
||||
c.Group = map[string]Group{}
|
||||
c.Target = map[string]Target{}
|
||||
@ -36,6 +38,14 @@ func ParseCompose(dt []byte) (*Config, error) {
|
||||
|
||||
for _, s := range cfg.Services {
|
||||
|
||||
if reflect.DeepEqual(s.Build, zeroBuildConfig) {
|
||||
// if not make sure they're setting an image or it's invalid d-c.yml
|
||||
if s.Image == "" {
|
||||
return nil, fmt.Errorf("compose file invalid: service %s has neither an image nor a build context specified. At least one must be provided.", s.Name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
var contextPathP *string
|
||||
if s.Build.Context != "" {
|
||||
contextPath := s.Build.Context
|
||||
@ -46,14 +56,6 @@ func ParseCompose(dt []byte) (*Config, error) {
|
||||
dockerfilePath := s.Build.Dockerfile
|
||||
dockerfilePathP = &dockerfilePath
|
||||
}
|
||||
// Check if there's actually a dockerfile mentioned
|
||||
if dockerfilePathP == nil && contextPathP == nil {
|
||||
// if not make sure they're setting an image or it's invalid d-c.yml
|
||||
if s.Image == "" {
|
||||
return nil, fmt.Errorf("Compose file invalid: Service %s has neither an image nor a build context specified. At least one must be provided.", s.Name)
|
||||
}
|
||||
break
|
||||
}
|
||||
g.Targets = append(g.Targets, s.Name)
|
||||
t := Target{
|
||||
Context: contextPathP,
|
||||
|
Reference in New Issue
Block a user