Skip to content

Commit

Permalink
Improve Dockerfile fetching error reporting and "bashbrew children" /…
Browse files Browse the repository at this point in the history
… "bashbrew from" handling (especially in the case of no "--apply-constraints" flag)
  • Loading branch information
tianon committed Jun 6, 2019
1 parent 4c9db49 commit 4d88a14
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
19 changes: 13 additions & 6 deletions bashbrew/go/src/bashbrew/cmd-deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down
23 changes: 20 additions & 3 deletions bashbrew/go/src/bashbrew/cmd-from.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, " ")
Expand Down
8 changes: 4 additions & 4 deletions bashbrew/go/src/bashbrew/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down

0 comments on commit 4d88a14

Please sign in to comment.