Bust the dockerfile build cache across repository lines.
This commit is contained in:
parent
d95c321e28
commit
0a9ee6c49f
2 changed files with 25 additions and 1 deletions
|
@ -79,3 +79,8 @@ def parse_dockerfile(contents):
|
|||
})
|
||||
|
||||
return ParsedDockerfile(commands)
|
||||
|
||||
|
||||
def serialize_dockerfile(parsed_dockerfile):
|
||||
return '\n'.join([' '.join([command['command'], command['parameters']])
|
||||
for command in parsed_dockerfile.commands])
|
||||
|
|
|
@ -21,7 +21,7 @@ from data import model
|
|||
from workers.worker import Worker
|
||||
from app import app, userfiles as user_files
|
||||
from util.safetar import safe_extractall
|
||||
from util.dockerfileparse import parse_dockerfile, ParsedDockerfile
|
||||
from util.dockerfileparse import parse_dockerfile, ParsedDockerfile, serialize_dockerfile
|
||||
|
||||
|
||||
root_logger = logging.getLogger('')
|
||||
|
@ -124,8 +124,13 @@ class DockerfileBuildContext(object):
|
|||
# Compute the number of steps
|
||||
with open(dockerfile_path, 'r') as dockerfileobj:
|
||||
self._parsed_dockerfile = parse_dockerfile(dockerfileobj.read())
|
||||
|
||||
self.__inject_quay_repo_env(self._parsed_dockerfile, repo)
|
||||
self._num_steps = len(self._parsed_dockerfile.commands)
|
||||
|
||||
with open(dockerfile_path, 'w') as dockerfileobj:
|
||||
dockerfileobj.write(serialize_dockerfile(self._parsed_dockerfile))
|
||||
|
||||
logger.debug('Will build and push to repo %s with tags named: %s' %
|
||||
(self._repo, self._tag_names))
|
||||
|
||||
|
@ -141,6 +146,20 @@ class DockerfileBuildContext(object):
|
|||
|
||||
shutil.rmtree(self._build_dir)
|
||||
|
||||
@staticmethod
|
||||
def __inject_quay_repo_env(parsed_dockerfile, quay_reponame):
|
||||
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
|
||||
logger.debug('Injecting env command at dockerfile index: %s', new_command_index)
|
||||
parsed_dockerfile.commands.insert(new_command_index, env_command)
|
||||
break
|
||||
|
||||
|
||||
@staticmethod
|
||||
def __total_completion(statuses, total_images):
|
||||
percentage_with_sizes = float(len(statuses.values()))/total_images
|
||||
|
|
Reference in a new issue