From 4d88a14a08c027b8788c0b203883eec9fc526efc Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 6 Jun 2019 16:33:42 -0700 Subject: [PATCH] Improve Dockerfile fetching error reporting and "bashbrew children" / "bashbrew from" handling (especially in the case of no "--apply-constraints" flag) --- bashbrew/go/src/bashbrew/cmd-deps.go | 19 +++++++++++++------ bashbrew/go/src/bashbrew/cmd-from.go | 23 ++++++++++++++++++++--- bashbrew/go/src/bashbrew/docker.go | 8 ++++---- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/bashbrew/go/src/bashbrew/cmd-deps.go b/bashbrew/go/src/bashbrew/cmd-deps.go index 928179f1ab72ae..91e477e6b2db63 100644 --- a/bashbrew/go/src/bashbrew/cmd-deps.go +++ b/bashbrew/go/src/bashbrew/cmd-deps.go @@ -67,13 +67,20 @@ func cmdFamily(parents bool, c *cli.Context) error { continue } - froms, err := r.DockerFroms(entry) - if err != nil { - return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q)`, r.RepoName, entry.TagsString()), err) + entryArches := []string{arch} + if !applyConstraints { + entryArches = entry.Architectures } - for _, from := range froms { - for _, tag := range r.Tags("", false, entry) { - network.AddEdge(from, tag) + + for _, entryArch := range entryArches { + froms, err := r.ArchDockerFroms(entryArch, entry) + if err != nil { + return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q, arch %q)`, r.RepoName, entry.TagsString(), entryArch), err) + } + for _, from := range froms { + for _, tag := range r.Tags("", false, entry) { + network.AddEdge(from, tag) + } } } } diff --git a/bashbrew/go/src/bashbrew/cmd-from.go b/bashbrew/go/src/bashbrew/cmd-from.go index a6d9c7b3985f0a..f8db7e2fc32017 100644 --- a/bashbrew/go/src/bashbrew/cmd-from.go +++ b/bashbrew/go/src/bashbrew/cmd-from.go @@ -28,9 +28,26 @@ func cmdFrom(c *cli.Context) error { continue } - froms, err := r.DockerFroms(entry) - if err != nil { - return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q)`, r.RepoName, entry.TagsString()), err) + entryArches := []string{arch} + if !applyConstraints { + entryArches = entry.Architectures + } + + froms := []string{} + for _, entryArch := range entryArches { + archFroms, err := r.ArchDockerFroms(entryArch, entry) + if err != nil { + return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q, arch %q)`, r.RepoName, entry.TagsString(), entryArch), err) + } + ArchFroms: + for _, archFrom := range archFroms { + for _, from := range froms { + if from == archFrom { + continue ArchFroms + } + } + froms = append(froms, archFrom) + } } fromsString := strings.Join(froms, " ") diff --git a/bashbrew/go/src/bashbrew/docker.go b/bashbrew/go/src/bashbrew/docker.go index 96fb41ecf14095..3283ce45352914 100644 --- a/bashbrew/go/src/bashbrew/docker.go +++ b/bashbrew/go/src/bashbrew/docker.go @@ -55,7 +55,7 @@ var dockerfileMetadataCache = map[string]*dockerfileMetadata{} func (r Repo) archDockerfileMetadata(arch string, entry *manifest.Manifest2822Entry) (*dockerfileMetadata, error) { commit, err := r.fetchGitRepo(arch, entry) if err != nil { - return nil, err + return nil, cli.NewMultiError(fmt.Errorf("failed fetching Git repo for arch %q from entry %q", arch, entry.String()), err) } dockerfileFile := path.Join(entry.ArchDirectory(arch), entry.ArchFile(arch)) @@ -70,17 +70,17 @@ func (r Repo) archDockerfileMetadata(arch string, entry *manifest.Manifest2822En dockerfile, err := gitShow(commit, dockerfileFile) if err != nil { - return nil, err + return nil, cli.NewMultiError(fmt.Errorf(`failed "git show" for %q from commit %q`, dockerfileFile, commit), err) } defer dockerfile.Close() meta, err := parseDockerfileMetadata(dockerfile) if err != nil { - return nil, err + return nil, cli.NewMultiError(fmt.Errorf(`failed parsing Dockerfile metadata for %q from commit %q`, dockerfileFile, commit), err) } if err := dockerfile.Close(); err != nil { - return nil, err + return nil, cli.NewMultiError(fmt.Errorf(`failed closing "git show" for %q from commit %q`, dockerfileFile, commit), err) } dockerfileMetadataCache[cacheKey] = meta