Skip to content

Commit

Permalink
Add a dangling image prefix when tag name is not specified.
Browse files Browse the repository at this point in the history
Fixes: #1398
Signed-off-by: Manu Gupta <manugupt1@gmail.com>
  • Loading branch information
manugupt1 committed Oct 27, 2022
1 parent 817d6ec commit 99fc1b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/nerdctl/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ func generateBuildctlArgs(cmd *cobra.Command, buildkitHost string, platform, arg
return "", nil, false, "", nil, nil, err
}

output = output + ",dangling-name-prefix=none"
buildctlArgs = append(buildctlArgs, []string{
"build",
"--progress=" + progressValue,
Expand Down
30 changes: 30 additions & 0 deletions cmd/nerdctl/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package main

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -402,3 +403,32 @@ 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)
testutil.DockerIncompatible(t)
base := testutil.NewBase(t)
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("--debug", "build", buildCtx).AssertOK()
imgs := base.Cmd("images", "--format", "json").OutLines()
imgs = imgs[:len(imgs)-1]
var noneImage *imagePrintable
var foundNoneImage bool
for _, img := range imgs {
err := json.Unmarshal([]byte(img), &noneImage)
assert.NilError(t, err, img)
if noneImage.Tag == "<none>" {
foundNoneImage = true
break
}
}
assert.Assert(t, foundNoneImage)
defer base.Cmd("image", "rm", noneImage.ID).AssertOK()
base.Cmd("run", "--rm", noneImage.ID).AssertOutExactly("nerdctl-build-notag-string\n")
}

0 comments on commit 99fc1b3

Please sign in to comment.