Bug 1296397 - Move VCS task setup functionality to standalone function; r=dustin
authorGregory Szorc <gps@mozilla.com>
Tue, 13 Sep 2016 13:56:46 -0700
changeset 355184 ab5198e198b5f33ef8f2bb1bea3eb1d3dde677e8
parent 355183 33de74be048e90b1ba1ca5ca8703d5ce176827c2
child 355185 4b447ca3c1ae7a6db6483c19120d5f2e0d00e7fc
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdustin
bugs1296397
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1296397 - Move VCS task setup functionality to standalone function; r=dustin Tasks that aren't using run-task may want to configure a task for optimal VCS setup. Also, having all the code in the same place makes it easier to keep track of. MozReview-Commit-ID: GkB2YEUIQiX
taskcluster/taskgraph/transforms/job/common.py
taskcluster/taskgraph/transforms/job/run_task.py
--- a/taskcluster/taskgraph/transforms/job/common.py
+++ b/taskcluster/taskgraph/transforms/job/common.py
@@ -52,16 +52,48 @@ def docker_worker_add_gecko_vcs_env_vars
     env.update({
         'GECKO_BASE_REPOSITORY': config.params['base_repository'],
         'GECKO_HEAD_REF': config.params['head_rev'],
         'GECKO_HEAD_REPOSITORY': config.params['head_repository'],
         'GECKO_HEAD_REV': config.params['head_rev'],
     })
 
 
+def docker_worker_support_vcs_checkout(config, job, taskdesc):
+    """Update a job/task with parameters to enable a VCS checkout.
+
+    The configuration is intended for tasks using "run-task" and its
+    VCS checkout behavior.
+    """
+    level = config.params['level']
+
+    taskdesc['worker'].setdefault('caches', []).extend([
+        {
+            'type': 'persistent',
+            'name': 'level-%s-hg-shared' % level,
+            'mount-point': '/home/worker/hg-shared',
+        }, {
+            'type': 'persistent',
+            'name': 'level-%s-checkouts' % level,
+            'mount-point': '/home/worker/checkouts',
+        }
+    ])
+
+    taskdesc['worker'].setdefault('env', {}).update({
+        'GECKO_BASE_REPOSITORY': config.params['base_repository'],
+        'GECKO_HEAD_REPOSITORY': config.params['head_repository'],
+        'GECKO_HEAD_REV': config.params['head_rev'],
+    })
+
+    # Give task access to hgfingerprint secret so it can pin the certificate
+    # for hg.mozilla.org.
+    taskdesc['scopes'].append('secrets:get:project/taskcluster/gecko/hgfingerprint')
+    taskdesc['worker']['taskcluster-proxy'] = True
+
+
 def docker_worker_setup_secrets(config, job, taskdesc):
     """Set up access to secrets via taskcluster-proxy.  The value of
     run['secrets'] should be a boolean or a list of secret names that
     can be accessed."""
     if not job['run'].get('secrets'):
         return
 
     taskdesc['worker']['taskcluster-proxy'] = True
--- a/taskcluster/taskgraph/transforms/job/run_task.py
+++ b/taskcluster/taskgraph/transforms/job/run_task.py
@@ -5,16 +5,19 @@
 Support for running jobs that are invoked via the `run-task` script.
 """
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import copy
 
 from taskgraph.transforms.job import run_job_using
+from taskgraph.transforms.job.common import (
+    docker_worker_support_vcs_checkout,
+)
 from voluptuous import Schema, Required, Any
 
 run_task_schema = Schema({
     Required('using'): 'run-task',
 
     # if true, add a cache at ~worker/.cache, which is where things like pip
     # tend to hide their caches.  This cache is never added for level-1 jobs.
     Required('cache-dotcache', default=False): bool,
@@ -27,51 +30,30 @@ run_task_schema = Schema({
     # it will be included in a single argument to `bash -cx`.
     Required('command'): Any([basestring], basestring),
 })
 
 
 @run_job_using("docker-worker", "run-task", schema=run_task_schema)
 def docker_worker_run_task(config, job, taskdesc):
     run = job['run']
-    checkout = run['checkout']
 
     worker = taskdesc['worker'] = copy.deepcopy(job['worker'])
 
-    if checkout:
-        worker['caches'] = [{
-            'type': 'persistent',
-            'name': 'level-{}-hg-shared'.format(config.params['level']),
-            'mount-point': "/home/worker/hg-shared",
-        }, {
-            'type': 'persistent',
-            'name': 'level-{}-checkouts'.format(config.params['level']),
-            'mount-point': "/home/worker/checkouts",
-        }]
+    if run['checkout']:
+        docker_worker_support_vcs_checkout(config, job, taskdesc)
 
     if run.get('cache-dotcache') and int(config.params['level']) > 1:
         worker['caches'].append({
             'type': 'persistent',
             'name': 'level-{level}-{project}-dotcache'.format(**config.params),
             'mount-point': '/home/worker/.cache',
         })
 
-    env = worker['env'] = {}
-    env.update({
-        'GECKO_BASE_REPOSITORY': config.params['base_repository'],
-        'GECKO_HEAD_REPOSITORY': config.params['head_repository'],
-        'GECKO_HEAD_REV': config.params['head_rev'],
-    })
-
-    # give the task access to the hgfingerprint secret
-    if checkout:
-        taskdesc['scopes'].append('secrets:get:project/taskcluster/gecko/hgfingerprint')
-        worker['taskcluster-proxy'] = True
-
     run_command = run['command']
     if isinstance(run_command, basestring):
         run_command = ['bash', '-cx', run_command]
     command = ['/home/worker/bin/run-task']
-    if checkout:
+    if run['checkout']:
         command.append('--vcs-checkout=/home/worker/checkouts/gecko')
     command.append('--')
     command.extend(run_command)
     worker['command'] = command