diff --git a/src/taskgraph/docker.py b/src/taskgraph/docker.py index fd16e274b..ba8b57c73 100644 --- a/src/taskgraph/docker.py +++ b/src/taskgraph/docker.py @@ -211,7 +211,9 @@ def build_image( raise # Parent id doesn't exist, needs to be re-built as well. - parent = task.dependencies["parent"][len("docker-image-") :] + parent = next( + t for t in image_tasks if image_tasks[t].task_id == parent_id + ).removeprefix("docker-image-") parent_tar = temp_dir / "parent.tar" build_image(graph_config, parent, save_image=str(parent_tar)) volumes.append((str(parent_tar), "/workspace/parent.tar")) diff --git a/test/test_docker.py b/test/test_docker.py index 5cd5c5b7e..f5b6429c1 100644 --- a/test/test_docker.py +++ b/test/test_docker.py @@ -547,7 +547,13 @@ def test_load_task_with_develop(mocker, run_load_task, task): @pytest.fixture def run_build_image(mocker): - def inner(image_name, save_image=None, context_file=None, image_task=None): + def inner( + image_name, + save_image=None, + context_file=None, + image_task=None, + parent_task_id=None, + ): graph_config = GraphConfig( { "trust-domain": "test-domain", @@ -614,6 +620,8 @@ def mock_path_constructor(path_arg): parent_image = mocker.MagicMock() parent_image.task = {"payload": {"env": {}}} + if parent_task_id: + parent_image.task_id = parent_task_id mocks["image_task"] = image_task mocks["load_tasks_for_kind"].return_value = { @@ -717,8 +725,10 @@ def test_build_image_with_parent_not_found( # Test building image that uses DOCKER_IMAGE_PARENT image_task = mocker.MagicMock() image_task.task = {"payload": {"env": {"PARENT_TASK_ID": parent_task_id}}} - image_task.dependencies = {"parent": "docker-image-parent"} - result, mocks = run_build_image("hello-world", image_task=image_task) + image_task.dependencies = {"parent": parent_task_id} + result, mocks = run_build_image( + "hello-world", image_task=image_task, parent_task_id=parent_task_id + ) assert result == "hello-world:latest" # Verify the graph generation call