@@ -2,11 +2,15 @@ package cmd
2
2
3
3
import (
4
4
"archive/tar"
5
+ "encoding/json"
5
6
"errors"
6
7
"fmt"
8
+ "io/ioutil"
7
9
"os"
8
10
9
11
"github.com/andres-erbsen/clock"
12
+ "github.com/google/go-cmp/cmp"
13
+ "github.com/google/go-cmp/cmp/cmpopts"
10
14
"github.com/spf13/cobra"
11
15
"github.com/uber/makisu/lib/docker/image"
12
16
"github.com/uber/makisu/lib/log"
@@ -49,7 +53,6 @@ func getDiffCmd() *diffCmd {
49
53
}
50
54
51
55
func (cmd * diffCmd ) Diff (imagesFullName []string ) error {
52
- log .Infof ("ingore time? :%t" , cmd .ignoreModTime )
53
56
var pullImages []image.Name
54
57
for _ , imageFullName := range imagesFullName {
55
58
pullImage , err := image .ParseNameForPull (imageFullName )
@@ -69,6 +72,7 @@ func (cmd *diffCmd) Diff(imagesFullName []string) error {
69
72
}
70
73
71
74
var memFSArr []* snapshot.MemFS
75
+ var imageConfigs []* image.Config
72
76
for i , pullImage := range pullImages {
73
77
client := registry .New (store , pullImage .GetRegistry (), pullImage .GetRepository ())
74
78
manifest , err := client .Pull (pullImage .GetTag ())
@@ -94,11 +98,31 @@ func (cmd *diffCmd) Diff(imagesFullName []string) error {
94
98
panic (fmt .Errorf ("untar image %d layer reader: %s" , i + 1 , err ))
95
99
}
96
100
}
101
+
97
102
memFSArr = append (memFSArr , memfs )
103
+ reader , err := store .Layers .GetStoreFileReader (manifest .GetConfigDigest ().Hex ())
104
+ if err != nil {
105
+ panic (fmt .Errorf ("get image%d config file reader %s: %s" , i + 1 , manifest .GetConfigDigest ().Hex (), err ))
106
+ }
107
+
108
+ configBytes , err := ioutil .ReadAll (reader )
109
+ if err != nil {
110
+ panic (fmt .Errorf ("read image%d config file %s: %s" , i + 1 , manifest .GetConfigDigest ().Hex (), err ))
111
+ }
112
+
113
+ config := new (image.Config )
114
+ if err := json .Unmarshal (configBytes , config ); err != nil {
115
+ panic (fmt .Errorf ("unmarshal image%d config file %s: %s" , i + 1 , manifest .GetConfigDigest ().Hex (), err ))
116
+ }
117
+ imageConfigs = append (imageConfigs , config )
118
+ }
119
+
120
+ log .Infof ("* Diff image configs " )
121
+ if configDiff := cmp .Diff (imageConfigs [0 ], imageConfigs [1 ], cmpopts .IgnoreUnexported (image.Config {})); configDiff != "" {
122
+ log .Infof ("-image %s +image %s):\n %s" , pullImages [0 ].GetRepository ()+ ":" + pullImages [0 ].GetTag (), pullImages [1 ].GetRepository ()+ ":" + pullImages [1 ].GetTag (), configDiff )
98
123
}
99
124
100
- log .Infof ("* Diff two images" )
101
- // TODO: compare the image config.
125
+ log .Infof ("* Diff image layers" )
102
126
snapshot .CompareFS (memFSArr [0 ], memFSArr [1 ], pullImages [0 ], pullImages [1 ], cmd .ignoreModTime )
103
127
return nil
104
128
}
0 commit comments