diff --git a/dockerfile_parse/parser.py b/dockerfile_parse/parser.py index 343ef30..e95087e 100644 --- a/dockerfile_parse/parser.py +++ b/dockerfile_parse/parser.py @@ -871,10 +871,12 @@ def image_from(from_value): :param from_value: string like "image:tag" or "image:tag AS name" :return: tuple of the image and stage name, e.g. ("image:tag", None) """ - regex = re.compile(r"""(?xi) # readable, case-insensitive regex - \s* # ignore leading whitespace - (?P \S+ ) # image and optional tag - (?: # optional "AS name" clause for stage + regex = re.compile(r"""(?xi) # readable, case-insensitive regex + \s* # ignore leading whitespace + (?P --platform=\S+)? # optional platform parameter + \s* # more whitespaces + (?P \S+ ) # image and optional tag + (?: # optional "AS name" clause for stage \s+ AS \s+ (?P \S+ ) )? diff --git a/tests/test_parser.py b/tests/test_parser.py index fda75ab..e0ad807 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -311,6 +311,12 @@ def test_get_baseimg_from_df(self, dfparser): dfparser.lines = ["From fedora:latest\n", "LABEL a b\n"] assert dfparser.baseimage == 'fedora:latest' + + + def test_get_baseimg_from_df_with_platform(self, dfparser): + dfparser.lines = ["From --platform=linux/amd64 fedora:latest\n", + "LABEL a b\n"] + assert dfparser.baseimage == 'fedora:latest' def test_get_baseimg_from_arg(self, dfparser): dfparser.lines = ["ARG BASE=fedora:latest\n",