Skip to content
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

Support nerdctl build custom outputs alias of type local #1459

Merged
merged 1 commit into from
Oct 21, 2022
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
5 changes: 5 additions & 0 deletions cmd/nerdctl/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ func generateBuildctlArgs(cmd *cobra.Command, buildkitHost string, platform, arg
needsLoading = true
}
} else {
if !strings.Contains(output, "type=") {
// should accept --output <DIR> as an alias of --output
// type=local,dest=<DIR>
output = fmt.Sprintf("type=local,dest=%s", output)
}
if strings.Contains(output, "type=docker") || strings.Contains(output, "type=oci") {
needsLoading = true
}
Expand Down
14 changes: 13 additions & 1 deletion cmd/nerdctl/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ CMD ["echo", "nerdctl-build-test-dockerfile"]

func TestBuildLocal(t *testing.T) {
t.Parallel()
testutil.DockerIncompatible(t)
testutil.RequiresBuild(t)
base := testutil.NewBase(t)
if testutil.GetTarget() == testutil.Docker {
base.Env = append(base.Env, "DOCKER_BUILDKIT=1")
}
defer base.Cmd("builder", "prune").Run()
const testFileName = "nerdctl-build-test"
const testContent = "nerdctl"
Expand All @@ -202,6 +204,16 @@ COPY %s /`,
data, err := os.ReadFile(testFilePath)
assert.NilError(t, err)
assert.Equal(t, string(data), testContent)

aliasOutputDir := t.TempDir()
testAliasFilePath := filepath.Join(aliasOutputDir, testFileName)
base.Cmd("build", "-o", aliasOutputDir, buildCtx).AssertOK()
if _, err := os.Stat(testAliasFilePath); err != nil {
t.Fatal(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use assert.NilError ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I was planning to fix it.

}
data, err = os.ReadFile(testAliasFilePath)
assert.NilError(t, err)
assert.Equal(t, string(data), testContent)
}

func createBuildContext(dockerfile string) (string, error) {
Expand Down