Closes #10922
Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
| ... | ... |
@@ -33,6 +33,7 @@ import ( |
| 33 | 33 |
"github.com/docker/docker/nat" |
| 34 | 34 |
"github.com/docker/docker/opts" |
| 35 | 35 |
"github.com/docker/docker/pkg/archive" |
| 36 |
+ "github.com/docker/docker/pkg/common" |
|
| 36 | 37 |
"github.com/docker/docker/pkg/fileutils" |
| 37 | 38 |
"github.com/docker/docker/pkg/homedir" |
| 38 | 39 |
flag "github.com/docker/docker/pkg/mflag" |
| ... | ... |
@@ -1075,7 +1076,7 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
|
| 1075 | 1075 |
if *noTrunc {
|
| 1076 | 1076 |
fmt.Fprintf(w, "%s\t", outID) |
| 1077 | 1077 |
} else {
|
| 1078 |
- fmt.Fprintf(w, "%s\t", utils.TruncateID(outID)) |
|
| 1078 |
+ fmt.Fprintf(w, "%s\t", common.TruncateID(outID)) |
|
| 1079 | 1079 |
} |
| 1080 | 1080 |
|
| 1081 | 1081 |
fmt.Fprintf(w, "%s ago\t", units.HumanDuration(time.Now().UTC().Sub(time.Unix(out.GetInt64("Created"), 0))))
|
| ... | ... |
@@ -1090,7 +1091,7 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
|
| 1090 | 1090 |
if *noTrunc {
|
| 1091 | 1091 |
fmt.Fprintln(w, outID) |
| 1092 | 1092 |
} else {
|
| 1093 |
- fmt.Fprintln(w, utils.TruncateID(outID)) |
|
| 1093 |
+ fmt.Fprintln(w, common.TruncateID(outID)) |
|
| 1094 | 1094 |
} |
| 1095 | 1095 |
} |
| 1096 | 1096 |
} |
| ... | ... |
@@ -1384,7 +1385,7 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
| 1384 | 1384 |
} |
| 1385 | 1385 |
|
| 1386 | 1386 |
if matchName != "" {
|
| 1387 |
- if matchName == image.Get("Id") || matchName == utils.TruncateID(image.Get("Id")) {
|
|
| 1387 |
+ if matchName == image.Get("Id") || matchName == common.TruncateID(image.Get("Id")) {
|
|
| 1388 | 1388 |
startImage = image |
| 1389 | 1389 |
} |
| 1390 | 1390 |
|
| ... | ... |
@@ -1453,7 +1454,7 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
| 1453 | 1453 |
repo, tag := parsers.ParseRepositoryTag(repotag) |
| 1454 | 1454 |
outID := out.Get("Id")
|
| 1455 | 1455 |
if !*noTrunc {
|
| 1456 |
- outID = utils.TruncateID(outID) |
|
| 1456 |
+ outID = common.TruncateID(outID) |
|
| 1457 | 1457 |
} |
| 1458 | 1458 |
|
| 1459 | 1459 |
if !*quiet {
|
| ... | ... |
@@ -1508,8 +1509,8 @@ func (cli *DockerCli) printVizNode(noTrunc bool, image *engine.Env, prefix strin |
| 1508 | 1508 |
imageID = image.Get("Id")
|
| 1509 | 1509 |
parentID = image.Get("ParentId")
|
| 1510 | 1510 |
} else {
|
| 1511 |
- imageID = utils.TruncateID(image.Get("Id"))
|
|
| 1512 |
- parentID = utils.TruncateID(image.Get("ParentId"))
|
|
| 1511 |
+ imageID = common.TruncateID(image.Get("Id"))
|
|
| 1512 |
+ parentID = common.TruncateID(image.Get("ParentId"))
|
|
| 1513 | 1513 |
} |
| 1514 | 1514 |
if parentID == "" {
|
| 1515 | 1515 |
fmt.Fprintf(cli.out, " base -> \"%s\" [style=invis]\n", imageID) |
| ... | ... |
@@ -1528,7 +1529,7 @@ func (cli *DockerCli) printTreeNode(noTrunc bool, image *engine.Env, prefix stri |
| 1528 | 1528 |
if noTrunc {
|
| 1529 | 1529 |
imageID = image.Get("Id")
|
| 1530 | 1530 |
} else {
|
| 1531 |
- imageID = utils.TruncateID(image.Get("Id"))
|
|
| 1531 |
+ imageID = common.TruncateID(image.Get("Id"))
|
|
| 1532 | 1532 |
} |
| 1533 | 1533 |
|
| 1534 | 1534 |
fmt.Fprintf(cli.out, "%s%s Virtual Size: %s", prefix, imageID, units.HumanSize(float64(image.GetInt64("VirtualSize"))))
|
| ... | ... |
@@ -1636,7 +1637,7 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
| 1636 | 1636 |
outID := out.Get("Id")
|
| 1637 | 1637 |
|
| 1638 | 1638 |
if !*noTrunc {
|
| 1639 |
- outID = utils.TruncateID(outID) |
|
| 1639 |
+ outID = common.TruncateID(outID) |
|
| 1640 | 1640 |
} |
| 1641 | 1641 |
|
| 1642 | 1642 |
if *quiet {
|
| ... | ... |
@@ -32,6 +32,7 @@ import ( |
| 32 | 32 |
"github.com/docker/docker/builder/parser" |
| 33 | 33 |
"github.com/docker/docker/daemon" |
| 34 | 34 |
"github.com/docker/docker/engine" |
| 35 |
+ "github.com/docker/docker/pkg/common" |
|
| 35 | 36 |
"github.com/docker/docker/pkg/fileutils" |
| 36 | 37 |
"github.com/docker/docker/pkg/symlink" |
| 37 | 38 |
"github.com/docker/docker/pkg/tarsum" |
| ... | ... |
@@ -155,7 +156,7 @@ func (b *Builder) Run(context io.Reader) (string, error) {
|
| 155 | 155 |
} |
| 156 | 156 |
return "", err |
| 157 | 157 |
} |
| 158 |
- fmt.Fprintf(b.OutStream, " ---> %s\n", utils.TruncateID(b.image)) |
|
| 158 |
+ fmt.Fprintf(b.OutStream, " ---> %s\n", common.TruncateID(b.image)) |
|
| 159 | 159 |
if b.Remove {
|
| 160 | 160 |
b.clearTmp() |
| 161 | 161 |
} |
| ... | ... |
@@ -165,7 +166,7 @@ func (b *Builder) Run(context io.Reader) (string, error) {
|
| 165 | 165 |
return "", fmt.Errorf("No image was generated. Is your Dockerfile empty?")
|
| 166 | 166 |
} |
| 167 | 167 |
|
| 168 |
- fmt.Fprintf(b.OutStream, "Successfully built %s\n", utils.TruncateID(b.image)) |
|
| 168 |
+ fmt.Fprintf(b.OutStream, "Successfully built %s\n", common.TruncateID(b.image)) |
|
| 169 | 169 |
return b.image, nil |
| 170 | 170 |
} |
| 171 | 171 |
|
| ... | ... |
@@ -25,6 +25,7 @@ import ( |
| 25 | 25 |
imagepkg "github.com/docker/docker/image" |
| 26 | 26 |
"github.com/docker/docker/pkg/archive" |
| 27 | 27 |
"github.com/docker/docker/pkg/chrootarchive" |
| 28 |
+ "github.com/docker/docker/pkg/common" |
|
| 28 | 29 |
"github.com/docker/docker/pkg/ioutils" |
| 29 | 30 |
"github.com/docker/docker/pkg/parsers" |
| 30 | 31 |
"github.com/docker/docker/pkg/symlink" |
| ... | ... |
@@ -531,7 +532,7 @@ func (b *Builder) create() (*daemon.Container, error) {
|
| 531 | 531 |
} |
| 532 | 532 |
|
| 533 | 533 |
b.TmpContainers[c.ID] = struct{}{}
|
| 534 |
- fmt.Fprintf(b.OutStream, " ---> Running in %s\n", utils.TruncateID(c.ID)) |
|
| 534 |
+ fmt.Fprintf(b.OutStream, " ---> Running in %s\n", common.TruncateID(c.ID)) |
|
| 535 | 535 |
|
| 536 | 536 |
if len(config.Cmd) > 0 {
|
| 537 | 537 |
// override the entry point that may have been picked up from the base image |
| ... | ... |
@@ -713,11 +714,11 @@ func (b *Builder) clearTmp() {
|
| 713 | 713 |
} |
| 714 | 714 |
|
| 715 | 715 |
if err := b.Daemon.Rm(tmp); err != nil {
|
| 716 |
- fmt.Fprintf(b.OutStream, "Error removing intermediate container %s: %s\n", utils.TruncateID(c), err.Error()) |
|
| 716 |
+ fmt.Fprintf(b.OutStream, "Error removing intermediate container %s: %s\n", common.TruncateID(c), err.Error()) |
|
| 717 | 717 |
return |
| 718 | 718 |
} |
| 719 | 719 |
b.Daemon.DeleteVolumes(tmp.VolumePaths()) |
| 720 | 720 |
delete(b.TmpContainers, c) |
| 721 |
- fmt.Fprintf(b.OutStream, "Removing intermediate container %s\n", utils.TruncateID(c)) |
|
| 721 |
+ fmt.Fprintf(b.OutStream, "Removing intermediate container %s\n", common.TruncateID(c)) |
|
| 722 | 722 |
} |
| 723 | 723 |
} |
| ... | ... |
@@ -25,6 +25,7 @@ import ( |
| 25 | 25 |
"github.com/docker/docker/nat" |
| 26 | 26 |
"github.com/docker/docker/pkg/archive" |
| 27 | 27 |
"github.com/docker/docker/pkg/broadcastwriter" |
| 28 |
+ "github.com/docker/docker/pkg/common" |
|
| 28 | 29 |
"github.com/docker/docker/pkg/ioutils" |
| 29 | 30 |
"github.com/docker/docker/pkg/networkfs/etchosts" |
| 30 | 31 |
"github.com/docker/docker/pkg/networkfs/resolvconf" |
| ... | ... |
@@ -704,7 +705,7 @@ func (container *Container) Kill() error {
|
| 704 | 704 |
if _, err := container.WaitStop(10 * time.Second); err != nil {
|
| 705 | 705 |
// Ensure that we don't kill ourselves |
| 706 | 706 |
if pid := container.GetPid(); pid != 0 {
|
| 707 |
- log.Infof("Container %s failed to exit within 10 seconds of kill - trying direct SIGKILL", utils.TruncateID(container.ID))
|
|
| 707 |
+ log.Infof("Container %s failed to exit within 10 seconds of kill - trying direct SIGKILL", common.TruncateID(container.ID))
|
|
| 708 | 708 |
if err := syscall.Kill(pid, 9); err != nil {
|
| 709 | 709 |
if err != syscall.ESRCH {
|
| 710 | 710 |
return err |
| ... | ... |
@@ -31,6 +31,7 @@ import ( |
| 31 | 31 |
"github.com/docker/docker/image" |
| 32 | 32 |
"github.com/docker/docker/pkg/archive" |
| 33 | 33 |
"github.com/docker/docker/pkg/broadcastwriter" |
| 34 |
+ "github.com/docker/docker/pkg/common" |
|
| 34 | 35 |
"github.com/docker/docker/pkg/graphdb" |
| 35 | 36 |
"github.com/docker/docker/pkg/ioutils" |
| 36 | 37 |
"github.com/docker/docker/pkg/namesgenerator" |
| ... | ... |
@@ -511,7 +512,7 @@ func (daemon *Daemon) mergeAndVerifyConfig(config *runconfig.Config, img *image. |
| 511 | 511 |
func (daemon *Daemon) generateIdAndName(name string) (string, string, error) {
|
| 512 | 512 |
var ( |
| 513 | 513 |
err error |
| 514 |
- id = utils.GenerateRandomID() |
|
| 514 |
+ id = common.GenerateRandomID() |
|
| 515 | 515 |
) |
| 516 | 516 |
|
| 517 | 517 |
if name == "" {
|
| ... | ... |
@@ -556,7 +557,7 @@ func (daemon *Daemon) reserveName(id, name string) (string, error) {
|
| 556 | 556 |
nameAsKnownByUser := strings.TrimPrefix(name, "/") |
| 557 | 557 |
return "", fmt.Errorf( |
| 558 | 558 |
"Conflict. The name %q is already in use by container %s. You have to delete (or rename) that container to be able to reuse that name.", nameAsKnownByUser, |
| 559 |
- utils.TruncateID(conflictingContainer.ID)) |
|
| 559 |
+ common.TruncateID(conflictingContainer.ID)) |
|
| 560 | 560 |
} |
| 561 | 561 |
} |
| 562 | 562 |
return name, nil |
| ... | ... |
@@ -579,7 +580,7 @@ func (daemon *Daemon) generateNewName(id string) (string, error) {
|
| 579 | 579 |
return name, nil |
| 580 | 580 |
} |
| 581 | 581 |
|
| 582 |
- name = "/" + utils.TruncateID(id) |
|
| 582 |
+ name = "/" + common.TruncateID(id) |
|
| 583 | 583 |
if _, err := daemon.containerGraph.Set(name, id); err != nil {
|
| 584 | 584 |
return "", err |
| 585 | 585 |
} |
| ... | ... |
@@ -12,10 +12,10 @@ import ( |
| 12 | 12 |
"github.com/docker/docker/daemon/execdriver/lxc" |
| 13 | 13 |
"github.com/docker/docker/engine" |
| 14 | 14 |
"github.com/docker/docker/pkg/broadcastwriter" |
| 15 |
+ "github.com/docker/docker/pkg/common" |
|
| 15 | 16 |
"github.com/docker/docker/pkg/ioutils" |
| 16 | 17 |
"github.com/docker/docker/pkg/promise" |
| 17 | 18 |
"github.com/docker/docker/runconfig" |
| 18 |
- "github.com/docker/docker/utils" |
|
| 19 | 19 |
) |
| 20 | 20 |
|
| 21 | 21 |
type execConfig struct {
|
| ... | ... |
@@ -141,7 +141,7 @@ func (d *Daemon) ContainerExecCreate(job *engine.Job) engine.Status {
|
| 141 | 141 |
} |
| 142 | 142 |
|
| 143 | 143 |
execConfig := &execConfig{
|
| 144 |
- ID: utils.GenerateRandomID(), |
|
| 144 |
+ ID: common.GenerateRandomID(), |
|
| 145 | 145 |
OpenStdin: config.AttachStdin, |
| 146 | 146 |
OpenStdout: config.AttachStdout, |
| 147 | 147 |
OpenStderr: config.AttachStderr, |
| ... | ... |
@@ -34,6 +34,7 @@ import ( |
| 34 | 34 |
"github.com/docker/docker/daemon/graphdriver" |
| 35 | 35 |
"github.com/docker/docker/pkg/archive" |
| 36 | 36 |
"github.com/docker/docker/pkg/chrootarchive" |
| 37 |
+ "github.com/docker/docker/pkg/common" |
|
| 37 | 38 |
mountpk "github.com/docker/docker/pkg/mount" |
| 38 | 39 |
"github.com/docker/docker/utils" |
| 39 | 40 |
"github.com/docker/libcontainer/label" |
| ... | ... |
@@ -404,7 +405,7 @@ func (a *Driver) Cleanup() error {
|
| 404 | 404 |
|
| 405 | 405 |
for _, id := range ids {
|
| 406 | 406 |
if err := a.unmount(id); err != nil {
|
| 407 |
- log.Errorf("Unmounting %s: %s", utils.TruncateID(id), err)
|
|
| 407 |
+ log.Errorf("Unmounting %s: %s", common.TruncateID(id), err)
|
|
| 408 | 408 |
} |
| 409 | 409 |
} |
| 410 | 410 |
|
| ... | ... |
@@ -7,8 +7,8 @@ import ( |
| 7 | 7 |
"github.com/docker/docker/engine" |
| 8 | 8 |
"github.com/docker/docker/graph" |
| 9 | 9 |
"github.com/docker/docker/image" |
| 10 |
+ "github.com/docker/docker/pkg/common" |
|
| 10 | 11 |
"github.com/docker/docker/pkg/parsers" |
| 11 |
- "github.com/docker/docker/utils" |
|
| 12 | 12 |
) |
| 13 | 13 |
|
| 14 | 14 |
func (daemon *Daemon) ImageDelete(job *engine.Job) engine.Status {
|
| ... | ... |
@@ -143,11 +143,11 @@ func (daemon *Daemon) canDeleteImage(imgID string, force bool) error {
|
| 143 | 143 |
if imgID == p.ID {
|
| 144 | 144 |
if container.IsRunning() {
|
| 145 | 145 |
if force {
|
| 146 |
- return fmt.Errorf("Conflict, cannot force delete %s because the running container %s is using it, stop it and retry", utils.TruncateID(imgID), utils.TruncateID(container.ID))
|
|
| 146 |
+ return fmt.Errorf("Conflict, cannot force delete %s because the running container %s is using it, stop it and retry", common.TruncateID(imgID), common.TruncateID(container.ID))
|
|
| 147 | 147 |
} |
| 148 |
- return fmt.Errorf("Conflict, cannot delete %s because the running container %s is using it, stop it and use -f to force", utils.TruncateID(imgID), utils.TruncateID(container.ID))
|
|
| 148 |
+ return fmt.Errorf("Conflict, cannot delete %s because the running container %s is using it, stop it and use -f to force", common.TruncateID(imgID), common.TruncateID(container.ID))
|
|
| 149 | 149 |
} else if !force {
|
| 150 |
- return fmt.Errorf("Conflict, cannot delete %s because the container %s is using it, use -f to force", utils.TruncateID(imgID), utils.TruncateID(container.ID))
|
|
| 150 |
+ return fmt.Errorf("Conflict, cannot delete %s because the container %s is using it, use -f to force", common.TruncateID(imgID), common.TruncateID(container.ID))
|
|
| 151 | 151 |
} |
| 152 | 152 |
} |
| 153 | 153 |
return nil |
| ... | ... |
@@ -8,8 +8,8 @@ import ( |
| 8 | 8 |
|
| 9 | 9 |
log "github.com/Sirupsen/logrus" |
| 10 | 10 |
"github.com/docker/docker/daemon/execdriver" |
| 11 |
+ "github.com/docker/docker/pkg/common" |
|
| 11 | 12 |
"github.com/docker/docker/runconfig" |
| 12 |
- "github.com/docker/docker/utils" |
|
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 | 15 |
const defaultTimeIncrement = 100 |
| ... | ... |
@@ -230,7 +230,7 @@ func (m *containerMonitor) shouldRestart(exitCode int) bool {
|
| 230 | 230 |
// the default value of 0 for MaximumRetryCount means that we will not enforce a maximum count |
| 231 | 231 |
if max := m.restartPolicy.MaximumRetryCount; max != 0 && m.failureCount > max {
|
| 232 | 232 |
log.Debugf("stopping restart of container %s because maximum failure could of %d has been reached",
|
| 233 |
- utils.TruncateID(m.container.ID), max) |
|
| 233 |
+ common.TruncateID(m.container.ID), max) |
|
| 234 | 234 |
return false |
| 235 | 235 |
} |
| 236 | 236 |
|
| ... | ... |
@@ -17,6 +17,7 @@ import ( |
| 17 | 17 |
"github.com/docker/docker/daemon/graphdriver" |
| 18 | 18 |
"github.com/docker/docker/image" |
| 19 | 19 |
"github.com/docker/docker/pkg/archive" |
| 20 |
+ "github.com/docker/docker/pkg/common" |
|
| 20 | 21 |
"github.com/docker/docker/pkg/truncindex" |
| 21 | 22 |
"github.com/docker/docker/runconfig" |
| 22 | 23 |
"github.com/docker/docker/utils" |
| ... | ... |
@@ -116,7 +117,7 @@ func (graph *Graph) Get(name string) (*image.Image, error) {
|
| 116 | 116 |
// Create creates a new image and registers it in the graph. |
| 117 | 117 |
func (graph *Graph) Create(layerData archive.ArchiveReader, containerID, containerImage, comment, author string, containerConfig, config *runconfig.Config) (*image.Image, error) {
|
| 118 | 118 |
img := &image.Image{
|
| 119 |
- ID: utils.GenerateRandomID(), |
|
| 119 |
+ ID: common.GenerateRandomID(), |
|
| 120 | 120 |
Comment: comment, |
| 121 | 121 |
Created: time.Now().UTC(), |
| 122 | 122 |
DockerVersion: dockerversion.VERSION, |
| ... | ... |
@@ -209,14 +210,14 @@ func (graph *Graph) TempLayerArchive(id string, sf *utils.StreamFormatter, outpu |
| 209 | 209 |
if err != nil {
|
| 210 | 210 |
return nil, err |
| 211 | 211 |
} |
| 212 |
- progress := utils.ProgressReader(a, 0, output, sf, false, utils.TruncateID(id), "Buffering to disk") |
|
| 212 |
+ progress := utils.ProgressReader(a, 0, output, sf, false, common.TruncateID(id), "Buffering to disk") |
|
| 213 | 213 |
defer progress.Close() |
| 214 | 214 |
return archive.NewTempArchive(progress, tmp) |
| 215 | 215 |
} |
| 216 | 216 |
|
| 217 | 217 |
// Mktemp creates a temporary sub-directory inside the graph's filesystem. |
| 218 | 218 |
func (graph *Graph) Mktemp(id string) (string, error) {
|
| 219 |
- dir := path.Join(graph.Root, "_tmp", utils.GenerateRandomID()) |
|
| 219 |
+ dir := path.Join(graph.Root, "_tmp", common.GenerateRandomID()) |
|
| 220 | 220 |
if err := os.MkdirAll(dir, 0700); err != nil {
|
| 221 | 221 |
return "", err |
| 222 | 222 |
} |
| ... | ... |
@@ -13,6 +13,7 @@ import ( |
| 13 | 13 |
log "github.com/Sirupsen/logrus" |
| 14 | 14 |
"github.com/docker/docker/engine" |
| 15 | 15 |
"github.com/docker/docker/image" |
| 16 |
+ "github.com/docker/docker/pkg/common" |
|
| 16 | 17 |
"github.com/docker/docker/pkg/tarsum" |
| 17 | 18 |
"github.com/docker/docker/registry" |
| 18 | 19 |
"github.com/docker/docker/utils" |
| ... | ... |
@@ -170,9 +171,9 @@ func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo * |
| 170 | 170 |
// ensure no two downloads of the same image happen at the same time |
| 171 | 171 |
if c, err := s.poolAdd("pull", "img:"+img.ID); err != nil {
|
| 172 | 172 |
if c != nil {
|
| 173 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Layer already being pulled by another client. Waiting.", nil)) |
|
| 173 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Layer already being pulled by another client. Waiting.", nil)) |
|
| 174 | 174 |
<-c |
| 175 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Download complete", nil)) |
|
| 175 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil)) |
|
| 176 | 176 |
} else {
|
| 177 | 177 |
log.Debugf("Image (id: %s) pull is already running, skipping: %v", img.ID, err)
|
| 178 | 178 |
} |
| ... | ... |
@@ -183,12 +184,12 @@ func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo * |
| 183 | 183 |
} |
| 184 | 184 |
defer s.poolRemove("pull", "img:"+img.ID)
|
| 185 | 185 |
|
| 186 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s", img.Tag, repoInfo.CanonicalName), nil))
|
|
| 186 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s", img.Tag, repoInfo.CanonicalName), nil))
|
|
| 187 | 187 |
success := false |
| 188 | 188 |
var lastErr, err error |
| 189 | 189 |
var is_downloaded bool |
| 190 | 190 |
for _, ep := range repoInfo.Index.Mirrors {
|
| 191 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s, mirror: %s", img.Tag, repoInfo.CanonicalName, ep), nil))
|
|
| 191 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s, mirror: %s", img.Tag, repoInfo.CanonicalName, ep), nil))
|
|
| 192 | 192 |
if is_downloaded, err = s.pullImage(r, out, img.ID, ep, repoData.Tokens, sf); err != nil {
|
| 193 | 193 |
// Don't report errors when pulling from mirrors. |
| 194 | 194 |
log.Debugf("Error pulling image (%s) from %s, mirror: %s, %s", img.Tag, repoInfo.CanonicalName, ep, err)
|
| ... | ... |
@@ -200,12 +201,12 @@ func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo * |
| 200 | 200 |
} |
| 201 | 201 |
if !success {
|
| 202 | 202 |
for _, ep := range repoData.Endpoints {
|
| 203 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s, endpoint: %s", img.Tag, repoInfo.CanonicalName, ep), nil))
|
|
| 203 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Pulling image (%s) from %s, endpoint: %s", img.Tag, repoInfo.CanonicalName, ep), nil))
|
|
| 204 | 204 |
if is_downloaded, err = s.pullImage(r, out, img.ID, ep, repoData.Tokens, sf); err != nil {
|
| 205 | 205 |
// It's not ideal that only the last error is returned, it would be better to concatenate the errors. |
| 206 | 206 |
// As the error is also given to the output stream the user will see the error. |
| 207 | 207 |
lastErr = err |
| 208 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), fmt.Sprintf("Error pulling image (%s) from %s, endpoint: %s, %s", img.Tag, repoInfo.CanonicalName, ep, err), nil))
|
|
| 208 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), fmt.Sprintf("Error pulling image (%s) from %s, endpoint: %s, %s", img.Tag, repoInfo.CanonicalName, ep, err), nil))
|
|
| 209 | 209 |
continue |
| 210 | 210 |
} |
| 211 | 211 |
layers_downloaded = layers_downloaded || is_downloaded |
| ... | ... |
@@ -215,13 +216,13 @@ func (s *TagStore) pullRepository(r *registry.Session, out io.Writer, repoInfo * |
| 215 | 215 |
} |
| 216 | 216 |
if !success {
|
| 217 | 217 |
err := fmt.Errorf("Error pulling image (%s) from %s, %v", img.Tag, repoInfo.CanonicalName, lastErr)
|
| 218 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), err.Error(), nil)) |
|
| 218 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), err.Error(), nil)) |
|
| 219 | 219 |
if parallel {
|
| 220 | 220 |
errors <- err |
| 221 | 221 |
return |
| 222 | 222 |
} |
| 223 | 223 |
} |
| 224 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Download complete", nil)) |
|
| 224 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil)) |
|
| 225 | 225 |
|
| 226 | 226 |
if parallel {
|
| 227 | 227 |
errors <- nil |
| ... | ... |
@@ -268,7 +269,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint |
| 268 | 268 |
if err != nil {
|
| 269 | 269 |
return false, err |
| 270 | 270 |
} |
| 271 |
- out.Write(sf.FormatProgress(utils.TruncateID(imgID), "Pulling dependent layers", nil)) |
|
| 271 |
+ out.Write(sf.FormatProgress(common.TruncateID(imgID), "Pulling dependent layers", nil)) |
|
| 272 | 272 |
// FIXME: Try to stream the images? |
| 273 | 273 |
// FIXME: Launch the getRemoteImage() in goroutines |
| 274 | 274 |
|
| ... | ... |
@@ -284,7 +285,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint |
| 284 | 284 |
defer s.poolRemove("pull", "layer:"+id)
|
| 285 | 285 |
|
| 286 | 286 |
if !s.graph.Exists(id) {
|
| 287 |
- out.Write(sf.FormatProgress(utils.TruncateID(id), "Pulling metadata", nil)) |
|
| 287 |
+ out.Write(sf.FormatProgress(common.TruncateID(id), "Pulling metadata", nil)) |
|
| 288 | 288 |
var ( |
| 289 | 289 |
imgJSON []byte |
| 290 | 290 |
imgSize int |
| ... | ... |
@@ -295,7 +296,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint |
| 295 | 295 |
for j := 1; j <= retries; j++ {
|
| 296 | 296 |
imgJSON, imgSize, err = r.GetRemoteImageJSON(id, endpoint, token) |
| 297 | 297 |
if err != nil && j == retries {
|
| 298 |
- out.Write(sf.FormatProgress(utils.TruncateID(id), "Error pulling dependent layers", nil)) |
|
| 298 |
+ out.Write(sf.FormatProgress(common.TruncateID(id), "Error pulling dependent layers", nil)) |
|
| 299 | 299 |
return layers_downloaded, err |
| 300 | 300 |
} else if err != nil {
|
| 301 | 301 |
time.Sleep(time.Duration(j) * 500 * time.Millisecond) |
| ... | ... |
@@ -304,7 +305,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint |
| 304 | 304 |
img, err = image.NewImgJSON(imgJSON) |
| 305 | 305 |
layers_downloaded = true |
| 306 | 306 |
if err != nil && j == retries {
|
| 307 |
- out.Write(sf.FormatProgress(utils.TruncateID(id), "Error pulling dependent layers", nil)) |
|
| 307 |
+ out.Write(sf.FormatProgress(common.TruncateID(id), "Error pulling dependent layers", nil)) |
|
| 308 | 308 |
return layers_downloaded, fmt.Errorf("Failed to parse json: %s", err)
|
| 309 | 309 |
} else if err != nil {
|
| 310 | 310 |
time.Sleep(time.Duration(j) * 500 * time.Millisecond) |
| ... | ... |
@@ -320,7 +321,7 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint |
| 320 | 320 |
if j > 1 {
|
| 321 | 321 |
status = fmt.Sprintf("Pulling fs layer [retries: %d]", j)
|
| 322 | 322 |
} |
| 323 |
- out.Write(sf.FormatProgress(utils.TruncateID(id), status, nil)) |
|
| 323 |
+ out.Write(sf.FormatProgress(common.TruncateID(id), status, nil)) |
|
| 324 | 324 |
layer, err := r.GetRemoteImageLayer(img.ID, endpoint, token, int64(imgSize)) |
| 325 | 325 |
if uerr, ok := err.(*url.Error); ok {
|
| 326 | 326 |
err = uerr.Err |
| ... | ... |
@@ -329,26 +330,26 @@ func (s *TagStore) pullImage(r *registry.Session, out io.Writer, imgID, endpoint |
| 329 | 329 |
time.Sleep(time.Duration(j) * 500 * time.Millisecond) |
| 330 | 330 |
continue |
| 331 | 331 |
} else if err != nil {
|
| 332 |
- out.Write(sf.FormatProgress(utils.TruncateID(id), "Error pulling dependent layers", nil)) |
|
| 332 |
+ out.Write(sf.FormatProgress(common.TruncateID(id), "Error pulling dependent layers", nil)) |
|
| 333 | 333 |
return layers_downloaded, err |
| 334 | 334 |
} |
| 335 | 335 |
layers_downloaded = true |
| 336 | 336 |
defer layer.Close() |
| 337 | 337 |
|
| 338 | 338 |
err = s.graph.Register(img, |
| 339 |
- utils.ProgressReader(layer, imgSize, out, sf, false, utils.TruncateID(id), "Downloading")) |
|
| 339 |
+ utils.ProgressReader(layer, imgSize, out, sf, false, common.TruncateID(id), "Downloading")) |
|
| 340 | 340 |
if terr, ok := err.(net.Error); ok && terr.Timeout() && j < retries {
|
| 341 | 341 |
time.Sleep(time.Duration(j) * 500 * time.Millisecond) |
| 342 | 342 |
continue |
| 343 | 343 |
} else if err != nil {
|
| 344 |
- out.Write(sf.FormatProgress(utils.TruncateID(id), "Error downloading dependent layers", nil)) |
|
| 344 |
+ out.Write(sf.FormatProgress(common.TruncateID(id), "Error downloading dependent layers", nil)) |
|
| 345 | 345 |
return layers_downloaded, err |
| 346 | 346 |
} else {
|
| 347 | 347 |
break |
| 348 | 348 |
} |
| 349 | 349 |
} |
| 350 | 350 |
} |
| 351 |
- out.Write(sf.FormatProgress(utils.TruncateID(id), "Download complete", nil)) |
|
| 351 |
+ out.Write(sf.FormatProgress(common.TruncateID(id), "Download complete", nil)) |
|
| 352 | 352 |
} |
| 353 | 353 |
return layers_downloaded, nil |
| 354 | 354 |
} |
| ... | ... |
@@ -463,16 +464,16 @@ func (s *TagStore) pullV2Tag(eng *engine.Engine, r *registry.Session, out io.Wri |
| 463 | 463 |
return false, fmt.Errorf("expected 2 parts in the sumStr, got %#v", chunks)
|
| 464 | 464 |
} |
| 465 | 465 |
sumType, checksum := chunks[0], chunks[1] |
| 466 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Pulling fs layer", nil)) |
|
| 466 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Pulling fs layer", nil)) |
|
| 467 | 467 |
|
| 468 | 468 |
downloadFunc := func(di *downloadInfo) error {
|
| 469 | 469 |
log.Debugf("pulling blob %q to V1 img %s", sumStr, img.ID)
|
| 470 | 470 |
|
| 471 | 471 |
if c, err := s.poolAdd("pull", "img:"+img.ID); err != nil {
|
| 472 | 472 |
if c != nil {
|
| 473 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Layer already being pulled by another client. Waiting.", nil)) |
|
| 473 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Layer already being pulled by another client. Waiting.", nil)) |
|
| 474 | 474 |
<-c |
| 475 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Download complete", nil)) |
|
| 475 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil)) |
|
| 476 | 476 |
} else {
|
| 477 | 477 |
log.Debugf("Image (id: %s) pull is already running, skipping: %v", img.ID, err)
|
| 478 | 478 |
} |
| ... | ... |
@@ -495,16 +496,16 @@ func (s *TagStore) pullV2Tag(eng *engine.Engine, r *registry.Session, out io.Wri |
| 495 | 495 |
return fmt.Errorf("unable to wrap image blob reader with TarSum: %s", err)
|
| 496 | 496 |
} |
| 497 | 497 |
|
| 498 |
- io.Copy(tmpFile, utils.ProgressReader(ioutil.NopCloser(tarSumReader), int(l), out, sf, false, utils.TruncateID(img.ID), "Downloading")) |
|
| 498 |
+ io.Copy(tmpFile, utils.ProgressReader(ioutil.NopCloser(tarSumReader), int(l), out, sf, false, common.TruncateID(img.ID), "Downloading")) |
|
| 499 | 499 |
|
| 500 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Verifying Checksum", nil)) |
|
| 500 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Verifying Checksum", nil)) |
|
| 501 | 501 |
|
| 502 | 502 |
if finalChecksum := tarSumReader.Sum(nil); !strings.EqualFold(finalChecksum, sumStr) {
|
| 503 | 503 |
log.Infof("Image verification failed: checksum mismatch - expected %q but got %q", sumStr, finalChecksum)
|
| 504 | 504 |
verified = false |
| 505 | 505 |
} |
| 506 | 506 |
|
| 507 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Download complete", nil)) |
|
| 507 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Download complete", nil)) |
|
| 508 | 508 |
|
| 509 | 509 |
log.Debugf("Downloaded %s to tempfile %s", img.ID, tmpFile.Name())
|
| 510 | 510 |
di.tmpFile = tmpFile |
| ... | ... |
@@ -545,17 +546,17 @@ func (s *TagStore) pullV2Tag(eng *engine.Engine, r *registry.Session, out io.Wri |
| 545 | 545 |
d.tmpFile.Seek(0, 0) |
| 546 | 546 |
if d.tmpFile != nil {
|
| 547 | 547 |
err = s.graph.Register(d.img, |
| 548 |
- utils.ProgressReader(d.tmpFile, int(d.length), out, sf, false, utils.TruncateID(d.img.ID), "Extracting")) |
|
| 548 |
+ utils.ProgressReader(d.tmpFile, int(d.length), out, sf, false, common.TruncateID(d.img.ID), "Extracting")) |
|
| 549 | 549 |
if err != nil {
|
| 550 | 550 |
return false, err |
| 551 | 551 |
} |
| 552 | 552 |
|
| 553 | 553 |
// FIXME: Pool release here for parallel tag pull (ensures any downloads block until fully extracted) |
| 554 | 554 |
} |
| 555 |
- out.Write(sf.FormatProgress(utils.TruncateID(d.img.ID), "Pull complete", nil)) |
|
| 555 |
+ out.Write(sf.FormatProgress(common.TruncateID(d.img.ID), "Pull complete", nil)) |
|
| 556 | 556 |
layersDownloaded = true |
| 557 | 557 |
} else {
|
| 558 |
- out.Write(sf.FormatProgress(utils.TruncateID(d.img.ID), "Already exists", nil)) |
|
| 558 |
+ out.Write(sf.FormatProgress(common.TruncateID(d.img.ID), "Already exists", nil)) |
|
| 559 | 559 |
} |
| 560 | 560 |
|
| 561 | 561 |
} |
| ... | ... |
@@ -14,6 +14,7 @@ import ( |
| 14 | 14 |
log "github.com/Sirupsen/logrus" |
| 15 | 15 |
"github.com/docker/docker/engine" |
| 16 | 16 |
"github.com/docker/docker/image" |
| 17 |
+ "github.com/docker/docker/pkg/common" |
|
| 17 | 18 |
"github.com/docker/docker/registry" |
| 18 | 19 |
"github.com/docker/docker/utils" |
| 19 | 20 |
"github.com/docker/libtrust" |
| ... | ... |
@@ -129,7 +130,7 @@ func lookupImageOnEndpoint(wg *sync.WaitGroup, r *registry.Session, out io.Write |
| 129 | 129 |
imagesToPush <- image.id |
| 130 | 130 |
continue |
| 131 | 131 |
} |
| 132 |
- out.Write(sf.FormatStatus("", "Image %s already pushed, skipping", utils.TruncateID(image.id)))
|
|
| 132 |
+ out.Write(sf.FormatStatus("", "Image %s already pushed, skipping", common.TruncateID(image.id)))
|
|
| 133 | 133 |
} |
| 134 | 134 |
} |
| 135 | 135 |
|
| ... | ... |
@@ -181,7 +182,7 @@ func (s *TagStore) pushImageToEndpoint(endpoint string, out io.Writer, remoteNam |
| 181 | 181 |
} |
| 182 | 182 |
} |
| 183 | 183 |
for _, tag := range tags[id] {
|
| 184 |
- out.Write(sf.FormatStatus("", "Pushing tag for rev [%s] on {%s}", utils.TruncateID(id), endpoint+"repositories/"+remoteName+"/tags/"+tag))
|
|
| 184 |
+ out.Write(sf.FormatStatus("", "Pushing tag for rev [%s] on {%s}", common.TruncateID(id), endpoint+"repositories/"+remoteName+"/tags/"+tag))
|
|
| 185 | 185 |
if err := r.PushRegistryTag(remoteName, id, tag, endpoint, repo.Tokens); err != nil {
|
| 186 | 186 |
return err |
| 187 | 187 |
} |
| ... | ... |
@@ -234,7 +235,7 @@ func (s *TagStore) pushImage(r *registry.Session, out io.Writer, imgID, ep strin |
| 234 | 234 |
if err != nil {
|
| 235 | 235 |
return "", fmt.Errorf("Cannot retrieve the path for {%s}: %s", imgID, err)
|
| 236 | 236 |
} |
| 237 |
- out.Write(sf.FormatProgress(utils.TruncateID(imgID), "Pushing", nil)) |
|
| 237 |
+ out.Write(sf.FormatProgress(common.TruncateID(imgID), "Pushing", nil)) |
|
| 238 | 238 |
|
| 239 | 239 |
imgData := ®istry.ImgData{
|
| 240 | 240 |
ID: imgID, |
| ... | ... |
@@ -243,7 +244,7 @@ func (s *TagStore) pushImage(r *registry.Session, out io.Writer, imgID, ep strin |
| 243 | 243 |
// Send the json |
| 244 | 244 |
if err := r.PushImageJSONRegistry(imgData, jsonRaw, ep, token); err != nil {
|
| 245 | 245 |
if err == registry.ErrAlreadyExists {
|
| 246 |
- out.Write(sf.FormatProgress(utils.TruncateID(imgData.ID), "Image already pushed, skipping", nil)) |
|
| 246 |
+ out.Write(sf.FormatProgress(common.TruncateID(imgData.ID), "Image already pushed, skipping", nil)) |
|
| 247 | 247 |
return "", nil |
| 248 | 248 |
} |
| 249 | 249 |
return "", err |
| ... | ... |
@@ -258,7 +259,7 @@ func (s *TagStore) pushImage(r *registry.Session, out io.Writer, imgID, ep strin |
| 258 | 258 |
// Send the layer |
| 259 | 259 |
log.Debugf("rendered layer for %s of [%d] size", imgData.ID, layerData.Size)
|
| 260 | 260 |
|
| 261 |
- checksum, checksumPayload, err := r.PushImageLayerRegistry(imgData.ID, utils.ProgressReader(layerData, int(layerData.Size), out, sf, false, utils.TruncateID(imgData.ID), "Pushing"), ep, token, jsonRaw) |
|
| 261 |
+ checksum, checksumPayload, err := r.PushImageLayerRegistry(imgData.ID, utils.ProgressReader(layerData, int(layerData.Size), out, sf, false, common.TruncateID(imgData.ID), "Pushing"), ep, token, jsonRaw) |
|
| 262 | 262 |
if err != nil {
|
| 263 | 263 |
return "", err |
| 264 | 264 |
} |
| ... | ... |
@@ -269,7 +270,7 @@ func (s *TagStore) pushImage(r *registry.Session, out io.Writer, imgID, ep strin |
| 269 | 269 |
return "", err |
| 270 | 270 |
} |
| 271 | 271 |
|
| 272 |
- out.Write(sf.FormatProgress(utils.TruncateID(imgData.ID), "Image successfully pushed", nil)) |
|
| 272 |
+ out.Write(sf.FormatProgress(common.TruncateID(imgData.ID), "Image successfully pushed", nil)) |
|
| 273 | 273 |
return imgData.Checksum, nil |
| 274 | 274 |
} |
| 275 | 275 |
|
| ... | ... |
@@ -359,7 +360,7 @@ func (s *TagStore) pushV2Repository(r *registry.Session, eng *engine.Engine, out |
| 359 | 359 |
// Call mount blob |
| 360 | 360 |
exists, err := r.HeadV2ImageBlob(endpoint, repoInfo.RemoteName, sumParts[0], manifestSum, auth) |
| 361 | 361 |
if err != nil {
|
| 362 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Image push failed", nil)) |
|
| 362 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Image push failed", nil)) |
|
| 363 | 363 |
return err |
| 364 | 364 |
} |
| 365 | 365 |
|
| ... | ... |
@@ -368,7 +369,7 @@ func (s *TagStore) pushV2Repository(r *registry.Session, eng *engine.Engine, out |
| 368 | 368 |
return err |
| 369 | 369 |
} |
| 370 | 370 |
} else {
|
| 371 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Image already exists", nil)) |
|
| 371 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Image already exists", nil)) |
|
| 372 | 372 |
} |
| 373 | 373 |
} |
| 374 | 374 |
|
| ... | ... |
@@ -382,7 +383,7 @@ func (s *TagStore) pushV2Repository(r *registry.Session, eng *engine.Engine, out |
| 382 | 382 |
|
| 383 | 383 |
// PushV2Image pushes the image content to the v2 registry, first buffering the contents to disk |
| 384 | 384 |
func (s *TagStore) pushV2Image(r *registry.Session, img *image.Image, endpoint *registry.Endpoint, imageName, sumType, sumStr string, sf *utils.StreamFormatter, out io.Writer, auth *registry.RequestAuthorization) error {
|
| 385 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Buffering to Disk", nil)) |
|
| 385 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Buffering to Disk", nil)) |
|
| 386 | 386 |
|
| 387 | 387 |
image, err := s.graph.Get(img.ID) |
| 388 | 388 |
if err != nil {
|
| ... | ... |
@@ -411,11 +412,11 @@ func (s *TagStore) pushV2Image(r *registry.Session, img *image.Image, endpoint * |
| 411 | 411 |
// Send the layer |
| 412 | 412 |
log.Debugf("rendered layer for %s of [%d] size", img.ID, size)
|
| 413 | 413 |
|
| 414 |
- if err := r.PutV2ImageBlob(endpoint, imageName, sumType, sumStr, utils.ProgressReader(tf, int(size), out, sf, false, utils.TruncateID(img.ID), "Pushing"), auth); err != nil {
|
|
| 415 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Image push failed", nil)) |
|
| 414 |
+ if err := r.PutV2ImageBlob(endpoint, imageName, sumType, sumStr, utils.ProgressReader(tf, int(size), out, sf, false, common.TruncateID(img.ID), "Pushing"), auth); err != nil {
|
|
| 415 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Image push failed", nil)) |
|
| 416 | 416 |
return err |
| 417 | 417 |
} |
| 418 |
- out.Write(sf.FormatProgress(utils.TruncateID(img.ID), "Image successfully pushed", nil)) |
|
| 418 |
+ out.Write(sf.FormatProgress(common.TruncateID(img.ID), "Image successfully pushed", nil)) |
|
| 419 | 419 |
return nil |
| 420 | 420 |
} |
| 421 | 421 |
|
| ... | ... |
@@ -12,9 +12,9 @@ import ( |
| 12 | 12 |
"sync" |
| 13 | 13 |
|
| 14 | 14 |
"github.com/docker/docker/image" |
| 15 |
+ "github.com/docker/docker/pkg/common" |
|
| 15 | 16 |
"github.com/docker/docker/pkg/parsers" |
| 16 | 17 |
"github.com/docker/docker/registry" |
| 17 |
- "github.com/docker/docker/utils" |
|
| 18 | 18 |
"github.com/docker/libtrust" |
| 19 | 19 |
) |
| 20 | 20 |
|
| ... | ... |
@@ -148,7 +148,7 @@ func (store *TagStore) ImageName(id string) string {
|
| 148 | 148 |
if names, exists := store.ByID()[id]; exists && len(names) > 0 {
|
| 149 | 149 |
return names[0] |
| 150 | 150 |
} |
| 151 |
- return utils.TruncateID(id) |
|
| 151 |
+ return common.TruncateID(id) |
|
| 152 | 152 |
} |
| 153 | 153 |
|
| 154 | 154 |
func (store *TagStore) DeleteAll(id string) error {
|
| ... | ... |
@@ -274,7 +274,7 @@ func (store *TagStore) GetRepoRefs() map[string][]string {
|
| 274 | 274 |
|
| 275 | 275 |
for name, repository := range store.Repositories {
|
| 276 | 276 |
for tag, id := range repository {
|
| 277 |
- shortID := utils.TruncateID(id) |
|
| 277 |
+ shortID := common.TruncateID(id) |
|
| 278 | 278 |
reporefs[shortID] = append(reporefs[shortID], fmt.Sprintf("%s:%s", name, tag))
|
| 279 | 279 |
} |
| 280 | 280 |
} |
| ... | ... |
@@ -12,8 +12,8 @@ import ( |
| 12 | 12 |
log "github.com/Sirupsen/logrus" |
| 13 | 13 |
"github.com/docker/docker/api/client" |
| 14 | 14 |
"github.com/docker/docker/daemon" |
| 15 |
+ "github.com/docker/docker/pkg/common" |
|
| 15 | 16 |
"github.com/docker/docker/pkg/term" |
| 16 |
- "github.com/docker/docker/utils" |
|
| 17 | 17 |
"github.com/kr/pty" |
| 18 | 18 |
) |
| 19 | 19 |
|
| ... | ... |
@@ -286,7 +286,7 @@ func TestAttachDetachTruncatedID(t *testing.T) {
|
| 286 | 286 |
ch := make(chan struct{})
|
| 287 | 287 |
go func() {
|
| 288 | 288 |
defer close(ch) |
| 289 |
- if err := cli.CmdAttach(utils.TruncateID(container.ID)); err != nil {
|
|
| 289 |
+ if err := cli.CmdAttach(common.TruncateID(container.ID)); err != nil {
|
|
| 290 | 290 |
if err != io.ErrClosedPipe {
|
| 291 | 291 |
t.Fatal(err) |
| 292 | 292 |
} |
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
"github.com/docker/docker/graph" |
| 8 | 8 |
"github.com/docker/docker/image" |
| 9 | 9 |
"github.com/docker/docker/pkg/archive" |
| 10 |
+ "github.com/docker/docker/pkg/common" |
|
| 10 | 11 |
"github.com/docker/docker/utils" |
| 11 | 12 |
"io" |
| 12 | 13 |
"io/ioutil" |
| ... | ... |
@@ -69,7 +70,7 @@ func TestInterruptedRegister(t *testing.T) {
|
| 69 | 69 |
defer nukeGraph(graph) |
| 70 | 70 |
badArchive, w := io.Pipe() // Use a pipe reader as a fake archive which never yields data |
| 71 | 71 |
image := &image.Image{
|
| 72 |
- ID: utils.GenerateRandomID(), |
|
| 72 |
+ ID: common.GenerateRandomID(), |
|
| 73 | 73 |
Comment: "testing", |
| 74 | 74 |
Created: time.Now(), |
| 75 | 75 |
} |
| ... | ... |
@@ -129,7 +130,7 @@ func TestRegister(t *testing.T) {
|
| 129 | 129 |
t.Fatal(err) |
| 130 | 130 |
} |
| 131 | 131 |
image := &image.Image{
|
| 132 |
- ID: utils.GenerateRandomID(), |
|
| 132 |
+ ID: common.GenerateRandomID(), |
|
| 133 | 133 |
Comment: "testing", |
| 134 | 134 |
Created: time.Now(), |
| 135 | 135 |
} |
| ... | ... |
@@ -159,7 +160,7 @@ func TestDeletePrefix(t *testing.T) {
|
| 159 | 159 |
graph, _ := tempGraph(t) |
| 160 | 160 |
defer nukeGraph(graph) |
| 161 | 161 |
img := createTestImage(graph, t) |
| 162 |
- if err := graph.Delete(utils.TruncateID(img.ID)); err != nil {
|
|
| 162 |
+ if err := graph.Delete(common.TruncateID(img.ID)); err != nil {
|
|
| 163 | 163 |
t.Fatal(err) |
| 164 | 164 |
} |
| 165 | 165 |
assertNImages(graph, t, 0) |
| ... | ... |
@@ -245,19 +246,19 @@ func TestByParent(t *testing.T) {
|
| 245 | 245 |
graph, _ := tempGraph(t) |
| 246 | 246 |
defer nukeGraph(graph) |
| 247 | 247 |
parentImage := &image.Image{
|
| 248 |
- ID: utils.GenerateRandomID(), |
|
| 248 |
+ ID: common.GenerateRandomID(), |
|
| 249 | 249 |
Comment: "parent", |
| 250 | 250 |
Created: time.Now(), |
| 251 | 251 |
Parent: "", |
| 252 | 252 |
} |
| 253 | 253 |
childImage1 := &image.Image{
|
| 254 |
- ID: utils.GenerateRandomID(), |
|
| 254 |
+ ID: common.GenerateRandomID(), |
|
| 255 | 255 |
Comment: "child1", |
| 256 | 256 |
Created: time.Now(), |
| 257 | 257 |
Parent: parentImage.ID, |
| 258 | 258 |
} |
| 259 | 259 |
childImage2 := &image.Image{
|
| 260 |
- ID: utils.GenerateRandomID(), |
|
| 260 |
+ ID: common.GenerateRandomID(), |
|
| 261 | 261 |
Comment: "child2", |
| 262 | 262 |
Created: time.Now(), |
| 263 | 263 |
Parent: parentImage.ID, |
| ... | ... |
@@ -22,6 +22,7 @@ import ( |
| 22 | 22 |
"github.com/docker/docker/engine" |
| 23 | 23 |
"github.com/docker/docker/image" |
| 24 | 24 |
"github.com/docker/docker/nat" |
| 25 |
+ "github.com/docker/docker/pkg/common" |
|
| 25 | 26 |
"github.com/docker/docker/pkg/ioutils" |
| 26 | 27 |
"github.com/docker/docker/pkg/reexec" |
| 27 | 28 |
"github.com/docker/docker/runconfig" |
| ... | ... |
@@ -305,7 +306,7 @@ func TestDaemonCreate(t *testing.T) {
|
| 305 | 305 |
&runconfig.HostConfig{},
|
| 306 | 306 |
"conflictname", |
| 307 | 307 |
) |
| 308 |
- if _, _, err := daemon.Create(&runconfig.Config{Image: GetTestImage(daemon).ID, Cmd: []string{"ls", "-al"}}, &runconfig.HostConfig{}, testContainer.Name); err == nil || !strings.Contains(err.Error(), utils.TruncateID(testContainer.ID)) {
|
|
| 308 |
+ if _, _, err := daemon.Create(&runconfig.Config{Image: GetTestImage(daemon).ID, Cmd: []string{"ls", "-al"}}, &runconfig.HostConfig{}, testContainer.Name); err == nil || !strings.Contains(err.Error(), common.TruncateID(testContainer.ID)) {
|
|
| 309 | 309 |
t.Fatalf("Name conflict error doesn't include the correct short id. Message was: %s", err.Error())
|
| 310 | 310 |
} |
| 311 | 311 |
|
| 312 | 312 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,38 @@ |
| 0 |
+package common |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "crypto/rand" |
|
| 4 |
+ "encoding/hex" |
|
| 5 |
+ "io" |
|
| 6 |
+ "strconv" |
|
| 7 |
+) |
|
| 8 |
+ |
|
| 9 |
+// TruncateID returns a shorthand version of a string identifier for convenience. |
|
| 10 |
+// A collision with other shorthands is very unlikely, but possible. |
|
| 11 |
+// In case of a collision a lookup with TruncIndex.Get() will fail, and the caller |
|
| 12 |
+// will need to use a langer prefix, or the full-length Id. |
|
| 13 |
+func TruncateID(id string) string {
|
|
| 14 |
+ shortLen := 12 |
|
| 15 |
+ if len(id) < shortLen {
|
|
| 16 |
+ shortLen = len(id) |
|
| 17 |
+ } |
|
| 18 |
+ return id[:shortLen] |
|
| 19 |
+} |
|
| 20 |
+ |
|
| 21 |
+// GenerateRandomID returns an unique id |
|
| 22 |
+func GenerateRandomID() string {
|
|
| 23 |
+ for {
|
|
| 24 |
+ id := make([]byte, 32) |
|
| 25 |
+ if _, err := io.ReadFull(rand.Reader, id); err != nil {
|
|
| 26 |
+ panic(err) // This shouldn't happen |
|
| 27 |
+ } |
|
| 28 |
+ value := hex.EncodeToString(id) |
|
| 29 |
+ // if we try to parse the truncated for as an int and we don't have |
|
| 30 |
+ // an error then the value is all numberic and causes issues when |
|
| 31 |
+ // used as a hostname. ref #3869 |
|
| 32 |
+ if _, err := strconv.ParseInt(TruncateID(value), 10, 64); err == nil {
|
|
| 33 |
+ continue |
|
| 34 |
+ } |
|
| 35 |
+ return value |
|
| 36 |
+ } |
|
| 37 |
+} |
| ... | ... |
@@ -4,7 +4,7 @@ import ( |
| 4 | 4 |
"math/rand" |
| 5 | 5 |
"testing" |
| 6 | 6 |
|
| 7 |
- "github.com/docker/docker/utils" |
|
| 7 |
+ "github.com/docker/docker/pkg/common" |
|
| 8 | 8 |
) |
| 9 | 9 |
|
| 10 | 10 |
// Test the behavior of TruncIndex, an index for querying IDs from a non-conflicting prefix. |
| ... | ... |
@@ -111,7 +111,7 @@ func assertIndexGet(t *testing.T, index *TruncIndex, input, expectedResult strin |
| 111 | 111 |
func BenchmarkTruncIndexAdd100(b *testing.B) {
|
| 112 | 112 |
var testSet []string |
| 113 | 113 |
for i := 0; i < 100; i++ {
|
| 114 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 114 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 115 | 115 |
} |
| 116 | 116 |
b.ResetTimer() |
| 117 | 117 |
for i := 0; i < b.N; i++ {
|
| ... | ... |
@@ -127,7 +127,7 @@ func BenchmarkTruncIndexAdd100(b *testing.B) {
|
| 127 | 127 |
func BenchmarkTruncIndexAdd250(b *testing.B) {
|
| 128 | 128 |
var testSet []string |
| 129 | 129 |
for i := 0; i < 250; i++ {
|
| 130 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 130 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 131 | 131 |
} |
| 132 | 132 |
b.ResetTimer() |
| 133 | 133 |
for i := 0; i < b.N; i++ {
|
| ... | ... |
@@ -143,7 +143,7 @@ func BenchmarkTruncIndexAdd250(b *testing.B) {
|
| 143 | 143 |
func BenchmarkTruncIndexAdd500(b *testing.B) {
|
| 144 | 144 |
var testSet []string |
| 145 | 145 |
for i := 0; i < 500; i++ {
|
| 146 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 146 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 147 | 147 |
} |
| 148 | 148 |
b.ResetTimer() |
| 149 | 149 |
for i := 0; i < b.N; i++ {
|
| ... | ... |
@@ -160,7 +160,7 @@ func BenchmarkTruncIndexGet100(b *testing.B) {
|
| 160 | 160 |
var testSet []string |
| 161 | 161 |
var testKeys []string |
| 162 | 162 |
for i := 0; i < 100; i++ {
|
| 163 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 163 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 164 | 164 |
} |
| 165 | 165 |
index := NewTruncIndex([]string{})
|
| 166 | 166 |
for _, id := range testSet {
|
| ... | ... |
@@ -184,7 +184,7 @@ func BenchmarkTruncIndexGet250(b *testing.B) {
|
| 184 | 184 |
var testSet []string |
| 185 | 185 |
var testKeys []string |
| 186 | 186 |
for i := 0; i < 250; i++ {
|
| 187 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 187 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 188 | 188 |
} |
| 189 | 189 |
index := NewTruncIndex([]string{})
|
| 190 | 190 |
for _, id := range testSet {
|
| ... | ... |
@@ -208,7 +208,7 @@ func BenchmarkTruncIndexGet500(b *testing.B) {
|
| 208 | 208 |
var testSet []string |
| 209 | 209 |
var testKeys []string |
| 210 | 210 |
for i := 0; i < 500; i++ {
|
| 211 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 211 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 212 | 212 |
} |
| 213 | 213 |
index := NewTruncIndex([]string{})
|
| 214 | 214 |
for _, id := range testSet {
|
| ... | ... |
@@ -231,7 +231,7 @@ func BenchmarkTruncIndexGet500(b *testing.B) {
|
| 231 | 231 |
func BenchmarkTruncIndexDelete100(b *testing.B) {
|
| 232 | 232 |
var testSet []string |
| 233 | 233 |
for i := 0; i < 100; i++ {
|
| 234 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 234 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 235 | 235 |
} |
| 236 | 236 |
b.ResetTimer() |
| 237 | 237 |
for i := 0; i < b.N; i++ {
|
| ... | ... |
@@ -254,7 +254,7 @@ func BenchmarkTruncIndexDelete100(b *testing.B) {
|
| 254 | 254 |
func BenchmarkTruncIndexDelete250(b *testing.B) {
|
| 255 | 255 |
var testSet []string |
| 256 | 256 |
for i := 0; i < 250; i++ {
|
| 257 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 257 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 258 | 258 |
} |
| 259 | 259 |
b.ResetTimer() |
| 260 | 260 |
for i := 0; i < b.N; i++ {
|
| ... | ... |
@@ -277,7 +277,7 @@ func BenchmarkTruncIndexDelete250(b *testing.B) {
|
| 277 | 277 |
func BenchmarkTruncIndexDelete500(b *testing.B) {
|
| 278 | 278 |
var testSet []string |
| 279 | 279 |
for i := 0; i < 500; i++ {
|
| 280 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 280 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 281 | 281 |
} |
| 282 | 282 |
b.ResetTimer() |
| 283 | 283 |
for i := 0; i < b.N; i++ {
|
| ... | ... |
@@ -300,7 +300,7 @@ func BenchmarkTruncIndexDelete500(b *testing.B) {
|
| 300 | 300 |
func BenchmarkTruncIndexNew100(b *testing.B) {
|
| 301 | 301 |
var testSet []string |
| 302 | 302 |
for i := 0; i < 100; i++ {
|
| 303 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 303 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 304 | 304 |
} |
| 305 | 305 |
b.ResetTimer() |
| 306 | 306 |
for i := 0; i < b.N; i++ {
|
| ... | ... |
@@ -311,7 +311,7 @@ func BenchmarkTruncIndexNew100(b *testing.B) {
|
| 311 | 311 |
func BenchmarkTruncIndexNew250(b *testing.B) {
|
| 312 | 312 |
var testSet []string |
| 313 | 313 |
for i := 0; i < 250; i++ {
|
| 314 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 314 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 315 | 315 |
} |
| 316 | 316 |
b.ResetTimer() |
| 317 | 317 |
for i := 0; i < b.N; i++ {
|
| ... | ... |
@@ -322,7 +322,7 @@ func BenchmarkTruncIndexNew250(b *testing.B) {
|
| 322 | 322 |
func BenchmarkTruncIndexNew500(b *testing.B) {
|
| 323 | 323 |
var testSet []string |
| 324 | 324 |
for i := 0; i < 500; i++ {
|
| 325 |
- testSet = append(testSet, utils.GenerateRandomID()) |
|
| 325 |
+ testSet = append(testSet, common.GenerateRandomID()) |
|
| 326 | 326 |
} |
| 327 | 327 |
b.ResetTimer() |
| 328 | 328 |
for i := 0; i < b.N; i++ {
|
| ... | ... |
@@ -334,7 +334,7 @@ func BenchmarkTruncIndexAddGet100(b *testing.B) {
|
| 334 | 334 |
var testSet []string |
| 335 | 335 |
var testKeys []string |
| 336 | 336 |
for i := 0; i < 500; i++ {
|
| 337 |
- id := utils.GenerateRandomID() |
|
| 337 |
+ id := common.GenerateRandomID() |
|
| 338 | 338 |
testSet = append(testSet, id) |
| 339 | 339 |
l := rand.Intn(12) + 12 |
| 340 | 340 |
testKeys = append(testKeys, id[:l]) |
| ... | ... |
@@ -359,7 +359,7 @@ func BenchmarkTruncIndexAddGet250(b *testing.B) {
|
| 359 | 359 |
var testSet []string |
| 360 | 360 |
var testKeys []string |
| 361 | 361 |
for i := 0; i < 500; i++ {
|
| 362 |
- id := utils.GenerateRandomID() |
|
| 362 |
+ id := common.GenerateRandomID() |
|
| 363 | 363 |
testSet = append(testSet, id) |
| 364 | 364 |
l := rand.Intn(12) + 12 |
| 365 | 365 |
testKeys = append(testKeys, id[:l]) |
| ... | ... |
@@ -384,7 +384,7 @@ func BenchmarkTruncIndexAddGet500(b *testing.B) {
|
| 384 | 384 |
var testSet []string |
| 385 | 385 |
var testKeys []string |
| 386 | 386 |
for i := 0; i < 500; i++ {
|
| 387 |
- id := utils.GenerateRandomID() |
|
| 387 |
+ id := common.GenerateRandomID() |
|
| 388 | 388 |
testSet = append(testSet, id) |
| 389 | 389 |
l := rand.Intn(12) + 12 |
| 390 | 390 |
testKeys = append(testKeys, id[:l]) |
| ... | ... |
@@ -3,7 +3,6 @@ package utils |
| 3 | 3 |
import ( |
| 4 | 4 |
"bufio" |
| 5 | 5 |
"bytes" |
| 6 |
- "crypto/rand" |
|
| 7 | 6 |
"crypto/sha1" |
| 8 | 7 |
"crypto/sha256" |
| 9 | 8 |
"encoding/hex" |
| ... | ... |
@@ -16,7 +15,6 @@ import ( |
| 16 | 16 |
"path/filepath" |
| 17 | 17 |
"regexp" |
| 18 | 18 |
"runtime" |
| 19 |
- "strconv" |
|
| 20 | 19 |
"strings" |
| 21 | 20 |
"sync" |
| 22 | 21 |
|
| ... | ... |
@@ -164,36 +162,6 @@ func GetTotalUsedFds() int {
|
| 164 | 164 |
return -1 |
| 165 | 165 |
} |
| 166 | 166 |
|
| 167 |
-// TruncateID returns a shorthand version of a string identifier for convenience. |
|
| 168 |
-// A collision with other shorthands is very unlikely, but possible. |
|
| 169 |
-// In case of a collision a lookup with TruncIndex.Get() will fail, and the caller |
|
| 170 |
-// will need to use a langer prefix, or the full-length Id. |
|
| 171 |
-func TruncateID(id string) string {
|
|
| 172 |
- shortLen := 12 |
|
| 173 |
- if len(id) < shortLen {
|
|
| 174 |
- shortLen = len(id) |
|
| 175 |
- } |
|
| 176 |
- return id[:shortLen] |
|
| 177 |
-} |
|
| 178 |
- |
|
| 179 |
-// GenerateRandomID returns an unique id |
|
| 180 |
-func GenerateRandomID() string {
|
|
| 181 |
- for {
|
|
| 182 |
- id := make([]byte, 32) |
|
| 183 |
- if _, err := io.ReadFull(rand.Reader, id); err != nil {
|
|
| 184 |
- panic(err) // This shouldn't happen |
|
| 185 |
- } |
|
| 186 |
- value := hex.EncodeToString(id) |
|
| 187 |
- // if we try to parse the truncated for as an int and we don't have |
|
| 188 |
- // an error then the value is all numberic and causes issues when |
|
| 189 |
- // used as a hostname. ref #3869 |
|
| 190 |
- if _, err := strconv.ParseInt(TruncateID(value), 10, 64); err == nil {
|
|
| 191 |
- continue |
|
| 192 |
- } |
|
| 193 |
- return value |
|
| 194 |
- } |
|
| 195 |
-} |
|
| 196 |
- |
|
| 197 | 167 |
func ValidateID(id string) error {
|
| 198 | 168 |
if ok := validHex.MatchString(id); !ok {
|
| 199 | 169 |
err := fmt.Errorf("image ID '%s' is invalid", id)
|
| ... | ... |
@@ -9,7 +9,7 @@ import ( |
| 9 | 9 |
|
| 10 | 10 |
log "github.com/Sirupsen/logrus" |
| 11 | 11 |
"github.com/docker/docker/daemon/graphdriver" |
| 12 |
- "github.com/docker/docker/utils" |
|
| 12 |
+ "github.com/docker/docker/pkg/common" |
|
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 | 15 |
type Repository struct {
|
| ... | ... |
@@ -43,7 +43,7 @@ func (r *Repository) newVolume(path string, writable bool) (*Volume, error) {
|
| 43 | 43 |
var ( |
| 44 | 44 |
isBindMount bool |
| 45 | 45 |
err error |
| 46 |
- id = utils.GenerateRandomID() |
|
| 46 |
+ id = common.GenerateRandomID() |
|
| 47 | 47 |
) |
| 48 | 48 |
if path != "" {
|
| 49 | 49 |
isBindMount = true |