Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Insert the latest tag implicitly
Browse files Browse the repository at this point in the history
Also add usage examples for image rm.

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
  • Loading branch information
rumpl committed Oct 1, 2019
1 parent 5b857bc commit 27bbc86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
21 changes: 17 additions & 4 deletions e2e/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,23 @@ func TestImageRm(t *testing.T) {
digest := insertBundles(t, cmd, dir, info)

cmd.Command = dockerCli.Command("app", "image", "rm", info.registryAddress+"/c-myapp@"+digest)
icmd.RunCmd(cmd).Assert(t, icmd.Success)

cmd.Command = dockerCli.Command("app", "image", "rm", "a-simple-app:latest", "b-simple-app:latest")
icmd.RunCmd(cmd).Assert(t, icmd.Success)
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
ExitCode: 0,
Out: "Deleted: " + info.registryAddress + "/c-myapp@" + digest,
})

cmd.Command = dockerCli.Command("app", "image", "rm", "a-simple-app", "b-simple-app:latest")
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
ExitCode: 0,
Out: `Deleted: a-simple-app:latest
Deleted: b-simple-app:latest`,
})

cmd.Command = dockerCli.Command("app", "image", "rm", "b-simple-app")
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
ExitCode: 1,
Err: `Error: no such image b-simple-app:latest`,
})

expectedOutput := "REPOSITORY TAG APP NAME\n"
cmd.Command = dockerCli.Command("app", "image", "ls")
Expand Down
9 changes: 6 additions & 3 deletions internal/commands/image/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func rmCmd() *cobra.Command {
Use: "rm [APP_IMAGE] [APP_IMAGE...]",
Short: "Remove an application image",
Args: cli.RequiresMinArgs(1),
Example: `$ docker app image rm myapp
$ docker app image rm myapp:1.0.0
$ docker app image rm docker.io/library/myapp@sha256:beef...`,
RunE: func(cmd *cobra.Command, args []string) error {
appstore, err := store.NewApplicationStore(config.Dir())
if err != nil {
Expand Down Expand Up @@ -48,11 +51,11 @@ func runRm(bundleStore store.BundleStore, app string) error {
return err
}

err = bundleStore.Remove(ref)
if err != nil {
tagged := reference.TagNameOnly(ref)
if err := bundleStore.Remove(tagged); err != nil {
return err
}

fmt.Println("Deleted: " + ref.String())
fmt.Println("Deleted: " + reference.FamiliarString(tagged))
return nil
}
2 changes: 1 addition & 1 deletion internal/store/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (b *bundleStore) Remove(ref reference.Named) error {
}

if _, err := os.Stat(path); os.IsNotExist(err) {
return errors.New("no such image " + ref.String())
return errors.New("no such image " + reference.FamiliarString(ref))
}

return os.Remove(path)
Expand Down

0 comments on commit 27bbc86

Please sign in to comment.