diff --git a/src/taskgraph/docker.py b/src/taskgraph/docker.py index 0bd7d8035..8dc76b8e9 100644 --- a/src/taskgraph/docker.py +++ b/src/taskgraph/docker.py @@ -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, ) @@ -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 @@ -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: diff --git a/test/test_docker.py b/test/test_docker.py index db010454d..3bc3d3638 100644 --- a/test/test_docker.py +++ b/test/test_docker.py @@ -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):