From 3bfc82257878e55141bb029390574130c3ac0530 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 17 Jun 2013 18:39:30 -0700 Subject: [PATCH 1/3] * API: Add tag lookup to history command. Fixes #882 --- api_params.go | 1 + commands.go | 2 +- server.go | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/api_params.go b/api_params.go index 2a641f8ccd..c3fabb2be0 100644 --- a/api_params.go +++ b/api_params.go @@ -2,6 +2,7 @@ package docker type APIHistory struct { ID string `json:"Id"` + Tag string `json:",omitempty"` Created int64 CreatedBy string `json:",omitempty"` } diff --git a/commands.go b/commands.go index ce15fd6cf1..98be40181c 100644 --- a/commands.go +++ b/commands.go @@ -627,7 +627,7 @@ func (cli *DockerCli) CmdHistory(args ...string) error { fmt.Fprintln(w, "ID\tCREATED\tCREATED BY") for _, out := range outs { - fmt.Fprintf(w, "%s\t%s ago\t%s\n", out.ID, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy) + fmt.Fprintf(w, "%s (%s)\t%s ago\t%s\n", out.ID, out.Tag, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy) } w.Flush() return nil diff --git a/server.go b/server.go index 30e3ec6b3a..912349b82e 100644 --- a/server.go +++ b/server.go @@ -218,12 +218,26 @@ func (srv *Server) ImageHistory(name string) ([]APIHistory, error) { return nil, err } + lookupMap := make(map[string]string) + for name, repository := range srv.runtime.repositories.Repositories { + for tag, id := range repository { + // If the ID already has a reverse lookup, do not update it unless for "latest" + if _, exists := lookupMap[id]; exists { + if tag != "latest" { + continue + } + } + lookupMap[id] = name + ":" + tag + } + } + outs := []APIHistory{} //produce [] when empty instead of 'null' err = image.WalkHistory(func(img *Image) error { var out APIHistory out.ID = srv.runtime.repositories.ImageName(img.ShortID()) out.Created = img.Created.Unix() out.CreatedBy = strings.Join(img.ContainerConfig.Cmd, " ") + out.Tag = lookupMap[img.ID] outs = append(outs, out) return nil }) From 02a002d264faa7b8cdf5c68b7370c31d6794a44d Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 17 Jun 2013 18:41:13 -0700 Subject: [PATCH 2/3] Update documentation --- docs/sources/api/docker_remote_api_v1.2.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sources/api/docker_remote_api_v1.2.rst b/docs/sources/api/docker_remote_api_v1.2.rst index fb69168120..44a397a4db 100644 --- a/docs/sources/api/docker_remote_api_v1.2.rst +++ b/docs/sources/api/docker_remote_api_v1.2.rst @@ -691,6 +691,7 @@ Get the history of an image [ { "Id":"b750fe79269d", + "Tag":"base:latest", "Created":1364102658, "CreatedBy":"/bin/bash" }, From 808faa6371c470fa0765f5d4e3aed7708d8f9ee6 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 18 Jun 2013 10:31:07 -0700 Subject: [PATCH 3/3] * API: Send all tags on History API call --- api_params.go | 4 ++-- commands.go | 5 ++++- docs/sources/api/docker_remote_api_v1.2.rst | 2 +- server.go | 12 +++++------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/api_params.go b/api_params.go index c3fabb2be0..b8af690c7f 100644 --- a/api_params.go +++ b/api_params.go @@ -1,8 +1,8 @@ package docker type APIHistory struct { - ID string `json:"Id"` - Tag string `json:",omitempty"` + ID string `json:"Id"` + Tags []string `json:",omitempty"` Created int64 CreatedBy string `json:",omitempty"` } diff --git a/commands.go b/commands.go index 98be40181c..844dbb132c 100644 --- a/commands.go +++ b/commands.go @@ -627,7 +627,10 @@ func (cli *DockerCli) CmdHistory(args ...string) error { fmt.Fprintln(w, "ID\tCREATED\tCREATED BY") for _, out := range outs { - fmt.Fprintf(w, "%s (%s)\t%s ago\t%s\n", out.ID, out.Tag, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy) + if out.Tags != nil { + out.ID = out.Tags[0] + } + fmt.Fprintf(w, "%s \t%s ago\t%s\n", out.ID, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy) } w.Flush() return nil diff --git a/docs/sources/api/docker_remote_api_v1.2.rst b/docs/sources/api/docker_remote_api_v1.2.rst index 44a397a4db..ba2becd4d3 100644 --- a/docs/sources/api/docker_remote_api_v1.2.rst +++ b/docs/sources/api/docker_remote_api_v1.2.rst @@ -691,7 +691,7 @@ Get the history of an image [ { "Id":"b750fe79269d", - "Tag":"base:latest", + "Tag":["base:latest"], "Created":1364102658, "CreatedBy":"/bin/bash" }, diff --git a/server.go b/server.go index 912349b82e..8e41091c32 100644 --- a/server.go +++ b/server.go @@ -218,16 +218,14 @@ func (srv *Server) ImageHistory(name string) ([]APIHistory, error) { return nil, err } - lookupMap := make(map[string]string) + lookupMap := make(map[string][]string) for name, repository := range srv.runtime.repositories.Repositories { for tag, id := range repository { // If the ID already has a reverse lookup, do not update it unless for "latest" - if _, exists := lookupMap[id]; exists { - if tag != "latest" { - continue - } + if _, exists := lookupMap[id]; !exists { + lookupMap[id] = []string{} } - lookupMap[id] = name + ":" + tag + lookupMap[id] = append(lookupMap[id], name+":"+tag) } } @@ -237,7 +235,7 @@ func (srv *Server) ImageHistory(name string) ([]APIHistory, error) { out.ID = srv.runtime.repositories.ImageName(img.ShortID()) out.Created = img.Created.Unix() out.CreatedBy = strings.Join(img.ContainerConfig.Cmd, " ") - out.Tag = lookupMap[img.ID] + out.Tags = lookupMap[img.ID] outs = append(outs, out) return nil })