mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Use old build for windows engine also on compose up
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
parent
487bf96ed2
commit
d5efef2aa7
@ -42,17 +42,6 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti
|
|||||||
opts := map[string]build.Options{}
|
opts := map[string]build.Options{}
|
||||||
imagesToBuild := []string{}
|
imagesToBuild := []string{}
|
||||||
|
|
||||||
// retrieve OS type
|
|
||||||
info, err := s.apiClient.Info(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if info.OSType == "windows" {
|
|
||||||
// no support yet for Windows container builds in Buildkit
|
|
||||||
// https://docs.docker.com/develop/develop-images/build_enhancements/#limitations
|
|
||||||
return s.windowsBuild(project, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, service := range project.Services {
|
for _, service := range project.Services {
|
||||||
if service.Build != nil {
|
if service.Build != nil {
|
||||||
imageName := getImageName(service, project.Name)
|
imageName := getImageName(service, project.Name)
|
||||||
@ -79,7 +68,7 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.build(ctx, project, opts, options.Progress)
|
err := s.build(ctx, project, opts, options.Progress)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if len(imagesToBuild) > 0 {
|
if len(imagesToBuild) > 0 {
|
||||||
utils.DisplayScanSuggestMsg()
|
utils.DisplayScanSuggestMsg()
|
||||||
@ -128,7 +117,7 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
|
|||||||
DockerfilePath: "-",
|
DockerfilePath: "-",
|
||||||
InStream: strings.NewReader("FROM " + service.Image),
|
InStream: strings.NewReader("FROM " + service.Image),
|
||||||
},
|
},
|
||||||
Tags: []string{service.Image},
|
Tags: []string{service.Image}, // Used to retrieve image to pull in case of windows engine
|
||||||
Pull: true,
|
Pull: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,6 +149,16 @@ func (s *composeService) localImagePresent(ctx context.Context, imageName string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) build(ctx context.Context, project *types.Project, opts map[string]build.Options, mode string) error {
|
func (s *composeService) build(ctx context.Context, project *types.Project, opts map[string]build.Options, mode string) error {
|
||||||
|
info, err := s.apiClient.Info(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.OSType == "windows" {
|
||||||
|
// no support yet for Windows container builds in Buildkit
|
||||||
|
// https://docs.docker.com/develop/develop-images/build_enhancements/#limitations
|
||||||
|
return s.windowsBuild(opts, mode)
|
||||||
|
}
|
||||||
if len(opts) == 0 {
|
if len(opts) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -18,52 +18,43 @@ package compose
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/buildx/build"
|
||||||
"github.com/docker/compose-cli/cli/mobycli"
|
"github.com/docker/compose-cli/cli/mobycli"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *composeService) windowsBuild(project *types.Project, options compose.BuildOptions) error {
|
func (s *composeService) windowsBuild(opts map[string]build.Options, mode string) error {
|
||||||
projectDir := project.WorkingDir
|
for serviceName, options := range opts {
|
||||||
for _, service := range project.Services {
|
imageName := serviceName
|
||||||
if service.Build != nil {
|
dockerfile := options.Inputs.DockerfilePath
|
||||||
imageName := getImageName(service, project.Name)
|
|
||||||
dockerfile := service.Build.Dockerfile
|
|
||||||
if dockerfile != "" {
|
|
||||||
if stat, err := os.Stat(projectDir); err == nil && stat.IsDir() {
|
|
||||||
|
|
||||||
dockerfile = filepath.Join(projectDir, dockerfile)
|
if options.Inputs.DockerfilePath == "-" { // image needs to be pulled
|
||||||
}
|
imageName := options.Tags[0]
|
||||||
|
err := shellOutMoby("pull", imageName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
// build args
|
} else {
|
||||||
cmd := &commandBuilder{
|
cmd := &commandBuilder{
|
||||||
Path: filepath.Join(projectDir, service.Build.Context),
|
Path: options.Inputs.ContextPath,
|
||||||
}
|
}
|
||||||
cmd.addParams("--build-arg", options.Args)
|
cmd.addParams("--build-arg", options.BuildArgs)
|
||||||
cmd.addFlag("--pull", options.Pull)
|
cmd.addFlag("--pull", options.Pull)
|
||||||
cmd.addArg("--progress", options.Progress)
|
cmd.addArg("--progress", mode)
|
||||||
|
|
||||||
cmd.addList("--cache-from", service.Build.CacheFrom)
|
cacheFrom := []string{}
|
||||||
|
for _, cacheImage := range options.CacheFrom {
|
||||||
|
cacheFrom = append(cacheFrom, cacheImage.Attrs["ref"])
|
||||||
|
}
|
||||||
|
cmd.addList("--cache-from", cacheFrom)
|
||||||
cmd.addArg("--file", dockerfile)
|
cmd.addArg("--file", dockerfile)
|
||||||
cmd.addParams("--label", service.Build.Labels)
|
cmd.addParams("--label", options.Labels)
|
||||||
cmd.addArg("--network", service.Build.Network)
|
cmd.addArg("--network", options.NetworkMode)
|
||||||
cmd.addArg("--target", service.Build.Target)
|
cmd.addArg("--target", options.Target)
|
||||||
cmd.addArg("--platform", service.Platform)
|
cmd.addList("--add-host", options.ExtraHosts)
|
||||||
cmd.addArg("--isolation", service.Build.Isolation)
|
|
||||||
cmd.addList("--add-host", service.Build.ExtraHosts)
|
|
||||||
|
|
||||||
cmd.addArg("--tag", imageName)
|
cmd.addArg("--tag", imageName)
|
||||||
|
|
||||||
args := cmd.getArguments()
|
err := shellOutMoby(cmd.getArguments()...)
|
||||||
// shell out to moby cli
|
|
||||||
childExit := make(chan bool)
|
|
||||||
err := mobycli.RunDocker(childExit, args...)
|
|
||||||
childExit <- true
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -72,6 +63,13 @@ func (s *composeService) windowsBuild(project *types.Project, options compose.Bu
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shellOutMoby(args ...string) error {
|
||||||
|
childExit := make(chan bool)
|
||||||
|
err := mobycli.RunDocker(childExit, args...)
|
||||||
|
childExit <- true
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
type commandBuilder struct {
|
type commandBuilder struct {
|
||||||
Args []string
|
Args []string
|
||||||
Path string
|
Path string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user