Skip to content

Commit

Permalink
Use TagImage in Commit
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Nephin <[email protected]>
  • Loading branch information
dnephin committed Feb 10, 2018
1 parent 2d97f5e commit afb3eda
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 35 deletions.
2 changes: 1 addition & 1 deletion api/server/router/image/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type imageBackend interface {
ImageHistory(imageName string) ([]*image.HistoryResponseItem, error)
Images(imageFilters filters.Args, all bool, withExtraAttrs bool) ([]*types.ImageSummary, error)
LookupImage(name string) (*types.ImageInspect, error)
TagImage(imageName, repository, tag string) error
TagImage(imageName, repository, tag string) (string, error)
ImagesPrune(ctx context.Context, pruneFilters filters.Args) (*types.ImagesPruneReport, error)
}

Expand Down
2 changes: 1 addition & 1 deletion api/server/router/image/image_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (s *imageRouter) postImagesTag(ctx context.Context, w http.ResponseWriter,
if err := httputils.ParseForm(r); err != nil {
return err
}
if err := s.backend.TagImage(vars["name"], r.Form.Get("repo"), r.Form.Get("tag")); err != nil {
if _, err := s.backend.TagImage(vars["name"], r.Form.Get("repo"), r.Form.Get("tag")); err != nil {
return err
}
w.WriteHeader(http.StatusCreated)
Expand Down
34 changes: 6 additions & 28 deletions daemon/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"time"

"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types/backend"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/builder/dockerfile"
Expand Down Expand Up @@ -176,9 +175,12 @@ func (daemon *Daemon) CreateImageFromContainer(name string, c *backend.CreateIma
return "", err
}

imageRef, err := daemon.tagCommit(c.Repo, c.Tag, id)
if err != nil {
return "", err
var imageRef string
if c.Repo != "" {
imageRef, err = daemon.TagImage(string(id), c.Repo, c.Tag)
if err != nil {
return "", err
}
}
daemon.LogContainerEventWithAttributes(container, "commit", map[string]string{
"comment": c.Comment,
Expand Down Expand Up @@ -247,30 +249,6 @@ func (daemon *Daemon) commitImage(c backend.CommitConfig) (image.ID, error) {
return id, nil
}

// TODO: remove from Daemon, move to api backend
func (daemon *Daemon) tagCommit(repo string, tag string, id image.ID) (string, error) {
imageRef := ""
if repo != "" {
newTag, err := reference.ParseNormalizedNamed(repo) // todo: should move this to API layer
if err != nil {
return "", err
}
if !reference.IsNameOnly(newTag) {
return "", errors.Errorf("unexpected repository name: %s", repo)
}
if tag != "" {
if newTag, err = reference.WithTag(newTag, tag); err != nil {
return "", err
}
}
if err := daemon.TagImageWithReference(id, newTag); err != nil {
return "", err
}
imageRef = reference.FamiliarString(newTag)
}
return imageRef, nil
}

func exportContainerRw(layerStore layer.Store, id, mountLabel string) (arch io.ReadCloser, err error) {
rwlayer, err := layerStore.GetRWLayer(id)
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions daemon/image_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ import (

// TagImage creates the tag specified by newTag, pointing to the image named
// imageName (alternatively, imageName can also be an image ID).
func (daemon *Daemon) TagImage(imageName, repository, tag string) error {
func (daemon *Daemon) TagImage(imageName, repository, tag string) (string, error) {
imageID, _, err := daemon.GetImageIDAndOS(imageName)
if err != nil {
return err
return "", err
}

newTag, err := reference.ParseNormalizedNamed(repository)
if err != nil {
return err
return "", err
}
if tag != "" {
if newTag, err = reference.WithTag(reference.TrimNamed(newTag), tag); err != nil {
return err
return "", err
}
}

return daemon.TagImageWithReference(imageID, newTag)
err = daemon.TagImageWithReference(imageID, newTag)
return reference.FamiliarString(newTag), err
}

// TagImageWithReference adds the given reference to the image ID provided.
Expand Down

0 comments on commit afb3eda

Please sign in to comment.