@@ -73,7 +73,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact,
73
73
// we might consider a different approach in the future.
74
74
// use CLI for cross-platform builds
75
75
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 )
77
77
} else {
78
78
imageID , err = b .localDocker .Build (ctx , out , a .Workspace , a .ImageName , a .ArtifactType .DockerArtifact , opts )
79
79
}
@@ -82,7 +82,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact,
82
82
return "" , newBuildError (err , b .cfg )
83
83
}
84
84
85
- if b .pushImages {
85
+ if ! b . useCLI && b .pushImages {
86
86
// TODO (tejaldesai) Remove https://github.com/GoogleContainerTools/skaffold/blob/main/pkg/skaffold/errors/err_map.go#L56
87
87
// and instead define a pushErr() method here.
88
88
return b .localDocker .Push (ctx , out , tag )
@@ -91,8 +91,8 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latest.Artifact,
91
91
return imageID , nil
92
92
}
93
93
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 }
96
96
imgRef , err := docker .ParseReference (opts .Tag )
97
97
if err != nil {
98
98
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
110
110
if err != nil {
111
111
return "" , fmt .Errorf ("getting docker build args: %w" , err )
112
112
}
113
+ if b .pushImages {
114
+ cliArgs = append (cliArgs , "--push" )
115
+ }
113
116
args = append (args , cliArgs ... )
114
117
115
118
if b .cfg .Prune () {
@@ -142,7 +145,7 @@ func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, name string
142
145
return "" , tryExecFormatErr (fmt .Errorf ("running build: %w" , err ), errBuffer )
143
146
}
144
147
145
- return b . localDocker . ImageID ( ctx , opts .Tag )
148
+ return opts .Tag , nil
146
149
}
147
150
148
151
func (b * Builder ) pullCacheFromImages (ctx context.Context , out io.Writer , a * latest.DockerArtifact , pl v1.Platform ) error {
0 commit comments