You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This allows bashbrew to properly handle cross-repository and cross-tag dependencies even in the face of multiple `FROM` instructions or `COPY --from=`.
This also provides the scaffolding necessary to implement this in scripts using `bashbrew cat`.
As fallback behavior, the `*DockerFrom` functions should return the `FROM` of the last stage in the `Dockerfile` (which is essentially the `FROM` of the final image).
Also, the output of `bashbrew from` is now a space-separated list.
returncli.NewMultiError(fmt.Errorf(`failed fetching/scraping FROM for %q (tags %q)`, r.RepoName, entry.TagsString()), err)
50
50
}
51
51
52
-
iffrom!="scratch"&&pull!="never" {
53
-
doPull:=false
54
-
switchpull {
55
-
case"always":
56
-
doPull=true
57
-
case"missing":
58
-
_, err:=dockerInspect("{{.Id}}", from)
59
-
doPull= (err!=nil)
60
-
default:
61
-
returnfmt.Errorf(`unexpected value for --pull: %s`, pull)
62
-
}
63
-
ifdoPull {
64
-
// TODO detect if "from" is something we've built (ie, "python:3-onbuild" is "FROM python:3" but we don't want to pull "python:3" if we "bashbrew build python")
returnfmt.Errorf(`unexpected value for --pull: %s`, pull)
63
+
}
64
+
ifdoPull {
65
+
// TODO detect if "from" is something we've built (ie, "python:3-onbuild" is "FROM python:3" but we don't want to pull "python:3" if we "bashbrew build python")
// TODO use "meta.StageNames" to do "docker build --target" so we can tag intermediate stages too for cache (streaming "git archive" directly to "docker build" makes that a little hard to accomplish without re-streaming)
StageFroms []string// every image "FROM" instruction value (or the parent stage's FROM value in the case of a named stage)
22
+
StageNames []string// the name of any named stage (in order)
23
+
StageNameFromsmap[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
24
+
25
+
Froms []string// every "FROM" or "COPY --from=xxx" value (minus named and/or numbered stages in the case of "--from=")
// (TODO see note above regarding "escape" parser directive)
107
+
forline[len(line)-1] =='\\'&&scanner.Scan() {
108
+
nextLine:=strings.TrimSpace(scanner.Text())
109
+
ifnextLine==""||nextLine[0] =='#' {
110
+
// ignore blank lines and comments
111
+
continue
112
+
}
113
+
line=line[0:len(line)-1]+nextLine
114
+
}
115
+
76
116
fields:=strings.Fields(line)
77
117
iflen(fields) <1 {
118
+
// must be a much more complex empty line??
78
119
continue
79
120
}
80
-
ifstrings.ToUpper(fields[0]) =="FROM" {
81
-
returnfields[1], nil
121
+
instruction:=strings.ToUpper(fields[0])
122
+
123
+
// TODO balk at ARG / $ in from values
124
+
125
+
switchinstruction {
126
+
case"FROM":
127
+
from:=fields[1]
128
+
129
+
ifstageFrom, ok:=meta.StageNameFroms[from]; ok {
130
+
// if this is a valid stage name, we should resolve it back to the original FROM value of that previous stage (we don't care about inter-stage dependencies for the purposes of either tag dependency calculation or tag building -- just how many there are and what external things they require)
0 commit comments