Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 committed Oct 21, 2020
1 parent 9e963ba commit c7dff7d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
24 changes: 23 additions & 1 deletion pkg/skaffold/docker/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -93,7 +116,6 @@ func GetDependencies(ctx context.Context, workspace string, dockerfilePath strin
dependencies = append(dependencies, file)
}
sort.Strings(dependencies)

return dependencies, nil
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/skaffold/docker/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit c7dff7d

Please sign in to comment.