From 316761a4479de1a01e56ff051c8f405ad8b5b79f Mon Sep 17 00:00:00 2001 From: Ladislav Kolacek Date: Thu, 3 Jun 2021 15:17:48 +0200 Subject: [PATCH] Avoid adding repos to from scratch with alias CLOUDBLD-5945 Signed-off-by: Ladislav Kolacek --- dockerfile_parse/parser.py | 3 ++- tests/test_parser.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dockerfile_parse/parser.py b/dockerfile_parse/parser.py index 34b0e08..4c70415 100644 --- a/dockerfile_parse/parser.py +++ b/dockerfile_parse/parser.py @@ -767,7 +767,8 @@ def add_lines(self, *lines, **kwargs): for stage in range(len(froms)-2, -1, -1): # e.g. 0 for single or 2, 1, 0 for 3 stages start, finish = froms[stage], froms[stage+1] linenum = start['endline'] + 1 if at_start else finish['startline'] - if skip_scratch and froms[stage]['value'] == 'scratch': + image, _ = image_from(froms[stage].get('value') or '') + if skip_scratch and image == 'scratch': continue df_lines[linenum:linenum] = lines diff --git a/tests/test_parser.py b/tests/test_parser.py index db1b850..fda75ab 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1176,6 +1176,8 @@ def test_add_lines_stages_skip_scratch(self, dfparser, at_start): ENV h i From scratch LABEL type=scratch2 + From scratch as foo + LABEL type=scratch3 """) dfparser.add_lines("something new ❤", all_stages=True, skip_scratch=True, at_start=at_start) @@ -1186,7 +1188,7 @@ def test_add_lines_stages_skip_scratch(self, dfparser, at_start): assert "something new ❤" in dfparser.lines[2] assert "something new ❤" in dfparser.lines[8] assert len([line for line in dfparser.lines if "something new ❤" in line]) == 2 - assert len(dfparser.lines) == 11 + assert len(dfparser.lines) == 13 def test_add_lines_stage_edge(self, dfparser): dfparser.content = "# no from or newline ❤"