graph: exported images times matching creation
| ... | ... |
@@ -2,10 +2,12 @@ package graph |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/json" |
| 5 |
+ "fmt" |
|
| 5 | 6 |
"io" |
| 6 | 7 |
"io/ioutil" |
| 7 | 8 |
"os" |
| 8 | 9 |
"path/filepath" |
| 10 |
+ "time" |
|
| 9 | 11 |
|
| 10 | 12 |
"github.com/Sirupsen/logrus" |
| 11 | 13 |
"github.com/docker/docker/pkg/archive" |
| ... | ... |
@@ -88,6 +90,9 @@ func (s *TagStore) ImageExport(names []string, outStream io.Writer) error {
|
| 88 | 88 |
if err := f.Close(); err != nil {
|
| 89 | 89 |
return err |
| 90 | 90 |
} |
| 91 |
+ if err := os.Chtimes(filepath.Join(tempdir, "repositories"), time.Unix(0, 0), time.Unix(0, 0)); err != nil {
|
|
| 92 |
+ return err |
|
| 93 |
+ } |
|
| 91 | 94 |
} else {
|
| 92 | 95 |
logrus.Debugf("There were no repositories to write")
|
| 93 | 96 |
} |
| ... | ... |
@@ -128,7 +133,11 @@ func (s *TagStore) exportImage(name, tempdir string) error {
|
| 128 | 128 |
if err != nil {
|
| 129 | 129 |
return err |
| 130 | 130 |
} |
| 131 |
- imageInspectRaw, err := s.lookupRaw(n) |
|
| 131 |
+ img, err := s.LookupImage(n) |
|
| 132 |
+ if err != nil || img == nil {
|
|
| 133 |
+ return fmt.Errorf("No such image %s", n)
|
|
| 134 |
+ } |
|
| 135 |
+ imageInspectRaw, err := s.graph.RawJSON(img.ID) |
|
| 132 | 136 |
if err != nil {
|
| 133 | 137 |
return err |
| 134 | 138 |
} |
| ... | ... |
@@ -149,11 +158,13 @@ func (s *TagStore) exportImage(name, tempdir string) error {
|
| 149 | 149 |
return err |
| 150 | 150 |
} |
| 151 | 151 |
|
| 152 |
- // find parent |
|
| 153 |
- img, err := s.LookupImage(n) |
|
| 154 |
- if err != nil {
|
|
| 155 |
- return err |
|
| 152 |
+ for _, fname := range []string{"", "VERSION", "json", "layer.tar"} {
|
|
| 153 |
+ if err := os.Chtimes(filepath.Join(tmpImageDir, fname), img.Created, img.Created); err != nil {
|
|
| 154 |
+ return err |
|
| 155 |
+ } |
|
| 156 | 156 |
} |
| 157 |
+ |
|
| 158 |
+ // try again with parent |
|
| 157 | 159 |
n = img.Parent |
| 158 | 160 |
} |
| 159 | 161 |
return nil |
| ... | ... |
@@ -11,22 +11,6 @@ import ( |
| 11 | 11 |
"github.com/docker/docker/utils" |
| 12 | 12 |
) |
| 13 | 13 |
|
| 14 |
-// lookupRaw looks up an image by name in a TagStore and returns the raw JSON |
|
| 15 |
-// describing the image. |
|
| 16 |
-func (s *TagStore) lookupRaw(name string) ([]byte, error) {
|
|
| 17 |
- image, err := s.LookupImage(name) |
|
| 18 |
- if err != nil || image == nil {
|
|
| 19 |
- return nil, fmt.Errorf("No such image %s", name)
|
|
| 20 |
- } |
|
| 21 |
- |
|
| 22 |
- imageInspectRaw, err := s.graph.RawJSON(image.ID) |
|
| 23 |
- if err != nil {
|
|
| 24 |
- return nil, err |
|
| 25 |
- } |
|
| 26 |
- |
|
| 27 |
- return imageInspectRaw, nil |
|
| 28 |
-} |
|
| 29 |
- |
|
| 30 | 14 |
// Lookup looks up an image by name in a TagStore and returns it as an |
| 31 | 15 |
// ImageInspect structure. |
| 32 | 16 |
func (s *TagStore) Lookup(name string) (*types.ImageInspect, error) {
|
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "encoding/json" |
|
| 4 | 5 |
"fmt" |
| 5 | 6 |
"io/ioutil" |
| 6 | 7 |
"os" |
| ... | ... |
@@ -9,6 +10,7 @@ import ( |
| 9 | 9 |
"reflect" |
| 10 | 10 |
"sort" |
| 11 | 11 |
"strings" |
| 12 |
+ "time" |
|
| 12 | 13 |
|
| 13 | 14 |
"github.com/go-check/check" |
| 14 | 15 |
) |
| ... | ... |
@@ -97,6 +99,24 @@ func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
|
| 97 | 97 |
} |
| 98 | 98 |
} |
| 99 | 99 |
|
| 100 |
+func (s *DockerSuite) TestSaveCheckTimes(c *check.C) {
|
|
| 101 |
+ repoName := "busybox:latest" |
|
| 102 |
+ out, _ := dockerCmd(c, "inspect", repoName) |
|
| 103 |
+ data := []struct {
|
|
| 104 |
+ ID string |
|
| 105 |
+ Created time.Time |
|
| 106 |
+ }{}
|
|
| 107 |
+ err := json.Unmarshal([]byte(out), &data) |
|
| 108 |
+ c.Assert(err, check.IsNil, check.Commentf("failed to marshal from %q: err %v", repoName, err))
|
|
| 109 |
+ c.Assert(len(data), check.Not(check.Equals), 0, check.Commentf("failed to marshal the data from %q", repoName))
|
|
| 110 |
+ tarTvTimeFormat := "2006-01-02 15:04" |
|
| 111 |
+ out, _, err = runCommandPipelineWithOutput( |
|
| 112 |
+ exec.Command(dockerBinary, "save", repoName), |
|
| 113 |
+ exec.Command("tar", "tv"),
|
|
| 114 |
+ exec.Command("grep", "-E", fmt.Sprintf("%s %s", data[0].Created.Format(tarTvTimeFormat), data[0].ID)))
|
|
| 115 |
+ c.Assert(err, check.IsNil, check.Commentf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err))
|
|
| 116 |
+} |
|
| 117 |
+ |
|
| 100 | 118 |
func (s *DockerSuite) TestSaveImageId(c *check.C) {
|
| 101 | 119 |
testRequires(c, DaemonIsLinux) |
| 102 | 120 |
repoName := "foobar-save-image-id-test" |