hazard.py (2151B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 """ 5 Support for running hazard jobs via dedicated scripts 6 """ 7 8 from taskgraph.util.schema import Schema 9 from voluptuous import Any, Optional, Required 10 11 from gecko_taskgraph.transforms.job import configure_taskdesc_for_run, run_job_using 12 from gecko_taskgraph.transforms.job.common import ( 13 add_tooltool, 14 docker_worker_add_artifacts, 15 setup_secrets, 16 ) 17 18 haz_run_schema = Schema({ 19 Required("using"): "hazard", 20 # The command to run within the task image (passed through to the worker) 21 Required("command"): str, 22 # The mozconfig to use; default in the script is used if omitted 23 Optional("mozconfig"): str, 24 # The set of secret names to which the task has access; these are prefixed 25 # with `project/releng/gecko/{treeherder.kind}/level-{level}/`. Setting 26 # this will enable any worker features required and set the task's scopes 27 # appropriately. `true` here means ['*'], all secrets. Not supported on 28 # Windows 29 Optional("secrets"): Any(bool, [str]), 30 # Base work directory used to set up the task. 31 Optional("workdir"): str, 32 }) 33 34 35 @run_job_using("docker-worker", "hazard", schema=haz_run_schema) 36 def docker_worker_hazard(config, job, taskdesc): 37 run = job["run"] 38 39 worker = taskdesc["worker"] = job["worker"] 40 worker.setdefault("artifacts", []) 41 42 docker_worker_add_artifacts(config, job, taskdesc) 43 worker.setdefault("required-volumes", []).append( 44 "{workdir}/workspace".format(**run) 45 ) 46 add_tooltool(config, job, taskdesc) 47 setup_secrets(config, job, taskdesc) 48 49 env = worker["env"] 50 env.update({ 51 "MOZ_BUILD_DATE": config.params["moz_build_date"], 52 "MOZ_SCM_LEVEL": config.params["level"], 53 }) 54 55 # script parameters 56 if run.get("mozconfig"): 57 env["MOZCONFIG"] = run.pop("mozconfig") 58 59 run["using"] = "run-task" 60 run["cwd"] = run["workdir"] 61 configure_taskdesc_for_run(config, job, taskdesc, worker["implementation"])