|
@@ -27,6 +27,7 @@ import (
|
|
|
"github.com/docker/cli/cli/command"
|
|
"github.com/docker/cli/cli/command"
|
|
|
cliopts "github.com/docker/cli/opts"
|
|
cliopts "github.com/docker/cli/opts"
|
|
|
ui "github.com/docker/compose/v2/pkg/progress"
|
|
ui "github.com/docker/compose/v2/pkg/progress"
|
|
|
|
|
+ "github.com/docker/compose/v2/pkg/utils"
|
|
|
buildkit "github.com/moby/buildkit/util/progress/progressui"
|
|
buildkit "github.com/moby/buildkit/util/progress/progressui"
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
@@ -145,6 +146,8 @@ func runBuild(ctx context.Context, dockerCli command.Cli, backend api.Service, o
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ services = addBuildDependencies(services, project)
|
|
|
|
|
+
|
|
|
if err := applyPlatforms(project, false); err != nil {
|
|
if err := applyPlatforms(project, false); err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
@@ -156,3 +159,21 @@ func runBuild(ctx context.Context, dockerCli command.Cli, backend api.Service, o
|
|
|
|
|
|
|
|
return backend.Build(ctx, project, apiBuildOptions)
|
|
return backend.Build(ctx, project, apiBuildOptions)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func addBuildDependencies(services []string, project *types.Project) []string {
|
|
|
|
|
+ servicesWithDependencies := utils.NewSet(services...)
|
|
|
|
|
+ for _, service := range services {
|
|
|
|
|
+ build := project.Services[service].Build
|
|
|
|
|
+ if build != nil {
|
|
|
|
|
+ for _, target := range build.AdditionalContexts {
|
|
|
|
|
+ if s, found := strings.CutPrefix(target, types.ServicePrefix); found {
|
|
|
|
|
+ servicesWithDependencies.Add(s)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if len(servicesWithDependencies) > len(services) {
|
|
|
|
|
+ return addBuildDependencies(servicesWithDependencies.Elements(), project)
|
|
|
|
|
+ }
|
|
|
|
|
+ return servicesWithDependencies.Elements()
|
|
|
|
|
+}
|