@@ -28,7 +28,7 @@ import (
2828
2929// checkConsistency validate a compose model is consistent
3030func checkConsistency (project * types.Project ) error {
31- for _ , s := range project .Services {
31+ for name , s := range project .Services {
3232 if s .Build == nil && s .Image == "" {
3333 return fmt .Errorf ("service %q has neither an image nor a build context specified: %w" , s .Name , errdefs .ErrInvalid )
3434 }
@@ -38,6 +38,18 @@ func checkConsistency(project *types.Project) error {
3838 return fmt .Errorf ("service %q declares mutualy exclusive dockerfile and dockerfile_inline: %w" , s .Name , errdefs .ErrInvalid )
3939 }
4040
41+ for add , c := range s .Build .AdditionalContexts {
42+ if target , ok := strings .CutPrefix (c , types .ServicePrefix ); ok {
43+ t , err := project .GetService (target )
44+ if err != nil {
45+ return fmt .Errorf ("service %q declares unknown service %q as additional contexts %s" , name , target , add )
46+ }
47+ if t .Build == nil {
48+ return fmt .Errorf ("service %q declares non-buildable service %q as additional contexts %s" , name , target , add )
49+ }
50+ }
51+ }
52+
4153 if len (s .Build .Platforms ) > 0 && s .Platform != "" {
4254 var found bool
4355 for _ , platform := range s .Build .Platforms {
0 commit comments