Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/taskgraph/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from taskgraph.util import docker
from taskgraph.util.taskcluster import (
get_artifact_url,
get_root_url,
get_session,
get_task_definition,
)
Expand Down Expand Up @@ -295,7 +296,15 @@ def load_task(task_id, remove=True):
image_task_id = task_def["payload"]["image"]["taskId"]
image_tag = load_image_by_task_id(image_task_id)

env = task_def["payload"].get("env")
# Set some env vars the worker would normally set.
env = {
"RUN_ID": "0",
"TASK_GROUP_ID": task_def.get("taskGroupId", ""),
"TASK_ID": task_id,
"TASKCLUSTER_ROOT_URL": get_root_url(False),
}
# Add the task's environment variables.
env.update(task_def["payload"].get("env", {}))

envfile = None
initfile = None
Expand All @@ -307,7 +316,7 @@ def load_task(task_id, remove=True):
image_tag,
"bash",
"-c",
f"{shlex.join(command)} && cd $TASK_WORKDIR && bash",
f"{shlex.join(command)} && cd $TASK_WORKDIR && su -p worker",
]

if remove:
Expand Down
5 changes: 4 additions & 1 deletion test/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,21 @@ def test_load_task(run_load_task):
"run",
"-v",
re.compile(f"{tempfile.gettempdir()}/tmp.*:/builds/worker/.bashrc"),
re.compile(f"--env-file={tempfile.gettempdir()}/tmp.*"),
"-it",
"image/tag",
"bash",
"-c",
"/usr/bin/run-task --repo-checkout=/builds/worker/vcs/repo "
"--task-cwd=/builds/worker/vcs/repo -- echo 'Task setup complete!\n"
"Run `exec-task` to execute the task'\"'\"'s command.' && cd $TASK_WORKDIR && bash",
"Run `exec-task` to execute the task'\"'\"'s command.' && cd $TASK_WORKDIR && su -p worker",
]

mocks["subprocess_run"].assert_called_once()
actual = mocks["subprocess_run"].call_args[0][0]

print(expected)
print(actual)
assert len(expected) == len(actual)
for i, exp in enumerate(expected):
if isinstance(exp, re.Pattern):
Expand Down
Loading