Skip to content

Commit 1c1fdeb

Browse files
committed
Always build with buildx
1 parent fa03604 commit 1c1fdeb

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

pkg/skaffold/build/docker/docker.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact,
7373
// we might consider a different approach in the future.
7474
// use CLI for cross-platform builds
7575
if b.useCLI || (b.useBuildKit != nil && *b.useBuildKit) || len(a.DockerArtifact.CliFlags) > 0 || matcher.IsNotEmpty() {
76-
imageID, err = b.dockerCLIBuild(ctx, output.GetUnderlyingWriter(out), a.ImageName, a.Workspace, dockerfile, a.ArtifactType.DockerArtifact, opts, pl)
76+
imageID, err = b.dockerCLIBuild(ctx, output.GetUnderlyingWriter(out), a.ImageName, a.Workspace, dockerfile, a.ArtifactType.DockerArtifact, opts, matcher)
7777
} else {
7878
imageID, err = b.localDocker.Build(ctx, out, a.Workspace, a.ImageName, a.ArtifactType.DockerArtifact, opts)
7979
}
@@ -82,7 +82,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact,
8282
return "", newBuildError(err, b.cfg)
8383
}
8484

85-
if b.pushImages {
85+
if !b.useCLI && b.pushImages {
8686
// TODO (tejaldesai) Remove https://github.com/GoogleContainerTools/skaffold/blob/main/pkg/skaffold/errors/err_map.go#L56
8787
// and instead define a pushErr() method here.
8888
return b.localDocker.Push(ctx, out, tag)
@@ -91,8 +91,8 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact,
9191
return imageID, nil
9292
}
9393

94-
func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string, workspace string, dockerfilePath string, a *latest.DockerArtifact, opts docker.BuildOptions, pl v1.Platform) (string, error) {
95-
args := []string{"build", workspace, "--file", dockerfilePath, "-t", opts.Tag}
94+
func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string, workspace string, dockerfilePath string, a *latest.DockerArtifact, opts docker.BuildOptions, pl platform.Matcher) (string, error) {
95+
args := []string{"buildx", "build", workspace, "--file", dockerfilePath, "-t", opts.Tag}
9696
imgRef, err := docker.ParseReference(opts.Tag)
9797
if err != nil {
9898
return "", fmt.Errorf("couldn't parse image tag: %w", err)
@@ -110,6 +110,9 @@ func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string
110110
if err != nil {
111111
return "", fmt.Errorf("getting docker build args: %w", err)
112112
}
113+
if b.pushImages {
114+
cliArgs = append(cliArgs, "--push")
115+
}
113116
args = append(args, cliArgs...)
114117

115118
if b.cfg.Prune() {
@@ -142,7 +145,7 @@ func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string
142145
return "", tryExecFormatErr(fmt.Errorf("running build: %w", err), errBuffer)
143146
}
144147

145-
return b.localDocker.ImageID(ctx, opts.Tag)
148+
return opts.Tag, nil
146149
}
147150

148151
func (b *Builder) pullCacheFromImages(ctx context.Context, out io.Writer, a *latest.DockerArtifact, pl v1.Platform) error {

pkg/skaffold/build/local/local.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, a *latest.Ar
7171
return "", err
7272
}
7373

74+
return digestOrImageID, nil // buildx
75+
7476
if b.pushImages {
7577
// only track images for pruning when building with docker
7678
// if we're pushing a bazel image, it was built directly to the registry
@@ -94,7 +96,8 @@ func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, a *latest.Ar
9496
}
9597

9698
func (b *Builder) runBuildForArtifact(ctx context.Context, out io.Writer, a *latest.Artifact, tag string, platforms platform.Matcher) (string, error) {
97-
if !b.pushImages {
99+
var buildx = true
100+
if !buildx && !b.pushImages {
98101
// All of the builders will rely on a local Docker:
99102
// + Either to build the image,
100103
// + Or to docker load it.

pkg/skaffold/build/platform.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ import (
3232

3333
func SupportsMultiPlatformBuild(a latest.Artifact) bool {
3434
switch {
35-
case a.DockerArtifact != nil || a.BazelArtifact != nil || a.BuildpackArtifact != nil:
35+
case a.DockerArtifact != nil:
36+
return true
37+
case a.BazelArtifact != nil || a.BuildpackArtifact != nil:
3638
return false
3739
case a.JibArtifact != nil || a.CustomArtifact != nil || a.KoArtifact != nil:
3840
return true

0 commit comments

Comments
 (0)