Bug 1334401 - Prefer docker images from higher levels. r?jonasfj
Considering docker images contents depend very much on the moment they
were built, it is possible that two images with the same hash in the
taskcluster index (at different levels) have different contents. When
this happens, the build or test results could be significantly
different between e.g. try and mozilla-central, possibly leading to
misleading results at landing time.
So if for some reason multiple levels have images for the same hash, the
one used at the highest level should be prefered, such that try uses the
same as mozilla-central once mozilla-central generates the image for
that hash, even if there is an image previously generated for try.
--- a/taskcluster/taskgraph/task/docker_image.py
+++ b/taskcluster/taskgraph/task/docker_image.py
@@ -82,17 +82,17 @@ class DockerImageTask(base.Task):
# As an optimization, if the context hash exists for a high level, that image
# task ID will be used. The reasoning behind this is that eventually everything ends
# up on level 3 at some point if most tasks use this as a common image
# for a given context hash, a worker within Taskcluster does not need to contain
# the same image per branch.
index_paths = ['{}.level-{}.{}.hash.{}'.format(
INDEX_PREFIX, level, image_name, context_hash)
- for level in range(int(params['level']), 4)]
+ for level in reversed(range(int(params['level']), 4))]
tasks.append(cls(kind, 'build-docker-image-' + image_name,
task=image_task['task'], attributes=attributes,
index_paths=index_paths))
return tasks
def get_dependencies(self, taskgraph):
@@ -123,15 +123,15 @@ class DockerImageTask(base.Task):
@classmethod
def from_json(cls, task_dict):
# Generating index_paths for optimization
imgMeta = task_dict['task']['extra']['imageMeta']
image_name = imgMeta['imageName']
context_hash = imgMeta['contextHash']
index_paths = ['{}.level-{}.{}.hash.{}'.format(
INDEX_PREFIX, level, image_name, context_hash)
- for level in range(int(imgMeta['level']), 4)]
+ for level in reversed(range(int(imgMeta['level']), 4))]
docker_image_task = cls(kind='docker-image',
label=task_dict['label'],
attributes=task_dict['attributes'],
task=task_dict['task'],
index_paths=index_paths)
return docker_image_task
--- a/taskcluster/taskgraph/test/test_taskgraph.py
+++ b/taskcluster/taskgraph/test/test_taskgraph.py
@@ -23,17 +23,17 @@ class TestTargetTasks(unittest.TestCase)
"imageMeta": {
"contextHash": "<hash>",
"imageName": "<image>",
"level": "1"
}
}
}
index_paths = ["{}.level-{}.<image>.hash.<hash>".format(INDEX_PREFIX, level)
- for level in range(1, 4)]
+ for level in reversed(range(1, 4))]
graph = TaskGraph(tasks={
'a': TransformTask(
kind='fancy',
task={
'label': 'a',
'attributes': {},
'dependencies': {},
'when': {},