Skip to content

Commit

Permalink
Merge pull request #1461 from manugupt1/noneimage
Browse files Browse the repository at this point in the history
Add a dangling image prefix when tag name is not specified.
  • Loading branch information
AkihiroSuda authored Nov 4, 2022
2 parents 6d7f68b + e688de7 commit b71443b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/nerdctl/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ func generateBuildctlArgs(cmd *cobra.Command, buildkitHost string, platform, arg
}
tags[idx] = dockerreference.TagNameOnly(named).String()
}
} else if len(tags) == 0 {
output = output + ",dangling-name-prefix=<none>"
}

buildctlArgs = buildkitutil.BuildctlBaseArgs(buildkitHost)
Expand Down
18 changes: 18 additions & 0 deletions cmd/nerdctl/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,21 @@ CMD ["echo", "dockerfile"]
base.Cmd("build", "-t", imageName, buildCtx).AssertOK()
base.Cmd("run", "--rm", imageName).AssertOutExactly("dockerfile\n")
}

func TestBuildNoTag(t *testing.T) {
testutil.RequiresBuild(t)
base := testutil.NewBase(t)
defer base.Cmd("builder", "prune").AssertOK()
base.Cmd("image", "prune", "--force", "--all").AssertOK()

dockerfile := fmt.Sprintf(`FROM %s
CMD ["echo", "nerdctl-build-notag-string"]
`, testutil.CommonImage)
buildCtx, err := createBuildContext(dockerfile)
assert.NilError(t, err)
defer os.RemoveAll(buildCtx)

base.Cmd("build", buildCtx).AssertOK()
base.Cmd("images").AssertOutContains("<none>")
base.Cmd("image", "prune", "--force", "--all").AssertOK()
}

0 comments on commit b71443b

Please sign in to comment.