File tree Expand file tree Collapse file tree 4 files changed +33
-7
lines changed
Expand file tree Collapse file tree 4 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -522,11 +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" ]
529-
530525 envfile = None
531526 initfile = None
532527 isatty = os .isatty (sys .stdin .fileno ())
@@ -569,6 +564,14 @@ def load_task(
569564
570565 command .extend (["-v" , f"{ initfile .name } :/builds/worker/.bashrc" ])
571566
567+ # run-task expects the worker to mount a volume for each path defined in
568+ # TASKCLUSTER_CACHES
569+ if "TASKCLUSTER_CACHES" in env :
570+ caches = env ["TASKCLUSTER_CACHES" ].split (";" )
571+ for cache in caches :
572+ if not volumes or cache not in volumes :
573+ command .extend (["-v" , cache ])
574+
572575 if volumes :
573576 for k , v in volumes .items ():
574577 command .extend (["-v" , f"{ k } :{ v } " ])
Original file line number Diff line number Diff 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+ )
795803def 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
Original file line number Diff line number Diff line change @@ -231,7 +231,7 @@ def test_load_task_env_init_and_remove(mocker, run_load_task):
231231 env_lines = written_env_content [0 ].split ("\n " )
232232
233233 # Verify written env is expected
234- assert "TASKCLUSTER_CACHES=path" not in env_lines
234+ assert "TASKCLUSTER_CACHES=path" in env_lines
235235 assert "FOO=BAR" in env_lines
236236 assert "BAZ=1" in env_lines
237237
@@ -253,7 +253,12 @@ def test_load_task_env_init_and_remove(mocker, run_load_task):
253253 actual = mocks ["subprocess_run" ].call_args [0 ][0 ]
254254 assert actual [4 ] == "--rm"
255255 assert actual [5 ] == "--env-file=/tmp/test_envfile"
256- assert actual [6 :8 ] == ["-v" , "/tmp/test_initfile:/builds/worker/.bashrc" ]
256+ assert actual [6 :10 ] == [
257+ "-v" ,
258+ "/tmp/test_initfile:/builds/worker/.bashrc" ,
259+ "-v" ,
260+ "path" ,
261+ ]
257262
258263
259264@pytest .mark .parametrize (
Original file line number Diff line number Diff line change @@ -466,6 +466,7 @@ def test_load_task_command(run_load_task):
466466 remove = True ,
467467 user = None ,
468468 custom_image = None ,
469+ volumes = {},
469470 )
470471
471472 # Test with interactive flag
@@ -479,6 +480,7 @@ def test_load_task_command(run_load_task):
479480 remove = True ,
480481 user = None ,
481482 custom_image = None ,
483+ volumes = {},
482484 )
483485
484486
@@ -503,6 +505,7 @@ def test_load_task_command_with_stdin(run_load_task):
503505 remove = True ,
504506 user = None ,
505507 custom_image = None ,
508+ volumes = {},
506509 )
507510
508511
@@ -520,6 +523,7 @@ def test_load_task_command_with_task_id(run_load_task):
520523 remove = True ,
521524 user = None ,
522525 custom_image = None ,
526+ volumes = {},
523527 )
524528
525529
You can’t perform that action at this time.
0 commit comments