Fix broken regex for Dockerfile parsing
This commit is contained in:
parent
8c49e0d2c6
commit
91b8ecfb63
2 changed files with 19 additions and 1 deletions
18
tools/reparsedockerfile.py
Normal file
18
tools/reparsedockerfile.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from util.dockerfileparse import parse_dockerfile, ParsedDockerfile, serialize_dockerfile
|
||||
|
||||
with open('Dockerfile.test', 'r') as dockerfileobj:
|
||||
parsed_dockerfile = parse_dockerfile(dockerfileobj.read())
|
||||
|
||||
quay_reponame = 'something'
|
||||
env_command = {
|
||||
'command': 'ENV',
|
||||
'parameters': 'QUAY_REPOSITORY %s' % quay_reponame
|
||||
}
|
||||
|
||||
for index, command in reversed(list(enumerate(parsed_dockerfile.commands))):
|
||||
if command['command'] == 'FROM':
|
||||
new_command_index = index + 1
|
||||
parsed_dockerfile.commands.insert(new_command_index, env_command)
|
||||
break
|
||||
|
||||
print serialize_dockerfile(parsed_dockerfile)
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
|
||||
LINE_CONTINUATION_REGEX = re.compile('\s*\\\s*\n')
|
||||
LINE_CONTINUATION_REGEX = re.compile(r'(\s)*\\(\s)*\n')
|
||||
COMMAND_REGEX = re.compile('([A-Za-z]+)\s(.*)')
|
||||
|
||||
COMMENT_CHARACTER = '#'
|
||||
|
|
Reference in a new issue