Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support --platform parameter in image_from #130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions dockerfile_parse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<image> \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> --platform=\S+)? # optional platform parameter
rcerven marked this conversation as resolved.
Show resolved Hide resolved
\s* # more whitespaces
(?P<image> \S+ ) # image and optional tag
(?: # optional "AS name" clause for stage
\s+ AS \s+
(?P<name> \S+ )
)?
Expand Down
6 changes: 6 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down