Skip to content

Commit 879c515

Browse files
committed
feat(load-task): support specifying volumes
1 parent 3f49387 commit 879c515

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/taskgraph/docker.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ def load_task(
380380
user: Optional[str] = None,
381381
custom_image: Optional[str] = None,
382382
interactive: Optional[bool] = False,
383+
volumes: Optional[Dict[str, str]] = None,
383384
) -> int:
384385
"""Load and run a task interactively in a Docker container.
385386
@@ -498,6 +499,11 @@ def load_task(
498499

499500
if task_command:
500501
command.extend(task_command)
502+
503+
if volumes:
504+
for k, v in volumes.items():
505+
command[2:2] = ["-v", f"{k}:{v}"]
506+
501507
if remove:
502508
command.insert(2, "--rm")
503509

test/test_docker.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ def mock_run(*popenargs, check=False, **kwargs):
111111
@pytest.fixture
112112
def run_load_task(mocker):
113113
def inner(
114-
task, remove=False, custom_image=None, pass_task_def=False, interactive=True
114+
task,
115+
remove=False,
116+
custom_image=None,
117+
pass_task_def=False,
118+
interactive=True,
119+
volumes=None,
115120
):
116121
proc = mocker.MagicMock()
117122
proc.returncode = 0
@@ -159,6 +164,7 @@ def inner(
159164
remove=remove,
160165
custom_image=custom_image,
161166
interactive=interactive,
167+
volumes=volumes,
162168
)
163169
return ret, mocks
164170

@@ -198,7 +204,9 @@ def test_load_task(run_load_task):
198204
"image": {"taskId": image_task_id, "type": "task-image"},
199205
},
200206
}
201-
ret, mocks = run_load_task(task)
207+
# Test with custom volumes
208+
volumes = {"/host/path": "/container/path", "/another/host": "/another/container"}
209+
ret, mocks = run_load_task(task, volumes=volumes)
202210
assert ret == 0
203211

204212
if "get_task_definition" in mocks:
@@ -211,6 +219,10 @@ def test_load_task(run_load_task):
211219
"-v",
212220
re.compile(f"{tempfile.gettempdir()}/tmp.*:/builds/worker/.bashrc"),
213221
re.compile(f"--env-file={tempfile.gettempdir()}/tmp.*"),
222+
"-v",
223+
"/another/host:/another/container",
224+
"-v",
225+
"/host/path:/container/path",
214226
"-i",
215227
"-t",
216228
"image/tag",

0 commit comments

Comments
 (0)