Skip to content

Commit 9d7bde6

Browse files
committed
load-task: allow specifying caches on the command line
When debugging a task it can be useful to re-use e.g. the checkout cache between load-task invocations, to not have to clone from scratch each time.
1 parent ee9db51 commit 9d7bde6

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/taskgraph/docker.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,6 @@ def load_task(
522522
# Add the task's environment variables.
523523
env.update(task_def["payload"].get("env", {})) # type: ignore
524524

525-
# run-task expects the worker to mount a volume for each path defined in
526-
# TASKCLUSTER_CACHES, delete them to avoid needing to do the same.
527-
if "TASKCLUSTER_CACHES" in env:
528-
del env["TASKCLUSTER_CACHES"]
529525

530526
envfile = None
531527
initfile = None
@@ -569,6 +565,14 @@ def load_task(
569565

570566
command.extend(["-v", f"{initfile.name}:/builds/worker/.bashrc"])
571567

568+
# run-task expects the worker to mount a volume for each path defined in
569+
# TASKCLUSTER_CACHES
570+
if "TASKCLUSTER_CACHES" in env:
571+
caches = env["TASKCLUSTER_CACHES"].split(";")
572+
for cache in caches:
573+
if not volumes or cache not in volumes:
574+
command.extend(["-v", cache])
575+
572576
if volumes:
573577
for k, v in volumes.items():
574578
command.extend(["-v", f"{k}:{v}"])

src/taskgraph/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,14 @@ def image_digest(args):
792792
default="taskcluster",
793793
help="Relative path to the root of the Taskgraph definition.",
794794
)
795+
@argument(
796+
"--volume",
797+
"-v",
798+
metavar="HOST_DIR:CONTAINER_DIR",
799+
default=[],
800+
action="append",
801+
help="Mount local path into the container.",
802+
)
795803
def load_task(args):
796804
from taskgraph.config import load_graph_config # noqa: PLC0415
797805
from taskgraph.docker import load_task # noqa: PLC0415
@@ -806,6 +814,11 @@ def load_task(args):
806814
except ValueError:
807815
args["task"] = data # assume it is a taskId
808816

817+
volumes = {}
818+
for vol in args["volume"]:
819+
k, v = vol.split(":", 1)
820+
volumes[k] = v
821+
809822
root = args["root"]
810823
graph_config = load_graph_config(root)
811824
return load_task(
@@ -815,6 +828,7 @@ def load_task(args):
815828
remove=args["remove"],
816829
user=args["user"],
817830
custom_image=args["image"],
831+
volumes=volumes,
818832
)
819833

820834

0 commit comments

Comments
 (0)