From c7dff7dca927ac370fcdbf49279d607bf8076071 Mon Sep 17 00:00:00 2001 From: tejal29 Date: Wed, 21 Oct 2020 15:38:58 -0700 Subject: [PATCH] wip --- pkg/skaffold/docker/dependencies.go | 24 +++++++++++++++++++++++- pkg/skaffold/docker/parse.go | 8 +++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pkg/skaffold/docker/dependencies.go b/pkg/skaffold/docker/dependencies.go index d9ff2009469..796d39740a2 100644 --- a/pkg/skaffold/docker/dependencies.go +++ b/pkg/skaffold/docker/dependencies.go @@ -28,6 +28,18 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/walk" ) + +// dockerDependencies describes +type dockerfileDependencies struct { + files []string + err error +} + +// dependencyCache is a cache for dependencies for each dockerfile. +var ( + dependencyCache = map[string]dockerfileDependencies{} +) + // NormalizeDockerfilePath returns the absolute path to the dockerfile. func NormalizeDockerfilePath(context, dockerfile string) (string, error) { // Expected case: should be found relative to the context directory. @@ -50,6 +62,17 @@ func GetDependencies(ctx context.Context, workspace string, dockerfilePath strin return nil, fmt.Errorf("normalizing dockerfile path: %w", err) } + if _, ok := dependencyCache[absDockerfilePath]; !ok { + paths, err := getDependencies(workspace, dockerfilePath, absDockerfilePath, buildArgs, cfg) + dependencyCache[absDockerfilePath] = dockerfileDependencies{ + files: paths, + err: err, + } + } + return dependencyCache[absDockerfilePath].files, dependencyCache[absDockerfilePath].err +} + +func getDependencies(workspace string, dockerfilePath string, absDockerfilePath string, buildArgs map[string]*string, cfg Config) ([]string, error){ // If the Dockerfile doesn't exist, we can't compute the dependencies. // But since we know the Dockerfile is a dependency, let's return a list // with only that file. It makes errors down the line more actionable @@ -93,7 +116,6 @@ func GetDependencies(ctx context.Context, workspace string, dockerfilePath strin dependencies = append(dependencies, file) } sort.Strings(dependencies) - return dependencies, nil } diff --git a/pkg/skaffold/docker/parse.go b/pkg/skaffold/docker/parse.go index d70f63a924b..c99ee3dcd7f 100644 --- a/pkg/skaffold/docker/parse.go +++ b/pkg/skaffold/docker/parse.go @@ -62,9 +62,10 @@ type fromTo struct { var ( // RetrieveImage is overridden for unit testing RetrieveImage = retrieveImage - onBuildRetrieveErr = errors.New("error retrieving ONBUILD image") + unsupportedMediaTypeError = errors.New("unsupported MediaType error") ) + func readCopyCmdsFromDockerfile(onlyLastImage bool, absDockerfilePath, workspace string, buildArgs map[string]*string, cfg Config) ([]fromTo, error) { f, err := os.Open(absDockerfilePath) if err != nil { @@ -218,6 +219,7 @@ func extractCopyCommands(nodes []*parser.Node, onlyLastImage bool, cfg Config) ( if !stages[strings.ToLower(from.image)] { img, err := RetrieveImage(from.image, cfg) if err != nil { + if return nil, err } @@ -320,7 +322,7 @@ func expandOnbuildInstructions(nodes []*parser.Node, cfg Config) ([]*parser.Node } else if ons, err := parseOnbuild(from.image, cfg); err == nil { onbuildNodes = ons } else { - if errors.Is(err, onBuildRetrieveErr) { + if errors.Is(err, notSupportedManifestError) { // TODO: [4895] collect warning codes for warnings seen during a dev iteration. logrus.Warnf("could not retrieve ONBUILD image %s. Will ignore files dependencies for all ONBUILD triggers", from.image) return []*parser.Node{}, nil @@ -346,7 +348,7 @@ func parseOnbuild(image string, cfg Config) ([]*parser.Node, error) { // Image names are case SENSITIVE img, err := RetrieveImage(image, cfg) if err != nil { - return nil, onBuildRetrieveErr + return nil, } if len(img.Config.OnBuild) == 0 {