Skip to content

Commit 4d88a14

Browse files
committed
Improve Dockerfile fetching error reporting and "bashbrew children" / "bashbrew from" handling (especially in the case of no "--apply-constraints" flag)
1 parent 4c9db49 commit 4d88a14

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

bashbrew/go/src/bashbrew/cmd-deps.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,20 @@ func cmdFamily(parents bool, c *cli.Context) error {
6767
continue
6868
}
6969

70-
froms, err := r.DockerFroms(entry)
71-
if err != nil {
72-
return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q)`, r.RepoName, entry.TagsString()), err)
70+
entryArches := []string{arch}
71+
if !applyConstraints {
72+
entryArches = entry.Architectures
7373
}
74-
for _, from := range froms {
75-
for _, tag := range r.Tags("", false, entry) {
76-
network.AddEdge(from, tag)
74+
75+
for _, entryArch := range entryArches {
76+
froms, err := r.ArchDockerFroms(entryArch, entry)
77+
if err != nil {
78+
return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q, arch %q)`, r.RepoName, entry.TagsString(), entryArch), err)
79+
}
80+
for _, from := range froms {
81+
for _, tag := range r.Tags("", false, entry) {
82+
network.AddEdge(from, tag)
83+
}
7784
}
7885
}
7986
}

bashbrew/go/src/bashbrew/cmd-from.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,26 @@ func cmdFrom(c *cli.Context) error {
2828
continue
2929
}
3030

31-
froms, err := r.DockerFroms(entry)
32-
if err != nil {
33-
return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q)`, r.RepoName, entry.TagsString()), err)
31+
entryArches := []string{arch}
32+
if !applyConstraints {
33+
entryArches = entry.Architectures
34+
}
35+
36+
froms := []string{}
37+
for _, entryArch := range entryArches {
38+
archFroms, err := r.ArchDockerFroms(entryArch, entry)
39+
if err != nil {
40+
return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q, arch %q)`, r.RepoName, entry.TagsString(), entryArch), err)
41+
}
42+
ArchFroms:
43+
for _, archFrom := range archFroms {
44+
for _, from := range froms {
45+
if from == archFrom {
46+
continue ArchFroms
47+
}
48+
}
49+
froms = append(froms, archFrom)
50+
}
3451
}
3552

3653
fromsString := strings.Join(froms, " ")

bashbrew/go/src/bashbrew/docker.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var dockerfileMetadataCache = map[string]*dockerfileMetadata{}
5555
func (r Repo) archDockerfileMetadata(arch string, entry *manifest.Manifest2822Entry) (*dockerfileMetadata, error) {
5656
commit, err := r.fetchGitRepo(arch, entry)
5757
if err != nil {
58-
return nil, err
58+
return nil, cli.NewMultiError(fmt.Errorf("failed fetching Git repo for arch %q from entry %q", arch, entry.String()), err)
5959
}
6060

6161
dockerfileFile := path.Join(entry.ArchDirectory(arch), entry.ArchFile(arch))
@@ -70,17 +70,17 @@ func (r Repo) archDockerfileMetadata(arch string, entry *manifest.Manifest2822En
7070

7171
dockerfile, err := gitShow(commit, dockerfileFile)
7272
if err != nil {
73-
return nil, err
73+
return nil, cli.NewMultiError(fmt.Errorf(`failed "git show" for %q from commit %q`, dockerfileFile, commit), err)
7474
}
7575
defer dockerfile.Close()
7676

7777
meta, err := parseDockerfileMetadata(dockerfile)
7878
if err != nil {
79-
return nil, err
79+
return nil, cli.NewMultiError(fmt.Errorf(`failed parsing Dockerfile metadata for %q from commit %q`, dockerfileFile, commit), err)
8080
}
8181

8282
if err := dockerfile.Close(); err != nil {
83-
return nil, err
83+
return nil, cli.NewMultiError(fmt.Errorf(`failed closing "git show" for %q from commit %q`, dockerfileFile, commit), err)
8484
}
8585

8686
dockerfileMetadataCache[cacheKey] = meta

0 commit comments

Comments
 (0)