-
Notifications
You must be signed in to change notification settings - Fork 237
Remove Docker dependency for retrieving image filesystem #97
Changes from 5 commits
fb56153
a005f0c
369759d
d4db8be
f9d7987
0293e9a
8702bb7
6a1e169
6de5efb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,10 +35,10 @@ var diffCmd = &cobra.Command{ | |
Long: `Compares two images using the specifed analyzers as indicated via flags (see documentation for available ones).`, | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if err := validateArgs(args, checkDiffArgNum); err != nil { | ||
return errors.New(err.Error()) | ||
return err | ||
} | ||
if err := checkIfValidAnalyzer(types); err != nil { | ||
return errors.New(err.Error()) | ||
return err | ||
} | ||
return nil | ||
}, | ||
|
@@ -52,21 +52,20 @@ var diffCmd = &cobra.Command{ | |
|
||
func checkDiffArgNum(args []string) error { | ||
if len(args) != 2 { | ||
return errors.New("'diff' requires two images as arguments: container diff [image1] [image2]") | ||
return errors.New("'diff' requires two images as arguments: container-diff diff [image1] [image2]") | ||
} | ||
return nil | ||
} | ||
|
||
func diffImages(image1Arg, image2Arg string, diffArgs []string) error { | ||
diffTypes, err := differs.GetAnalyzers(diffArgs) | ||
if err != nil { | ||
glog.Error(err.Error()) | ||
return errors.New("Could not perform image diff") | ||
return fmt.Errorf("err msg: %s", err.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just return err or make this more informative? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed up the errors in this file |
||
} | ||
|
||
cli, err := NewClient() | ||
if err != nil { | ||
return fmt.Errorf("Error getting docker client for differ: %s", err) | ||
return fmt.Errorf("err msg: %s", err) | ||
} | ||
defer cli.Close() | ||
var wg sync.WaitGroup | ||
|
@@ -81,8 +80,10 @@ func diffImages(image1Arg, image2Arg string, diffArgs []string) error { | |
for imageArg := range imageMap { | ||
go func(imageName string, imageMap map[string]*pkgutil.Image) { | ||
defer wg.Done() | ||
|
||
prefixedName := processImageName(imageName) | ||
ip := pkgutil.ImagePrepper{ | ||
Source: imageName, | ||
Source: prefixedName, | ||
Client: cli, | ||
} | ||
image, err := ip.GetImage() | ||
|
@@ -102,8 +103,7 @@ func diffImages(image1Arg, image2Arg string, diffArgs []string) error { | |
req := differs.DiffRequest{*imageMap[image1Arg], *imageMap[image2Arg], diffTypes} | ||
diffs, err := req.GetDiff() | ||
if err != nil { | ||
glog.Error(err.Error()) | ||
return errors.New("Could not perform image diff") | ||
return fmt.Errorf("err msg: %s", err.Error()) | ||
} | ||
glog.Info("Retrieving diffs") | ||
outputResults(diffs) | ||
|
@@ -116,6 +116,14 @@ func diffImages(image1Arg, image2Arg string, diffArgs []string) error { | |
return nil | ||
} | ||
|
||
func processImageName(imageName string) string { | ||
if pkgutil.IsTar(imageName) || strings.HasPrefix(imageName, "daemon://") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if it already has remote://? would this add it a second time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't really planning on advertising that prefix to users, but I guess there's nothing stopping them from adding it in which case this would break. fixed |
||
return imageName | ||
} | ||
// not a tar and not explicitly local, so force remote | ||
return "remote://" + imageName | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(diffCmd) | ||
addSharedFlags(diffCmd) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ package util | |
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/docker/docker/client" | ||
"github.com/golang/glog" | ||
|
@@ -36,12 +38,42 @@ type Prepper interface { | |
SupportsImage() bool | ||
} | ||
|
||
func (p ImagePrepper) GetImage() (Image, error) { | ||
func getImage(prepper Prepper) (Image, error) { | ||
imgPath, err := prepper.GetFileSystem() | ||
if err != nil { | ||
return Image{}, fmt.Errorf("error msg: %s", err.Error()) | ||
} | ||
|
||
config, err := prepper.GetConfig() | ||
if err != nil { | ||
return Image{}, fmt.Errorf("error msg: %s", err.Error()) | ||
} | ||
|
||
glog.Infof("Finished prepping image %s", prepper.GetSource()) | ||
return Image{ | ||
Source: prepper.GetSource(), | ||
FSPath: imgPath, | ||
Config: config, | ||
}, nil | ||
} | ||
|
||
func (p *ImagePrepper) GetImage() (Image, error) { | ||
glog.Infof("Starting prep for image %s", p.Source) | ||
img := p.Source | ||
|
||
var prepper Prepper | ||
|
||
// first, respect prefixes on image names | ||
if strings.HasPrefix(p.Source, "daemon://") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like this should be redundant with the loop below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was stripping off the prefix of the image source before creating the prepper, but since the rest of the logic was essentially redundant I moved this into the |
||
p.Source = strings.Replace(p.Source, "daemon://", "", -1) | ||
prepper = DaemonPrepper{ImagePrepper: p} | ||
return getImage(prepper) | ||
} else if strings.HasPrefix(p.Source, "remote://") { | ||
p.Source = strings.Replace(p.Source, "remote://", "", -1) | ||
prepper = CloudPrepper{ImagePrepper: p} | ||
return getImage(prepper) | ||
} | ||
|
||
for _, prepperConstructor := range orderedPreppers { | ||
prepper = prepperConstructor(p) | ||
if prepper.SupportsImage() { | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably document the available image name flags somewhere, does it make sense here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I should put it here. should also go in the README somewhere