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