@@ -18,52 +18,43 @@ package compose
1818
1919import (
2020 "fmt"
21- "os"
22- "path/filepath"
2321
24- "github.com/docker/compose-cli/api/compose "
22+ "github.com/docker/buildx/build "
2523 "github.com/docker/compose-cli/cli/mobycli"
26-
27- "github.com/compose-spec/compose-go/types"
2824)
2925
30- func (s * composeService ) windowsBuild (project * types.Project , options compose.BuildOptions ) error {
31- projectDir := project .WorkingDir
32- for _ , service := range project .Services {
33- if service .Build != nil {
34- imageName := getImageName (service , project .Name )
35- dockerfile := service .Build .Dockerfile
36- if dockerfile != "" {
37- if stat , err := os .Stat (projectDir ); err == nil && stat .IsDir () {
38-
39- dockerfile = filepath .Join (projectDir , dockerfile )
40- }
26+ func (s * composeService ) windowsBuild (opts map [string ]build.Options , mode string ) error {
27+ for serviceName , options := range opts {
28+ imageName := serviceName
29+ dockerfile := options .Inputs .DockerfilePath
30+
31+ if options .Inputs .DockerfilePath == "-" { // image needs to be pulled
32+ imageName := options .Tags [0 ]
33+ err := shellOutMoby ("pull" , imageName )
34+ if err != nil {
35+ return err
4136 }
42- // build args
37+ } else {
4338 cmd := & commandBuilder {
44- Path : filepath . Join ( projectDir , service . Build . Context ) ,
39+ Path : options . Inputs . ContextPath ,
4540 }
46- cmd .addParams ("--build-arg" , options .Args )
41+ cmd .addParams ("--build-arg" , options .BuildArgs )
4742 cmd .addFlag ("--pull" , options .Pull )
48- cmd .addArg ("--progress" , options . Progress )
43+ cmd .addArg ("--progress" , mode )
4944
50- cmd .addList ("--cache-from" , service .Build .CacheFrom )
45+ cacheFrom := []string {}
46+ for _ , cacheImage := range options .CacheFrom {
47+ cacheFrom = append (cacheFrom , cacheImage .Attrs ["ref" ])
48+ }
49+ cmd .addList ("--cache-from" , cacheFrom )
5150 cmd .addArg ("--file" , dockerfile )
52- cmd .addParams ("--label" , service .Build .Labels )
53- cmd .addArg ("--network" , service .Build .Network )
54- cmd .addArg ("--target" , service .Build .Target )
55- cmd .addArg ("--platform" , service .Platform )
56- cmd .addArg ("--isolation" , service .Build .Isolation )
57- cmd .addList ("--add-host" , service .Build .ExtraHosts )
58-
51+ cmd .addParams ("--label" , options .Labels )
52+ cmd .addArg ("--network" , options .NetworkMode )
53+ cmd .addArg ("--target" , options .Target )
54+ cmd .addList ("--add-host" , options .ExtraHosts )
5955 cmd .addArg ("--tag" , imageName )
6056
61- args := cmd .getArguments ()
62- // shell out to moby cli
63- childExit := make (chan bool )
64- err := mobycli .RunDocker (childExit , args ... )
65- childExit <- true
66-
57+ err := shellOutMoby (cmd .getArguments ()... )
6758 if err != nil {
6859 return err
6960 }
@@ -72,6 +63,13 @@ func (s *composeService) windowsBuild(project *types.Project, options compose.Bu
7263 return nil
7364}
7465
66+ func shellOutMoby (args ... string ) error {
67+ childExit := make (chan bool )
68+ err := mobycli .RunDocker (childExit , args ... )
69+ childExit <- true
70+ return err
71+ }
72+
7573type commandBuilder struct {
7674 Args []string
7775 Path string
0 commit comments