Skip to content

Commit a243c72

Browse files
committed
Unexpose "DockerfileMetadata" and add new exposed "DockerFroms" (since that's what's really necessary externally from that internal structure)
1 parent da87baa commit a243c72

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

go/src/bashbrew/cmd-build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ func cmdBuild(c *cli.Context) error {
4444
continue
4545
}
4646

47-
meta, err := r.DockerfileMetadata(entry)
47+
froms, err := r.DockerFroms(entry)
4848
if err != nil {
4949
return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q)`, r.RepoName, entry.TagsString()), err)
5050
}
5151

52-
for _, from := range meta.Froms {
52+
for _, from := range froms {
5353
if from != "scratch" && pull != "never" {
5454
doPull := false
5555
switch pull {

go/src/bashbrew/cmd-deps.go

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

70-
meta, err := r.DockerfileMetadata(entry)
70+
froms, err := r.DockerFroms(entry)
7171
if err != nil {
7272
return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q)`, r.RepoName, entry.TagsString()), err)
7373
}
74-
for _, from := range meta.Froms {
74+
for _, from := range froms {
7575
for _, tag := range r.Tags("", false, entry) {
7676
network.AddEdge(from, tag)
7777
}

go/src/bashbrew/cmd-from.go

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

31-
meta, err := r.DockerfileMetadata(entry)
31+
froms, err := r.DockerFroms(entry)
3232
if err != nil {
3333
return cli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q)`, r.RepoName, entry.TagsString()), err)
3434
}
3535

36-
froms := strings.Join(meta.Froms, " ")
36+
fromsString := strings.Join(froms, " ")
3737
for _, tag := range r.Tags(namespace, uniq, entry) {
38-
fmt.Printf("%s: %s\n", tag, froms)
38+
fmt.Printf("%s: %s\n", tag, fromsString)
3939
}
4040
}
4141
}

go/src/bashbrew/docker.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/docker-library/go-dockerlibrary/manifest"
1818
)
1919

20-
type DockerfileMetadata struct {
20+
type dockerfileMetadata struct {
2121
StageFroms []string // every image "FROM" instruction value (or the parent stage's FROM value in the case of a named stage)
2222
StageNames []string // the name of any named stage (in order)
2323
StageNameFroms map[string]string // map of stage names to FROM values (or the parent stage's FROM value in the case of a named stage), useful for resolving stage names to FROM values
@@ -30,21 +30,33 @@ func (r Repo) DockerFrom(entry *manifest.Manifest2822Entry) (string, error) {
3030
}
3131

3232
func (r Repo) ArchDockerFrom(arch string, entry *manifest.Manifest2822Entry) (string, error) {
33-
dockerfileMeta, err := r.ArchDockerfileMetadata(arch, entry)
33+
dockerfileMeta, err := r.archDockerfileMetadata(arch, entry)
3434
if err != nil {
3535
return "", err
3636
}
3737

3838
return dockerfileMeta.StageFroms[len(dockerfileMeta.StageFroms)-1], nil
3939
}
4040

41-
func (r Repo) DockerfileMetadata(entry *manifest.Manifest2822Entry) (*DockerfileMetadata, error) {
42-
return r.ArchDockerfileMetadata(arch, entry)
41+
func (r Repo) DockerFroms(entry *manifest.Manifest2822Entry) ([]string, error) {
42+
return r.ArchDockerFroms(arch, entry)
4343
}
4444

45-
var dockerfileMetadataCache = map[string]*DockerfileMetadata{}
45+
func (r Repo) ArchDockerFroms(arch string, entry *manifest.Manifest2822Entry) ([]string, error) {
46+
dockerfileMeta, err := r.archDockerfileMetadata(arch, entry)
47+
if err != nil {
48+
return nil, err
49+
}
50+
return dockerfileMeta.Froms, nil
51+
}
52+
53+
func (r Repo) dockerfileMetadata(entry *manifest.Manifest2822Entry) (*dockerfileMetadata, error) {
54+
return r.archDockerfileMetadata(arch, entry)
55+
}
56+
57+
var dockerfileMetadataCache = map[string]*dockerfileMetadata{}
4658

47-
func (r Repo) ArchDockerfileMetadata(arch string, entry *manifest.Manifest2822Entry) (*DockerfileMetadata, error) {
59+
func (r Repo) archDockerfileMetadata(arch string, entry *manifest.Manifest2822Entry) (*dockerfileMetadata, error) {
4860
commit, err := r.fetchGitRepo(arch, entry)
4961
if err != nil {
5062
return nil, err
@@ -79,8 +91,8 @@ func (r Repo) ArchDockerfileMetadata(arch string, entry *manifest.Manifest2822En
7991
return meta, nil
8092
}
8193

82-
func parseDockerfileMetadata(dockerfile io.Reader) (*DockerfileMetadata, error) {
83-
meta := &DockerfileMetadata{
94+
func parseDockerfileMetadata(dockerfile io.Reader) (*dockerfileMetadata, error) {
95+
meta := &dockerfileMetadata{
8496
// panic: assignment to entry in nil map
8597
StageNameFroms: map[string]string{},
8698
// (nil slices work fine)
@@ -215,7 +227,7 @@ func (r Repo) dockerBuildUniqueBits(entry *manifest.Manifest2822Entry) ([]string
215227
entry.ArchDirectory(arch),
216228
entry.ArchFile(arch),
217229
}
218-
meta, err := r.DockerfileMetadata(entry)
230+
meta, err := r.dockerfileMetadata(entry)
219231
if err != nil {
220232
return nil, err
221233
}

go/src/bashbrew/sort.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ func sortRepoObjects(rs []*Repo, applyConstraints bool) ([]*Repo, error) {
101101
continue
102102
}
103103

104-
meta, err := r.DockerfileMetadata(entry)
104+
froms, err := r.DockerFroms(entry)
105105
if err != nil {
106106
return nil, err
107107
}
108108

109-
for _, from := range meta.Froms {
109+
for _, from := range froms {
110110
fromNode, ok := canonicalNodes[from]
111111
if !ok {
112112
// if our FROM isn't in the list of things we're sorting, it isn't relevant in this context

0 commit comments

Comments
 (0)