Skip to content

fix: docker build for artifact with cliFlags should use docker CLI #6930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/skaffold/build/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latestV1.Artifact

// ignore useCLI boolean if buildkit is enabled since buildkit is only implemented for docker CLI at the moment in skaffold.
// we might consider a different approach in the future.
if b.useCLI || (b.useBuildKit != nil && *b.useBuildKit) {
if b.useCLI || (b.useBuildKit != nil && *b.useBuildKit) || len(a.DockerArtifact.CliFlags) > 0 {
imageID, err = b.dockerCLIBuild(ctx, output.GetUnderlyingWriter(out), a.Workspace, dockerfile, a.ArtifactType.DockerArtifact, opts)
} else {
imageID, err = b.localDocker.Build(ctx, out, a.Workspace, a.ImageName, a.ArtifactType.DockerArtifact, opts)
Expand Down
18 changes: 14 additions & 4 deletions pkg/skaffold/build/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestDockerCLIBuild(t *testing.T) {
tests := []struct {
description string
localBuild latestV1.LocalBuild
cliFlags []string
cfg mockConfig
extraEnv []string
expectedEnv []string
Expand All @@ -67,6 +68,13 @@ func TestDockerCLIBuild(t *testing.T) {
wantDockerCLI: true,
expectedEnv: []string{"KEY=VALUE", "DOCKER_BUILDKIT=1"},
},
{
description: "cliFlags",
cliFlags: []string{"--platform", "linux/amd64"},
localBuild: latestV1.LocalBuild{},
wantDockerCLI: true,
expectedEnv: []string{"KEY=VALUE"},
},
{
description: "buildkit and extra env",
localBuild: latestV1.LocalBuild{UseBuildkit: util.BoolPtr(true)},
Expand Down Expand Up @@ -143,10 +151,11 @@ func TestDockerCLIBuild(t *testing.T) {
t.Override(&util.DefaultExecCommand, mockCmd)
}
if test.wantDockerCLI {
mockCmd = testutil.CmdRunEnv(
"docker build . --file "+dockerfilePath+" -t tag",
test.expectedEnv,
)
cmdLine := "docker build . --file " + dockerfilePath + " -t tag"
if len(test.cliFlags) > 0 {
cmdLine += " " + strings.Join(test.cliFlags, " ")
}
mockCmd = testutil.CmdRunEnv(cmdLine, test.expectedEnv)
t.Override(&util.DefaultExecCommand, mockCmd)
}
t.Override(&util.OSEnviron, func() []string { return []string{"KEY=VALUE"} })
Expand All @@ -158,6 +167,7 @@ func TestDockerCLIBuild(t *testing.T) {
ArtifactType: latestV1.ArtifactType{
DockerArtifact: &latestV1.DockerArtifact{
DockerfilePath: "Dockerfile",
CliFlags: test.cliFlags,
},
},
}
Expand Down