From d9dd46d344e72bb6da7d792c919ec8dcdadcdf2f Mon Sep 17 00:00:00 2001 From: Tim van Katwijk Date: Wed, 28 Sep 2022 12:22:23 +0200 Subject: [PATCH] support --platform parameter in image_from Signed-off-by: Tim van Katwijk --- dockerfile_parse/parser.py | 10 ++++++---- tests/test_parser.py | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) 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",