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

Commit da5f8b0

Browse files
committed
Always use the docker client
1 parent 828be57 commit da5f8b0

File tree

7 files changed

+75
-251
lines changed

7 files changed

+75
-251
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/analyze.go

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

33
import (
44
"errors"
5+
"fmt"
56
"os"
67

78
"github.com/GoogleCloudPlatform/container-diff/differs"
@@ -19,9 +20,6 @@ var analyzeCmd = &cobra.Command{
1920
glog.Error(err.Error())
2021
os.Exit(1)
2122
}
22-
23-
utils.SetDockerEngine(eng)
24-
2523
analyzeArgs := []string{}
2624
allAnalyzers := getAllAnalyzers()
2725
for _, name := range allAnalyzers {
@@ -52,7 +50,17 @@ func checkAnalyzeArgNum(args []string) (bool, error) {
5250
}
5351

5452
func analyzeImage(imageArg string, analyzerArgs []string) error {
55-
image, err := utils.ImagePrepper{imageArg}.GetImage()
53+
cli, err := NewClient()
54+
if err != nil {
55+
return fmt.Errorf("Error getting docker client for differ: %s", err)
56+
}
57+
defer cli.Close()
58+
ip := utils.ImagePrepper{
59+
Source: imageArg,
60+
Client: cli,
61+
}
62+
63+
image, err := ip.GetImage()
5664
if err != nil {
5765
glog.Error(err.Error())
5866
cleanupImage(image)

cmd/diff.go

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

33
import (
44
"errors"
5+
"fmt"
56
"os"
67
"sync"
78

@@ -20,9 +21,6 @@ var diffCmd = &cobra.Command{
2021
glog.Error(err.Error())
2122
os.Exit(1)
2223
}
23-
24-
utils.SetDockerEngine(eng)
25-
2624
analyzeArgs := []string{}
2725
allAnalyzers := getAllAnalyzers()
2826
for _, name := range allAnalyzers {
@@ -53,24 +51,36 @@ func checkDiffArgNum(args []string) (bool, error) {
5351
}
5452

5553
func diffImages(image1Arg, image2Arg string, diffArgs []string) error {
54+
cli, err := NewClient()
55+
if err != nil {
56+
return fmt.Errorf("Error getting docker client for differ: %s", err)
57+
}
58+
defer cli.Close()
5659
var wg sync.WaitGroup
5760
wg.Add(2)
5861

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

6164
var image1, image2 utils.Image
62-
var err error
6365
go func() {
6466
defer wg.Done()
65-
image1, err = utils.ImagePrepper{image1Arg}.GetImage()
67+
ip := utils.ImagePrepper{
68+
Source: image1Arg,
69+
Client: cli,
70+
}
71+
image1, err = ip.GetImage()
6672
if err != nil {
6773
glog.Error(err.Error())
6874
}
6975
}()
7076

7177
go func() {
7278
defer wg.Done()
73-
image2, err = utils.ImagePrepper{image2Arg}.GetImage()
79+
ip := utils.ImagePrepper{
80+
Source: image2Arg,
81+
Client: cli,
82+
}
83+
image2, err = ip.GetImage()
7484
if err != nil {
7585
glog.Error(err.Error())
7686
}

cmd/root.go

Lines changed: 12 additions & 1 deletion
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"
@@ -10,6 +11,7 @@ import (
1011
"sort"
1112

1213
"github.com/GoogleCloudPlatform/container-diff/utils"
14+
"github.com/docker/docker/client"
1315
"github.com/golang/glog"
1416
"github.com/spf13/cobra"
1517
"github.com/spf13/pflag"
@@ -40,6 +42,16 @@ var RootCmd = &cobra.Command{
4042
Long: `Analyzes a single image or compares two images using the specifed analyzers/differs as indicated via flags (see documentation for available ones).`,
4143
}
4244

45+
func NewClient() (*client.Client, error) {
46+
cli, err := client.NewEnvClient()
47+
if err != nil {
48+
return nil, fmt.Errorf("Error getting docker client: %s", err)
49+
}
50+
cli.NegotiateAPIVersion(context.Background())
51+
52+
return cli, nil
53+
}
54+
4355
func outputResults(resultMap map[string]utils.Result) {
4456
// Outputs diff/analysis results in alphabetical order by analyzer name
4557
sortedTypes := []string{}
@@ -145,7 +157,6 @@ func init() {
145157

146158
func addSharedFlags(cmd *cobra.Command) {
147159
cmd.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).")
148-
cmd.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).")
149160
cmd.Flags().BoolVarP(&pip, "pip", "p", false, "Set this flag to use the pip differ.")
150161
cmd.Flags().BoolVarP(&node, "node", "n", false, "Set this flag to use the node differ.")
151162
cmd.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)