-
Notifications
You must be signed in to change notification settings - Fork 53
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
Move ImageName class from osbs client to utils of dockerfile parser. #139
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,7 @@ jobs: | |
targets: | ||
- fedora-all | ||
- epel-8-x86_64 | ||
|
||
srpm_build_deps: | ||
- python3-pip | ||
- python3-setuptools_scm |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,13 @@ | |
import logging | ||
import os | ||
import re | ||
import warnings | ||
from contextlib import contextmanager | ||
from shlex import quote | ||
|
||
from .constants import DOCKERFILE_FILENAME, COMMENT_INSTRUCTION | ||
from .util import (b2u, extract_key_values, get_key_val_dictionary, | ||
u2b, Context, WordSplitter) | ||
u2b, Context, WordSplitter, ImageName) | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -238,6 +239,7 @@ def structure(self): | |
"value": "yum -y update && yum clean all"} | ||
] | ||
""" | ||
|
||
def _rstrip_eol(text, line_continuation_char='\\'): | ||
text = text.rstrip() | ||
if text.endswith(line_continuation_char): | ||
|
@@ -262,8 +264,8 @@ def _clean_comment_line(line): | |
lineno = -1 | ||
line_continuation_char = '\\' | ||
insnre = re.compile(r'^\s*(\S+)\s+(.*)$') # matched group is insn | ||
contre = re.compile(r'^.*\\\s*$') # line continues? | ||
commentre = re.compile(r'^\s*#') # line is a comment? | ||
contre = re.compile(r'^.*\\\s*$') # line continues? | ||
commentre = re.compile(r'^\s*#') # line is a comment? | ||
directive_possible = True | ||
# escape directive regex | ||
escape_directive_re = re.compile(r'^\s*#\s*escape\s*=\s*(\\|`)\s*$', re.I) | ||
|
@@ -354,7 +356,7 @@ def parent_images(self): | |
top_args[key] = value | ||
elif instr['instruction'] == 'FROM': | ||
in_stage = True | ||
image, _ = image_from(instr['value']) | ||
image, _ = image_name_from(instr['value']) | ||
if image is not None: | ||
image = WordSplitter(image, args=top_args).dequote() | ||
parents.append(image) | ||
|
@@ -376,7 +378,7 @@ def parent_images(self, parents): | |
if instr['instruction'] != 'FROM': | ||
continue | ||
|
||
old_image, stage = image_from(instr['value']) | ||
old_image, stage = image_name_from(instr['value']) | ||
if old_image is None: | ||
continue # broken FROM, fixing would just confuse things | ||
if not parents: | ||
|
@@ -393,7 +395,7 @@ def parent_images(self, parents): | |
|
||
lines = self.lines | ||
for instr in reversed(change_instrs): | ||
lines[instr['startline']:instr['endline']+1] = [instr['content']] | ||
lines[instr['startline']:instr['endline'] + 1] = [instr['content']] | ||
|
||
self.lines = lines | ||
|
||
|
@@ -416,7 +418,7 @@ def baseimage(self, new_image): | |
images = [] | ||
for instr in self.structure: | ||
if instr['instruction'] == 'FROM': | ||
image, _ = image_from(instr['value']) | ||
image, _ = image_name_from(instr['value']) | ||
if image is not None: | ||
images.append(image) | ||
if not images: | ||
|
@@ -762,7 +764,7 @@ 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'] | ||
image, _ = image_from(froms[stage].get('value') or '') | ||
image, _ = image_name_from(froms[stage].get('value') or '') | ||
if skip_scratch and image == 'scratch': | ||
continue | ||
df_lines[linenum:linenum] = lines | ||
|
@@ -862,6 +864,16 @@ def context_structure(self): | |
|
||
|
||
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) | ||
""" | ||
warnings.warn("Use image_name_from instead.", DeprecationWarning) | ||
image, name = image_name_from(from_value) | ||
return str(image) if image else None, name | ||
|
||
|
||
def image_name_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) | ||
|
@@ -877,7 +889,9 @@ def image_from(from_value): | |
)? | ||
""") | ||
match = re.match(regex, from_value) | ||
return match.group('image', 'name') if match else (None, None) | ||
image = ImageName.parse(match.group('image')) if match else None | ||
name = match.group('name') if match else None | ||
return image, name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are breaking BW compatibility here, I'm not sure if we can do this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as i'm aware it shouldn't break backwards compatibility: Old version: Image was a string This should be backwards compatible (the unit tests reflect this: there are only tests added, not changed). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addition: Just realized what I typed above is not 100% true: See the explicit str(s) in util.py (line 51). Alternative solution would be keeping the old function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, explicit casting to str() is required, that's breaking change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO would be safer to add new function and add deprecation warning to this one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
|
||
|
||
def _endline(line): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was apparently still missing in the master repo: I'm not 100% certain if this is correct. Please verify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sure what this fix is fixing, we had not such issue previously