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

diff image config #329

Merged
merged 4 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions bin/makisu/cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ package cmd

import (
"archive/tar"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/andres-erbsen/clock"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/spf13/cobra"
"github.com/uber/makisu/lib/docker/image"
"github.com/uber/makisu/lib/log"
Expand Down Expand Up @@ -49,7 +54,6 @@ func getDiffCmd() *diffCmd {
}

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

var memFSArr []*snapshot.MemFS
var imageConfigs []*image.Config
for i, pullImage := range pullImages {
client := registry.New(store, pullImage.GetRegistry(), pullImage.GetRepository())
manifest, err := client.Pull(pullImage.GetTag())
Expand All @@ -94,11 +99,36 @@ func (cmd *diffCmd) Diff(imagesFullName []string) error {
panic(fmt.Errorf("untar image %d layer reader: %s", i+1, err))
}
}

memFSArr = append(memFSArr, memfs)
reader, err := store.Layers.GetStoreFileReader(manifest.GetConfigDigest().Hex())
if err != nil {
panic(fmt.Errorf("get image%d config file reader %s: %s", i+1, manifest.GetConfigDigest().Hex(), err))
}

configBytes, err := ioutil.ReadAll(reader)
if err != nil {
panic(fmt.Errorf("read image%d config file %s: %s", i+1, manifest.GetConfigDigest().Hex(), err))
}

config := new(image.Config)
if err := json.Unmarshal(configBytes, config); err != nil {
panic(fmt.Errorf("unmarshal image%d config file %s: %s", i+1, manifest.GetConfigDigest().Hex(), err))
}
imageConfigs = append(imageConfigs, config)
}

log.Infof("* compare image %s and image %s config", pullImages[0].GetRepository()+":"+pullImages[0].GetTag(), pullImages[1].GetRepository()+":"+pullImages[1].GetTag())
if configDiff := cmp.Diff(imageConfigs[0], imageConfigs[1], cmpopts.IgnoreUnexported(image.Config{})); configDiff != "" {
// Format the diff string.
configDiff = strings.ReplaceAll(configDiff, "\n", "")
configDiff = strings.ReplaceAll(configDiff, "\t", "")
configDiff = strings.ReplaceAll(configDiff, "\"", "")
configDiff = strings.ReplaceAll(configDiff, " ", "")
log.Infof("-image %s +image %s):\n%s", pullImages[0].GetRepository()+":"+pullImages[0].GetTag(), pullImages[1].GetRepository()+":"+pullImages[1].GetTag(), configDiff)
}

log.Infof("* Diff two images")
// TODO: compare the image config.
snapshot.CompareFS(memFSArr[0], memFSArr[1], pullImages[0], pullImages[1], cmd.ignoreModTime)
return nil
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/go-redis/redis v6.14.2+incompatible
github.com/golang/mock v1.2.0
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/google/go-cmp v0.4.0
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/mux v1.6.2 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk=
Expand Down Expand Up @@ -158,6 +160,8 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5 h1:ZcPpqKMdoZeNQ/4GHlyY4COf8n8SmpPv6mcqF1+VPSM=
golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down