diff --git a/pkg/dockerfile/parse.go b/pkg/dockerfile/parse.go index 66ff0cf..81e3f67 100644 --- a/pkg/dockerfile/parse.go +++ b/pkg/dockerfile/parse.go @@ -106,6 +106,49 @@ func ParseReader(dockerfile io.Reader) (*Metadata, error) { // make sure to add ":latest" if it's implied from = latestizeRepoTag(from) + meta.Froms = append(meta.Froms, from) + } + + case "RUN": // TODO combine this and the above COPY-parsing code somehow sanely + for _, arg := range fields[1:] { + if !strings.HasPrefix(arg, "--") { + // doesn't appear to be a "flag"; time to bail! + break + } + if !strings.HasPrefix(arg, "--mount=") { + // ignore any flags we're not interested in + continue + } + csv := arg[len("--mount="):] + // TODO more correct CSV parsing + fields := strings.Split(csv, ",") + var mountType, from string + for _, field := range fields { + if strings.HasPrefix(field, "type=") { + mountType = field[len("type="):] + continue + } + if strings.HasPrefix(field, "from=") { + from = field[len("from="):] + continue + } + } + if mountType != "bind" || from == "" { + // this is probably something we should be worried about, but not something we're interested in parsing + continue + } + + if stageFrom, ok := meta.StageNameFroms[from]; ok { + // see note above regarding stage names in FROM + from = stageFrom + } else if stageNumber, err := strconv.Atoi(from); err == nil && stageNumber < len(meta.StageFroms) { + // must be a stage number, we should resolve it too + from = meta.StageFroms[stageNumber] + } + + // make sure to add ":latest" if it's implied + from = latestizeRepoTag(from) + meta.Froms = append(meta.Froms, from) } } diff --git a/pkg/dockerfile/parse_test.go b/pkg/dockerfile/parse_test.go index f650b4e..6e713fc 100644 --- a/pkg/dockerfile/parse_test.go +++ b/pkg/dockerfile/parse_test.go @@ -83,7 +83,7 @@ func TestParse(t *testing.T) { `, metadata: dockerfile.Metadata{ StageFroms: []string{"scratch"}, - Froms: []string{"scratch"}, // TODO this should include "busybox:uclibc" + Froms: []string{"scratch", "busybox:uclibc"}, }, }, { @@ -98,7 +98,7 @@ func TestParse(t *testing.T) { StageFroms: []string{"busybox:uclibc", "scratch"}, StageNames: []string{"bb"}, StageNameFroms: map[string]string{"bb": "busybox:uclibc"}, - Froms: []string{"busybox:uclibc", "scratch"}, // TODO this should end with "busybox:uclibc" + Froms: []string{"busybox:uclibc", "scratch", "busybox:uclibc"}, }, }, } {