Fix broken regex for Dockerfile parsing

This commit is contained in:
Joseph Schorr 2014-09-12 14:01:10 -04:00
parent 8c49e0d2c6
commit 91b8ecfb63
2 changed files with 19 additions and 1 deletions

View 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)

View file

@ -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 = '#'