tag.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package graph
  2. import (
  3. "github.com/docker/docker/engine"
  4. "github.com/docker/docker/pkg/parsers"
  5. )
  6. // CmdTag assigns a new name and tag to an existing image. If the tag already exists,
  7. // it is changed and the image previously referenced by the tag loses that reference.
  8. // This may cause the old image to be garbage-collected if its reference count reaches zero.
  9. //
  10. // Syntax: image_tag NEWNAME OLDNAME
  11. // Example: image_tag shykes/myapp:latest shykes/myapp:1.42.0
  12. func (s *TagStore) CmdTag(job *engine.Job) engine.Status {
  13. if len(job.Args) != 2 {
  14. return job.Errorf("usage: %s NEWNAME OLDNAME", job.Name)
  15. }
  16. var (
  17. newName = job.Args[0]
  18. oldName = job.Args[1]
  19. )
  20. newRepo, newTag := parsers.ParseRepositoryTag(newName)
  21. // FIXME: Set should either parse both old and new name, or neither.
  22. // the current prototype is inconsistent.
  23. if err := s.Set(newRepo, newTag, oldName, true); err != nil {
  24. return job.Error(err)
  25. }
  26. return engine.StatusOK
  27. }
  28. // FIXME: merge into CmdTag above, and merge "image_tag" and "tag" into a single job.
  29. func (s *TagStore) CmdTagLegacy(job *engine.Job) engine.Status {
  30. if len(job.Args) != 2 && len(job.Args) != 3 {
  31. return job.Errorf("Usage: %s IMAGE REPOSITORY [TAG]\n", job.Name)
  32. }
  33. var tag string
  34. if len(job.Args) == 3 {
  35. tag = job.Args[2]
  36. }
  37. if err := s.Set(job.Args[1], tag, job.Args[0], job.GetenvBool("force")); err != nil {
  38. return job.Error(err)
  39. }
  40. return engine.StatusOK
  41. }