Skip to content

Commit

Permalink
Support nerdctl build custom outputs alias of type local
Browse files Browse the repository at this point in the history
Signed-off-by: Hanchin Hsieh <[email protected]>
  • Loading branch information
yuchanns committed Oct 21, 2022
1 parent 165d19b commit ec8e352
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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)
}
data, err = os.ReadFile(testAliasFilePath)
assert.NilError(t, err)
assert.Equal(t, string(data), testContent)
}

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

0 comments on commit ec8e352

Please sign in to comment.