Skip to content

Commit 30dd32e

Browse files
committed
fix(load-task): ensure we don't leave docker-contexts in cwd
1 parent 017b44d commit 30dd32e

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

src/taskgraph/docker.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
zstd = e
2727

2828
from taskgraph.config import GraphConfig
29-
from taskgraph.transforms.docker_image import IMAGE_BUILDER_IMAGE
29+
from taskgraph.transforms import docker_image
3030
from taskgraph.util import docker, json
3131
from taskgraph.util.taskcluster import (
3232
find_task_id,
@@ -162,22 +162,31 @@ def build_image(
162162
if not os.path.isdir(image_dir):
163163
raise Exception(f"image directory does not exist: {image_dir}")
164164

165-
label = f"docker-image-{name}"
166-
image_tasks = load_tasks_for_kind(
167-
{"do_not_optimize": [label]},
168-
"docker-image",
169-
graph_attr="morphed_task_graph",
170-
write_artifacts=True,
171-
)
172-
173-
image_context = Path(f"docker-contexts/{name}.tar.gz").resolve()
174-
if context_file:
175-
shutil.move(image_context, context_file)
176-
return ""
177-
178165
with tempfile.TemporaryDirectory() as temp_dir:
179166
temp_dir = Path(temp_dir)
180-
output_dir = temp_dir / "artifacts"
167+
168+
# Ensure the docker-image transforms save the docker-contexts to our
169+
# temp_dir
170+
label = f"docker-image-{name}"
171+
contexts_dir = temp_dir / "docker-contexts"
172+
old_contexts_dir = docker_image.CONTEXTS_DIR
173+
try:
174+
docker_image.CONTEXTS_DIR = str(contexts_dir)
175+
image_tasks = load_tasks_for_kind(
176+
{"do_not_optimize": [label]},
177+
"docker-image",
178+
graph_attr="morphed_task_graph",
179+
write_artifacts=True,
180+
)
181+
finally:
182+
docker_image.CONTEXTS_DIR = old_contexts_dir
183+
184+
image_context = contexts_dir.joinpath(f"{name}.tar.gz").resolve()
185+
if context_file:
186+
shutil.move(image_context, context_file)
187+
return ""
188+
189+
output_dir = temp_dir / "out"
181190
output_dir.mkdir()
182191
volumes = {
183192
# TODO write artifacts to tmpdir
@@ -208,7 +217,7 @@ def build_image(
208217
load_task(
209218
graph_config,
210219
task_def,
211-
custom_image=IMAGE_BUILDER_IMAGE,
220+
custom_image=docker_image.IMAGE_BUILDER_IMAGE,
212221
interactive=False,
213222
volumes=volumes,
214223
)

0 commit comments

Comments
 (0)