Skip to content
This repository was archived by the owner on May 4, 2021. It is now read-only.

Commit 2c3c165

Browse files
author
jockeych
authored
diff image config (#329)
* diff image config * fix comments and use opensource package to show the fuzzy diff in image config * clean up log * fix comments & use ` --log-fmt=console` to better print the info
1 parent 41f1b5b commit 2c3c165

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

bin/makisu/cmd/diff.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ package cmd
22

33
import (
44
"archive/tar"
5+
"encoding/json"
56
"errors"
67
"fmt"
8+
"io/ioutil"
79
"os"
810

911
"github.com/andres-erbsen/clock"
12+
"github.com/google/go-cmp/cmp"
13+
"github.com/google/go-cmp/cmp/cmpopts"
1014
"github.com/spf13/cobra"
1115
"github.com/uber/makisu/lib/docker/image"
1216
"github.com/uber/makisu/lib/log"
@@ -49,7 +53,6 @@ func getDiffCmd() *diffCmd {
4953
}
5054

5155
func (cmd *diffCmd) Diff(imagesFullName []string) error {
52-
log.Infof("ingore time? :%t", cmd.ignoreModTime)
5356
var pullImages []image.Name
5457
for _, imageFullName := range imagesFullName {
5558
pullImage, err := image.ParseNameForPull(imageFullName)
@@ -69,6 +72,7 @@ func (cmd *diffCmd) Diff(imagesFullName []string) error {
6972
}
7073

7174
var memFSArr []*snapshot.MemFS
75+
var imageConfigs []*image.Config
7276
for i, pullImage := range pullImages {
7377
client := registry.New(store, pullImage.GetRegistry(), pullImage.GetRepository())
7478
manifest, err := client.Pull(pullImage.GetTag())
@@ -94,11 +98,31 @@ func (cmd *diffCmd) Diff(imagesFullName []string) error {
9498
panic(fmt.Errorf("untar image %d layer reader: %s", i+1, err))
9599
}
96100
}
101+
97102
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)
98123
}
99124

100-
log.Infof("* Diff two images")
101-
// TODO: compare the image config.
125+
log.Infof("* Diff image layers")
102126
snapshot.CompareFS(memFSArr[0], memFSArr[1], pullImages[0], pullImages[1], cmd.ignoreModTime)
103127
return nil
104128
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222
github.com/go-redis/redis v6.14.2+incompatible
2323
github.com/golang/mock v1.2.0
2424
github.com/gomodule/redigo v2.0.0+incompatible // indirect
25+
github.com/google/go-cmp v0.4.0
2526
github.com/gorilla/context v1.1.1 // indirect
2627
github.com/gorilla/mux v1.6.2 // indirect
2728
github.com/inconshreveable/mousetrap v1.0.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM
5353
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
5454
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
5555
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
56+
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
57+
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5658
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
5759
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
5860
github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk=
@@ -158,6 +160,8 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
158160
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
159161
golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5 h1:ZcPpqKMdoZeNQ/4GHlyY4COf8n8SmpPv6mcqF1+VPSM=
160162
golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
163+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
164+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
161165
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
162166
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
163167
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

0 commit comments

Comments
 (0)