Skip to content

Commit ff7bbc9

Browse files
tim-vkrcerven
authored andcommitted
support --platform parameter in image_from
Signed-off-by: Tim van Katwijk <[email protected]>
1 parent 6ccdbee commit ff7bbc9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

dockerfile_parse/parser.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,10 +869,12 @@ def image_from(from_value):
869869
:param from_value: string like "image:tag" or "image:tag AS name"
870870
:return: tuple of the image and stage name, e.g. ("image:tag", None)
871871
"""
872-
regex = re.compile(r"""(?xi) # readable, case-insensitive regex
873-
\s* # ignore leading whitespace
874-
(?P<image> \S+ ) # image and optional tag
875-
(?: # optional "AS name" clause for stage
872+
regex = re.compile(r"""(?xi) # readable, case-insensitive regex
873+
\s* # ignore leading whitespace
874+
(?P<platform> --platform=\S+)? # optional platform parameter
875+
\s* # more whitespaces
876+
(?P<image> \S+ ) # image and optional tag
877+
(?: # optional "AS name" clause for stage
876878
\s+ AS \s+
877879
(?P<name> \S+ )
878880
)?

tests/test_parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,12 @@ def test_get_baseimg_from_df(self, dfparser):
312312
dfparser.lines = ["From fedora:latest\n",
313313
"LABEL a b\n"]
314314
assert dfparser.baseimage == 'fedora:latest'
315+
316+
317+
def test_get_baseimg_from_df_with_platform(self, dfparser):
318+
dfparser.lines = ["From --platform=linux/amd64 fedora:latest\n",
319+
"LABEL a b\n"]
320+
assert dfparser.baseimage == 'fedora:latest'
315321

316322
def test_get_baseimg_from_arg(self, dfparser):
317323
dfparser.lines = ["ARG BASE=fedora:latest\n",

0 commit comments

Comments
 (0)