Skip to content

Commit

Permalink
Avoid adding repos to from scratch with alias
Browse files Browse the repository at this point in the history
CLOUDBLD-5945

Signed-off-by: Ladislav Kolacek <lkolacek@redhat.com>
  • Loading branch information
lkolacek committed Jun 8, 2021
1 parent 169a7ff commit 316761a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dockerfile_parse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 ❤"
Expand Down

0 comments on commit 316761a

Please sign in to comment.