mirror of
https://github.com/docker/compose.git
synced 2025-06-26 16:34:28 +02:00
use Bake by default
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
92fafccfb2
commit
0d0e12cc85
@ -22,7 +22,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/v2/types"
|
"github.com/compose-spec/compose-go/v2/types"
|
||||||
@ -34,7 +33,6 @@ import (
|
|||||||
"github.com/docker/buildx/util/buildflags"
|
"github.com/docker/buildx/util/buildflags"
|
||||||
xprogress "github.com/docker/buildx/util/progress"
|
xprogress "github.com/docker/buildx/util/progress"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/hints"
|
|
||||||
cliopts "github.com/docker/cli/opts"
|
cliopts "github.com/docker/cli/opts"
|
||||||
"github.com/docker/compose/v2/internal/tracing"
|
"github.com/docker/compose/v2/internal/tracing"
|
||||||
"github.com/docker/compose/v2/pkg/api"
|
"github.com/docker/compose/v2/pkg/api"
|
||||||
@ -71,10 +69,6 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti
|
|||||||
}, s.stdinfo(), "Building")
|
}, s.stdinfo(), "Building")
|
||||||
}
|
}
|
||||||
|
|
||||||
const bakeSuggest = "Compose can now delegate builds to bake for better performance.\n To do so, set COMPOSE_BAKE=true."
|
|
||||||
|
|
||||||
var suggest sync.Once
|
|
||||||
|
|
||||||
//nolint:gocyclo
|
//nolint:gocyclo
|
||||||
func (s *composeService) build(ctx context.Context, project *types.Project, options api.BuildOptions, localImages map[string]api.ImageSummary) (map[string]string, error) {
|
func (s *composeService) build(ctx context.Context, project *types.Project, options api.BuildOptions, localImages map[string]api.ImageSummary) (map[string]string, error) {
|
||||||
imageIDs := map[string]string{}
|
imageIDs := map[string]string{}
|
||||||
@ -156,11 +150,6 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
|
|||||||
w *xprogress.Printer
|
w *xprogress.Printer
|
||||||
)
|
)
|
||||||
if buildkitEnabled {
|
if buildkitEnabled {
|
||||||
if hints.Enabled() && progress.Mode != progress.ModeQuiet && progress.Mode != progress.ModeJSON {
|
|
||||||
suggest.Do(func() {
|
|
||||||
fmt.Fprintln(s.dockerCli.Out(), bakeSuggest) //nolint:errcheck
|
|
||||||
})
|
|
||||||
}
|
|
||||||
builderName := options.Builder
|
builderName := options.Builder
|
||||||
if builderName == "" {
|
if builderName == "" {
|
||||||
builderName = os.Getenv("BUILDX_BUILDER")
|
builderName = os.Getenv("BUILDX_BUILDER")
|
||||||
|
@ -51,12 +51,7 @@ import (
|
|||||||
func buildWithBake(dockerCli command.Cli) (bool, error) {
|
func buildWithBake(dockerCli command.Cli) (bool, error) {
|
||||||
b, ok := os.LookupEnv("COMPOSE_BAKE")
|
b, ok := os.LookupEnv("COMPOSE_BAKE")
|
||||||
if !ok {
|
if !ok {
|
||||||
if dockerCli.ConfigFile().Plugins["compose"]["build"] == "bake" {
|
b = "true"
|
||||||
b, ok = "true", true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
return false, nil
|
|
||||||
}
|
}
|
||||||
bake, err := strconv.ParseBool(b)
|
bake, err := strconv.ParseBool(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -72,6 +67,7 @@ func buildWithBake(dockerCli command.Cli) (bool, error) {
|
|||||||
}
|
}
|
||||||
if !enabled {
|
if !enabled {
|
||||||
logrus.Warnf("Docker Compose is configured to build using Bake, but buildkit isn't enabled")
|
logrus.Warnf("Docker Compose is configured to build using Bake, but buildkit isn't enabled")
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = manager.GetPlugin("buildx", dockerCli, &cobra.Command{})
|
_, err = manager.GetPlugin("buildx", dockerCli, &cobra.Command{})
|
||||||
|
@ -284,7 +284,7 @@ func TestBuildImageDependencies(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("BuildKit by dependency order", func(t *testing.T) {
|
t.Run("BuildKit by dependency order", func(t *testing.T) {
|
||||||
cli := NewCLI(t, WithEnv(
|
cli := NewCLI(t, WithEnv(
|
||||||
"DOCKER_BUILDKIT=1",
|
"DOCKER_BUILDKIT=1", "COMPOSE_BAKE=0",
|
||||||
"COMPOSE_FILE=./fixtures/build-dependencies/classic.yaml",
|
"COMPOSE_FILE=./fixtures/build-dependencies/classic.yaml",
|
||||||
))
|
))
|
||||||
doTest(t, cli, "build")
|
doTest(t, cli, "build")
|
||||||
@ -293,7 +293,7 @@ func TestBuildImageDependencies(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("BuildKit by additional contexts", func(t *testing.T) {
|
t.Run("BuildKit by additional contexts", func(t *testing.T) {
|
||||||
cli := NewCLI(t, WithEnv(
|
cli := NewCLI(t, WithEnv(
|
||||||
"DOCKER_BUILDKIT=1",
|
"DOCKER_BUILDKIT=1", "COMPOSE_BAKE=0",
|
||||||
"COMPOSE_FILE=./fixtures/build-dependencies/compose.yaml",
|
"COMPOSE_FILE=./fixtures/build-dependencies/compose.yaml",
|
||||||
))
|
))
|
||||||
doTest(t, cli, "build")
|
doTest(t, cli, "build")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user