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

Remove docker dependency for local images #100

Merged
merged 4 commits into from
Sep 21, 2017
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
4 changes: 4 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ go_library(
"//util:go_default_library",
"//vendor/github.com/docker/docker/client:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//version:go_default_library",
Expand Down
18 changes: 7 additions & 11 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package cmd

import (
"errors"
"fmt"
"os"
"strings"
Expand All @@ -34,10 +33,10 @@ var analyzeCmd = &cobra.Command{
Long: `Analyzes an image 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, checkAnalyzeArgNum); err != nil {
return errors.New(err.Error())
return err
}
if err := checkIfValidAnalyzer(types); err != nil {
return errors.New(err.Error())
return err
}
return nil
},
Expand All @@ -51,21 +50,20 @@ var analyzeCmd = &cobra.Command{

func checkAnalyzeArgNum(args []string) error {
if len(args) != 1 {
return errors.New("'analyze' requires one image as an argument: container analyze [image]")
return fmt.Errorf("'analyze' requires one image as an argument: container-diff analyze [image]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.New is fine here, it's basically the same as fmt.Errorf except fmt does formatting. You're not adding any arguments so we should stick to errors.New

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
return nil
}

func analyzeImage(imageArg string, analyzerArgs []string) error {
analyzeTypes, err := differs.GetAnalyzers(analyzerArgs)
if err != nil {
glog.Error(err.Error())
return errors.New("Could not perform image analysis")
return err
}

cli, err := NewClient()
if err != nil {
return fmt.Errorf("Error getting docker client for differ: %s", err)
return fmt.Errorf("Error getting docker client: %s", err)
}
defer cli.Close()
ip := pkgutil.ImagePrepper{
Expand All @@ -78,15 +76,13 @@ func analyzeImage(imageArg string, analyzerArgs []string) error {
defer pkgutil.CleanupImage(image)
}
if err != nil {
glog.Error(err.Error())
return errors.New("Could not perform image analysis")
return fmt.Errorf("Error processing image: %s", err)
}

req := differs.SingleRequest{image, analyzeTypes}
analyses, err := req.GetAnalysis()
if err != nil {
glog.Error(err.Error())
return errors.New("Could not perform image analysis")
return fmt.Errorf("Error performing image analysis: %s", err)
}

glog.Info("Retrieving analyses")
Expand Down
15 changes: 6 additions & 9 deletions cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package cmd

import (
"errors"
"fmt"
"os"
"strings"
Expand All @@ -35,10 +34,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
},
Expand All @@ -52,21 +51,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 fmt.Errorf("'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 err
}

cli, err := NewClient()
if err != nil {
return fmt.Errorf("Error getting docker client for differ: %s", err)
return err
}
defer cli.Close()
var wg sync.WaitGroup
Expand Down Expand Up @@ -102,8 +100,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("Could not retrieve diff: %s", err)
}
glog.Info("Retrieving diffs")
outputResults(diffs)
Expand Down
5 changes: 1 addition & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/GoogleCloudPlatform/container-diff/util"
"github.com/docker/docker/client"
"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -98,9 +97,7 @@ func checkIfValidAnalyzer(flagtypes string) error {
analyzers := strings.Split(flagtypes, ",")
for _, name := range analyzers {
if _, exists := differs.Analyzers[name]; !exists {
errMessage := fmt.Sprintf("Argument %s is not a valid analyzer\n", name)
glog.Errorf(errMessage)
return errors.New(errMessage)
return fmt.Errorf("Argument %s is not a valid analyzer", name)
}
}
return nil
Expand Down
10 changes: 5 additions & 5 deletions differs/differs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package differs

import (
"errors"
"fmt"

pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
Expand Down Expand Up @@ -98,16 +97,17 @@ func (req SingleRequest) GetAnalysis() (map[string]util.Result, error) {
return results, err
}

func GetAnalyzers(analyzeNames []string) (analyzeFuncs []Analyzer, err error) {
func GetAnalyzers(analyzeNames []string) ([]Analyzer, error) {
var analyzeFuncs []Analyzer
for _, name := range analyzeNames {
if a, exists := Analyzers[name]; exists {
analyzeFuncs = append(analyzeFuncs, a)
} else {
glog.Errorf("Unknown analyzer/differ specified", name)
return nil, fmt.Errorf("Unknown analyzer/differ specified: %s", name)
}
}
if len(analyzeFuncs) == 0 {
err = errors.New("No known analyzers/differs specified")
return nil, fmt.Errorf("No known analyzers/differs specified")
}
return
return analyzeFuncs, nil
}
1 change: 1 addition & 0 deletions pkg/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/containers/image/docker:go_default_library",
"//vendor/github.com/containers/image/docker/daemon:go_default_library",
"//vendor/github.com/containers/image/docker/tarfile:go_default_library",
"//vendor/github.com/containers/image/pkg/compression:go_default_library",
"//vendor/github.com/containers/image/types:go_default_library",
Expand Down
20 changes: 5 additions & 15 deletions pkg/util/daemon_prepper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package util

import (
"context"
"os"
"regexp"

"github.com/containers/image/docker/daemon"
"github.com/golang/glog"
)

Expand All @@ -45,29 +45,19 @@ func (p DaemonPrepper) SupportsImage() bool {
}

func (p DaemonPrepper) GetFileSystem() (string, error) {
tarPath, err := saveImageToTar(p.Client, p.Source, p.Source)
ref, err := daemon.ParseReference(p.Source)
if err != nil {
return "", err
}

defer os.Remove(tarPath)
return getImageFromTar(tarPath)
return getFileSystemFromReference(ref, p.Source)
}

func (p DaemonPrepper) GetConfig() (ConfigSchema, error) {
inspect, _, err := p.Client.ImageInspectWithRaw(context.Background(), p.Source)
ref, err := daemon.ParseReference(p.Source)
if err != nil {
return ConfigSchema{}, err
}

config := ConfigObject{
Env: inspect.Config.Env,
}
history := p.GetHistory()
return ConfigSchema{
Config: config,
History: history,
}, nil
return getConfigFromReference(ref, p.Source)
}

func (p DaemonPrepper) GetHistory() []ImageHistoryItem {
Expand Down
4 changes: 3 additions & 1 deletion pkg/util/tar_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ func UnTar(filename string, target string) error {
}

func IsTar(path string) bool {
return filepath.Ext(path) == ".tar"
return filepath.Ext(path) == ".tar" ||
filepath.Ext(path) == ".tar.gz" ||
filepath.Ext(path) == ".tgz"
}

func CheckTar(image string) bool {
Expand Down
23 changes: 23 additions & 0 deletions vendor/github.com/containers/image/docker/daemon/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading