@@ -28,7 +28,7 @@ import (
28
28
29
29
// checkConsistency validate a compose model is consistent
30
30
func checkConsistency (project * types.Project ) error {
31
- for _ , s := range project .Services {
31
+ for name , s := range project .Services {
32
32
if s .Build == nil && s .Image == "" {
33
33
return fmt .Errorf ("service %q has neither an image nor a build context specified: %w" , s .Name , errdefs .ErrInvalid )
34
34
}
@@ -38,6 +38,18 @@ func checkConsistency(project *types.Project) error {
38
38
return fmt .Errorf ("service %q declares mutualy exclusive dockerfile and dockerfile_inline: %w" , s .Name , errdefs .ErrInvalid )
39
39
}
40
40
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
+
41
53
if len (s .Build .Platforms ) > 0 && s .Platform != "" {
42
54
var found bool
43
55
for _ , platform := range s .Build .Platforms {
0 commit comments