@@ -18,52 +18,43 @@ package compose
18
18
19
19
import (
20
20
"fmt"
21
- "os"
22
- "path/filepath"
23
21
24
- "github.com/docker/compose-cli/api/compose "
22
+ "github.com/docker/buildx/build "
25
23
"github.com/docker/compose-cli/cli/mobycli"
26
-
27
- "github.com/compose-spec/compose-go/types"
28
24
)
29
25
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
41
36
}
42
- // build args
37
+ } else {
43
38
cmd := & commandBuilder {
44
- Path : filepath . Join ( projectDir , service . Build . Context ) ,
39
+ Path : options . Inputs . ContextPath ,
45
40
}
46
- cmd .addParams ("--build-arg" , options .Args )
41
+ cmd .addParams ("--build-arg" , options .BuildArgs )
47
42
cmd .addFlag ("--pull" , options .Pull )
48
- cmd .addArg ("--progress" , options . Progress )
43
+ cmd .addArg ("--progress" , mode )
49
44
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 )
51
50
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 )
59
55
cmd .addArg ("--tag" , imageName )
60
56
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 ()... )
67
58
if err != nil {
68
59
return err
69
60
}
@@ -72,6 +63,13 @@ func (s *composeService) windowsBuild(project *types.Project, options compose.Bu
72
63
return nil
73
64
}
74
65
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
+
75
73
type commandBuilder struct {
76
74
Args []string
77
75
Path string
0 commit comments