Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 26503ac

Browse files
committed
Always use the docker client
1 parent 8c7d517 commit 26503ac

File tree

5 files changed

+75
-248
lines changed

5 files changed

+75
-248
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ To get a JSON version of the container-diff output add a `-j` or `--json` flag.
8585

8686
```container-diff <img1> <img2> -j```
8787

88-
To use the docker client instead of shelling out to your local docker daemon, add a `-e` or `--eng` flag.
89-
9088
```container-diff <img1> <img2> -e```
9189

9290
To order files and packages by size (in descending order) when performing file system or package analyses/diffs, add a `-o` or `--order` flag.

cmd/root.go

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"bytes"
5+
"context"
56
"errors"
67
goflag "flag"
78
"fmt"
@@ -12,13 +13,13 @@ import (
1213

1314
"github.com/GoogleCloudPlatform/container-diff/differs"
1415
"github.com/GoogleCloudPlatform/container-diff/utils"
16+
"github.com/docker/docker/client"
1517
"github.com/golang/glog"
1618
"github.com/spf13/cobra"
1719
"github.com/spf13/pflag"
1820
)
1921

2022
var json bool
21-
var eng bool
2223
var save bool
2324

2425
var apt bool
@@ -45,8 +46,6 @@ var RootCmd = &cobra.Command{
4546
os.Exit(1)
4647
}
4748

48-
utils.SetDockerEngine(eng)
49-
5049
analyzeArgs := []string{}
5150
allAnalyzers := getAllAnalyzers()
5251
for _, name := range allAnalyzers {
@@ -76,25 +75,48 @@ var RootCmd = &cobra.Command{
7675
},
7776
}
7877

78+
func NewClient() (*client.Client, error) {
79+
cli, err := client.NewEnvClient()
80+
if err != nil {
81+
return nil, fmt.Errorf("Error getting docker client: %s", err)
82+
}
83+
cli.NegotiateAPIVersion(context.Background())
84+
85+
return cli, nil
86+
}
87+
7988
func diffImages(image1Arg, image2Arg string, diffArgs []string) error {
89+
cli, err := NewClient()
90+
if err != nil {
91+
return fmt.Errorf("Error getting docker client for differ: %s", err)
92+
}
93+
defer cli.Close()
94+
8095
var wg sync.WaitGroup
8196
wg.Add(2)
8297

8398
glog.Infof("Starting diff on images %s and %s, using differs: %s", image1Arg, image2Arg, diffArgs)
8499

85100
var image1, image2 utils.Image
86-
var err error
87101
go func() {
88102
defer wg.Done()
89-
image1, err = utils.ImagePrepper{image1Arg}.GetImage()
103+
ip := utils.ImagePrepper{
104+
Source: image1Arg,
105+
Client: cli,
106+
}
107+
image1, err = ip.GetImage()
90108
if err != nil {
91109
glog.Error(err.Error())
92110
}
93111
}()
94112

95113
go func() {
96114
defer wg.Done()
97-
image2, err = utils.ImagePrepper{image2Arg}.GetImage()
115+
ip := utils.ImagePrepper{
116+
Source: image2Arg,
117+
Client: cli,
118+
}
119+
image2, err = ip.GetImage()
98120
if err != nil {
99121
glog.Error(err.Error())
100122
}
@@ -137,7 +159,18 @@ func diffImages(image1Arg, image2Arg string, diffArgs []string) error {
137159
}
138160

139161
func analyzeImage(imageArg string, analyzerArgs []string) error {
140-
image, err := utils.ImagePrepper{imageArg}.GetImage()
162+
cli, err := NewClient()
163+
if err != nil {
164+
return fmt.Errorf("Error getting docker client for analyzer: %s", err)
165+
}
166+
defer cli.Close()
167+
168+
ip := utils.ImagePrepper{
169+
Source: imageArg,
170+
Client: cli,
171+
}
172+
173+
image, err := ip.GetImage()
141174
if err != nil {
142175
glog.Error(err.Error())
143176
cleanupImage(image)
@@ -288,7 +321,6 @@ func remove(path string, dir bool) string {
288321
func init() {
289322
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
290323
RootCmd.Flags().BoolVarP(&json, "json", "j", false, "JSON Output defines if the diff should be returned in a human readable format (false) or a JSON (true).")
291-
RootCmd.Flags().BoolVarP(&eng, "eng", "e", false, "By default the docker calls are shelled out locally, set this flag to use the Docker Engine Client (version compatibility required).")
292324
RootCmd.Flags().BoolVarP(&pip, "pip", "p", false, "Set this flag to use the pip differ.")
293325
RootCmd.Flags().BoolVarP(&node, "node", "n", false, "Set this flag to use the node differ.")
294326
RootCmd.Flags().BoolVarP(&apt, "apt", "a", false, "Set this flag to use the apt differ.")

differs/historyDiff.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import (
99
type HistoryAnalyzer struct {
1010
}
1111

12+
type HistDiff struct {
13+
Adds []string
14+
Dels []string
15+
}
16+
1217
func (a HistoryAnalyzer) Diff(image1, image2 utils.Image) (utils.Result, error) {
1318
diff, err := getHistoryDiff(image1, image2)
1419
return &utils.HistDiffResult{
@@ -29,13 +34,13 @@ func (a HistoryAnalyzer) Analyze(image utils.Image) (utils.Result, error) {
2934
return &result, nil
3035
}
3136

32-
func getHistoryDiff(image1, image2 utils.Image) (utils.HistDiff, error) {
37+
func getHistoryDiff(image1, image2 utils.Image) (HistDiff, error) {
3338
history1 := getHistoryList(image1.Config.History)
3439
history2 := getHistoryList(image2.Config.History)
3540

3641
adds := utils.GetAdditions(history1, history2)
3742
dels := utils.GetDeletions(history1, history2)
38-
diff := utils.HistDiff{adds, dels}
43+
diff := HistDiff{adds, dels}
3944
return diff, nil
4045
}
4146

0 commit comments

Comments
 (0)