@@ -106,6 +106,49 @@ func ParseReader(dockerfile io.Reader) (*Metadata, error) {
106
106
// make sure to add ":latest" if it's implied
107
107
from = latestizeRepoTag (from )
108
108
109
+ meta .Froms = append (meta .Froms , from )
110
+ }
111
+
112
+ case "RUN" : // TODO combine this and the above COPY-parsing code somehow sanely
113
+ for _ , arg := range fields [1 :] {
114
+ if ! strings .HasPrefix (arg , "--" ) {
115
+ // doesn't appear to be a "flag"; time to bail!
116
+ break
117
+ }
118
+ if ! strings .HasPrefix (arg , "--mount=" ) {
119
+ // ignore any flags we're not interested in
120
+ continue
121
+ }
122
+ csv := arg [len ("--mount=" ):]
123
+ // TODO more correct CSV parsing
124
+ fields := strings .Split (csv , "," )
125
+ var mountType , from string
126
+ for _ , field := range fields {
127
+ if strings .HasPrefix (field , "type=" ) {
128
+ mountType = field [len ("type=" ):]
129
+ continue
130
+ }
131
+ if strings .HasPrefix (field , "from=" ) {
132
+ from = field [len ("from=" ):]
133
+ continue
134
+ }
135
+ }
136
+ if mountType != "bind" || from == "" {
137
+ // this is probably something we should be worried about, but not something we're interested in parsing
138
+ continue
139
+ }
140
+
141
+ if stageFrom , ok := meta .StageNameFroms [from ]; ok {
142
+ // see note above regarding stage names in FROM
143
+ from = stageFrom
144
+ } else if stageNumber , err := strconv .Atoi (from ); err == nil && stageNumber < len (meta .StageFroms ) {
145
+ // must be a stage number, we should resolve it too
146
+ from = meta .StageFroms [stageNumber ]
147
+ }
148
+
149
+ // make sure to add ":latest" if it's implied
150
+ from = latestizeRepoTag (from )
151
+
109
152
meta .Froms = append (meta .Froms , from )
110
153
}
111
154
}
0 commit comments