From 697707e4afe6f1e7e5e33c24ada2f1f2af279142 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 5 Dec 2013 14:03:23 -0800 Subject: [PATCH] Save layersize on pull Do not display size and virtual size on the cli. Only display virtual size on the cli --- commands.go | 9 ++----- docs/sources/commandline/cli.rst | 44 ++++++++++++++++---------------- graph.go | 22 +++++++++++++--- image.go | 32 ++++++++++++----------- integration/commands_test.go | 2 +- 5 files changed, 60 insertions(+), 49 deletions(-) diff --git a/commands.go b/commands.go index 9df91d723e..b7e7c08cac 100644 --- a/commands.go +++ b/commands.go @@ -1200,7 +1200,7 @@ func (cli *DockerCli) CmdImages(args ...string) error { w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0) if !*quiet { - fmt.Fprintln(w, "REPOSITORY\tTAG\tIMAGE ID\tCREATED\tSIZE") + fmt.Fprintln(w, "REPOSITORY\tTAG\tIMAGE ID\tCREATED\tVIRTUAL SIZE") } for _, out := range outs { @@ -1213,12 +1213,7 @@ func (cli *DockerCli) CmdImages(args ...string) error { } if !*quiet { - fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t", repo, tag, out.ID, utils.HumanDuration(time.Now().UTC().Sub(time.Unix(out.Created, 0)))) - if out.VirtualSize > 0 { - fmt.Fprintf(w, "%s (virtual %s)\n", utils.HumanSize(out.Size), utils.HumanSize(out.VirtualSize)) - } else { - fmt.Fprintf(w, "%s\n", utils.HumanSize(out.Size)) - } + fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\n", repo, tag, out.ID, utils.HumanDuration(time.Now().UTC().Sub(time.Unix(out.Created, 0))), utils.HumanSize(out.VirtualSize)) } else { fmt.Fprintln(w, out.ID) } diff --git a/docs/sources/commandline/cli.rst b/docs/sources/commandline/cli.rst index d7bb03b954..a2132476c9 100644 --- a/docs/sources/commandline/cli.rst +++ b/docs/sources/commandline/cli.rst @@ -237,8 +237,8 @@ Simple commit of an existing container $ docker commit c3f279d17e0a SvenDowideit/testimage:version3 f5283438590d $ docker images | head - REPOSITORY TAG ID CREATED SIZE - SvenDowideit/testimage version3 f5283438590d 16 seconds ago 204.2 MB (virtual 335.7 MB) + REPOSITORY TAG ID CREATED VIRTUAL SIZE + SvenDowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB Full -run example @@ -481,16 +481,16 @@ Listing the most recently created images .. code-block:: bash $ sudo docker images | head - REPOSITORY TAG IMAGE ID CREATED SIZE - 77af4d6b9913 19 hours ago 30.53 MB (virtual 1.089 GB) - committest latest b6fa739cedf5 19 hours ago 30.53 MB (virtual 1.089 GB) - 78a85c484f71 19 hours ago 30.53 MB (virtual 1.089 GB) - docker latest 30557a29d5ab 20 hours ago 30.53 MB (virtual 1.089 GB) - 0124422dd9f9 20 hours ago 30.53 MB (virtual 1.089 GB) - 18ad6fad3402 22 hours ago 23.68 MB (virtual 1.082 GB) - f9f1e26352f0 23 hours ago 30.46 MB (virtual 1.089 GB) - tryout latest 2629d1fa0b81 23 hours ago 16.4 kB (virtual 131.5 MB) - 5ed6274db6ce 24 hours ago 30.44 MB (virtual 1.089 GB) + REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE + 77af4d6b9913 19 hours ago 1.089 GB + committest latest b6fa739cedf5 19 hours ago 1.089 GB + 78a85c484f71 19 hours ago 1.089 GB + docker latest 30557a29d5ab 20 hours ago 1.089 GB + 0124422dd9f9 20 hours ago 1.089 GB + 18ad6fad3402 22 hours ago 1.082 GB + f9f1e26352f0 23 hours ago 1.089 GB + tryout latest 2629d1fa0b81 23 hours ago 131.5 MB + 5ed6274db6ce 24 hours ago 1.089 GB Listing the full length image IDs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -498,16 +498,16 @@ Listing the full length image IDs .. code-block:: bash $ sudo docker images -notrunc | head - REPOSITORY TAG IMAGE ID CREATED SIZE - 77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 30.53 MB (virtual 1.089 GB) - committest latest b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 30.53 MB (virtual 1.089 GB) - 78a85c484f71509adeaace20e72e941f6bdd2b25b4c75da8693efd9f61a37921 19 hours ago 30.53 MB (virtual 1.089 GB) - docker latest 30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago 30.53 MB (virtual 1.089 GB) - 0124422dd9f9cf7ef15c0617cda3931ee68346455441d66ab8bdc5b05e9fdce5 20 hours ago 30.53 MB (virtual 1.089 GB) - 18ad6fad340262ac2a636efd98a6d1f0ea775ae3d45240d3418466495a19a81b 22 hours ago 23.68 MB (virtual 1.082 GB) - f9f1e26352f0a3ba6a0ff68167559f64f3e21ff7ada60366e2d44a04befd1d3a 23 hours ago 30.46 MB (virtual 1.089 GB) - tryout latest 2629d1fa0b81b222fca63371ca16cbf6a0772d07759ff80e8d1369b926940074 23 hours ago 16.4 kB (virtual 131.5 MB) - 5ed6274db6ceb2397844896966ea239290555e74ef307030ebb01ff91b1914df 24 hours ago 30.44 MB (virtual 1.089 GB) + REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE + 77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 1.089 GB + committest latest b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 1.089 GB + 78a85c484f71509adeaace20e72e941f6bdd2b25b4c75da8693efd9f61a37921 19 hours ago 1.089 GB + docker latest 30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago 1.089 GB + 0124422dd9f9cf7ef15c0617cda3931ee68346455441d66ab8bdc5b05e9fdce5 20 hours ago 1.089 GB + 18ad6fad340262ac2a636efd98a6d1f0ea775ae3d45240d3418466495a19a81b 22 hours ago 1.082 GB + f9f1e26352f0a3ba6a0ff68167559f64f3e21ff7ada60366e2d44a04befd1d3a 23 hours ago 1.089 GB + tryout latest 2629d1fa0b81b222fca63371ca16cbf6a0772d07759ff80e8d1369b926940074 23 hours ago 131.5 MB + 5ed6274db6ceb2397844896966ea239290555e74ef307030ebb01ff91b1914df 24 hours ago 1.089 GB Displaying images visually ~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/graph.go b/graph.go index 19c668830e..82128bfe15 100644 --- a/graph.go +++ b/graph.go @@ -94,11 +94,25 @@ func (graph *Graph) Get(name string) (*Image, error) { return nil, fmt.Errorf("Image stored at '%s' has wrong id '%s'", id, img.ID) } img.graph = graph - if img.Size == 0 { - size, err := utils.TreeSize(rootfs) - if err != nil { - return nil, fmt.Errorf("Error computing size of rootfs %s: %s", img.ID, err) + + if img.Size < 0 { + var size int64 + if img.Parent == "" { + if size, err = utils.TreeSize(rootfs); err != nil { + return nil, err + } + } else { + parentFs, err := graph.driver.Get(img.Parent) + if err != nil { + return nil, err + } + changes, err := archive.ChangesDirs(rootfs, parentFs) + if err != nil { + return nil, err + } + size = archive.ChangesSize(rootfs, changes) } + img.Size = size if err := img.SaveSize(graph.imageRoot(id)); err != nil { return nil, err diff --git a/image.go b/image.go index 5a0b043fc7..0f07a74ee8 100644 --- a/image.go +++ b/image.go @@ -51,6 +51,9 @@ func LoadImage(root string) (*Image, error) { if !os.IsNotExist(err) { return nil, err } + // If the layersize file does not exist then set the size to a negative number + // because a layer size of 0 (zero) is valid + img.Size = -1 } else { size, err := strconv.Atoi(string(buf)) if err != nil { @@ -104,30 +107,29 @@ func StoreImage(img *Image, jsonData []byte, layerData archive.Archive, root, la if err != nil { return err } - if size = archive.ChangesSize(layer, changes); err != nil { - return err - } + size = archive.ChangesSize(layer, changes) } } } - // If raw json is provided, then use it - if jsonData != nil { - return ioutil.WriteFile(jsonPath(root), jsonData, 0600) - } - // Otherwise, unmarshal the image - if jsonData, err = json.Marshal(img); err != nil { - return err - } - if err := ioutil.WriteFile(jsonPath(root), jsonData, 0600); err != nil { - return err - } - img.Size = size if err := img.SaveSize(root); err != nil { return err } + // If raw json is provided, then use it + if jsonData != nil { + if err := ioutil.WriteFile(jsonPath(root), jsonData, 0600); err != nil { + return err + } + } else { + if jsonData, err = json.Marshal(img); err != nil { + return err + } + if err := ioutil.WriteFile(jsonPath(root), jsonData, 0600); err != nil { + return err + } + } return nil } diff --git a/integration/commands_test.go b/integration/commands_test.go index 129a1575f8..16e2b3fb02 100644 --- a/integration/commands_test.go +++ b/integration/commands_test.go @@ -871,7 +871,7 @@ func TestImagesTree(t *testing.T) { "(?m) └─[0-9a-f]+.*", "(?m) └─[0-9a-f]+.*", "(?m) └─[0-9a-f]+.*", - fmt.Sprintf("(?m)^ └─%s Size: \\d+.\\d+ MB \\(virtual \\d+.\\d+ MB\\) Tags: test:latest", utils.TruncateID(image.ID)), + fmt.Sprintf("(?m)^ └─%s Size: \\d+ B \\(virtual \\d+.\\d+ MB\\) Tags: test:latest", utils.TruncateID(image.ID)), } compiledRegexps := []*regexp.Regexp{}