Esempio n. 1
0
import json
import os
import slugid
import taskcluster
import urllib.request
from cib import createTask, updateWorkerPool


workerManager = taskcluster.WorkerManager(taskcluster.optionsFromEnvironment())
queue = taskcluster.Queue(taskcluster.optionsFromEnvironment())
commit = json.loads(urllib.request.urlopen(urllib.request.Request('https://api.github.com/repos/mozilla-platform-ops/cloud-image-builder/commits/{}'.format(os.getenv('TRAVIS_COMMIT')), None, { 'User-Agent' : 'Mozilla/5.0' })).read().decode())['commit']

updateWorkerPool(
  workerManager = workerManager,
  configPath = 'ci/config/worker-pool/relops/decision.yaml',
  workerPoolId = 'relops/decision')
updateWorkerPool(
  workerManager = workerManager,
  configPath = 'ci/config/worker-pool/relops/win2019.yaml',
  workerPoolId = 'relops/win2019')

createTask(
  queue = queue,
  image = 'python',
  taskId = slugid.nice(),
  taskName = '00 :: decision task',
  taskDescription = 'determine which windows cloud images should be built, where they should be deployed and trigger appropriate build tasks for the same',
  provisioner = 'relops',
  workerType = 'decision',
  features = {
    'taskclusterProxy': True
        '0000-00-00 00:00', '<task-id>',
        '{}/tasks/index/project.relops.cloud-image-builder.{}.{}/latest/'
    ).format(os.getenv('TASKCLUSTER_PROXY_URL'), platform, key),
    '- machine image builds:', '\n'.join(machineImageBuildsDescription),
    '- applied occ revision: [{}]({})'.format(
        occRevision[0:7],
        'https://github.com/mozilla-releng/OpenCloudConfig/commit/{}'.format(
            occRevision)), '#### deployment', '- platform: **{} ({})**'.format(
                platform, ', '.join(poolConfig['locations'])),
    '- last worker pool update: {} [{}]({})'.format(
        '{}'.format(datetime.utcnow().isoformat()[:-10].replace('T', ' ')),
        os.getenv('TASK_ID'),
        '{}/tasks/{}#artifacts'.format(os.getenv('TASKCLUSTER_PROXY_URL'),
                                       os.getenv('TASK_ID')))
]

providerConfig = {
    'description': '\n'.join(description),
    'owner': poolConfig['owner'],
    'emailOnError': True,
    'providerId': poolConfig['provider'],
    'config': workerPool
}
configPath = '../{}.yaml'.format(poolName.replace('/', '-'))
with open(configPath, 'w') as file:
    print('saving: {}'.format(configPath))
    yaml.dump(providerConfig, file, default_flow_style=False)
    updateWorkerPool(workerManager=taskclusterWorkerManagerClient,
                     configPath=configPath,
                     workerPoolId='{}'.format(poolName))
Esempio n. 3
0
if any(line.lower().strip() == 'no-ci' or line.lower().strip() == 'no-travis-ci' for line in lines):
  print('info: **no ci** commit syntax detected. skipping pool and role checks')
  quit()

if any(line.lower().startswith('include environments:') for line in lines):
  includeEnvironments = list(map(lambda x: x.lower().strip(), next(line for line in lines if line.startswith('include environments:')).replace('include environments:', '').split(',')))
  print('info: **include environments** commit syntax detected. ci will process environments: {}'.format(', '.join(includeEnvironments)))
elif any(line.lower().startswith('exclude environments:') for line in lines):
  includeEnvironments = list(filter(lambda x: x not in map(lambda x: x.lower().strip(), next(line for line in lines if line.lower().startswith('exclude environments:')).replace('exclude environments:', '').split(',')), includeEnvironments))
  print('info: **exclude environments** commit syntax detected. ci will process environments: {}'.format(', '.join(includeEnvironments)))
if currentEnvironment not in includeEnvironments:
  print('info: current environment ({}) is excluded. skipping pool and role checks'.format(currentEnvironment))
  quit()


taskclusterAuth = taskcluster.Auth(taskcluster.optionsFromEnvironment())
taskclusterWorkerManager = taskcluster.WorkerManager(taskcluster.optionsFromEnvironment())

updateRole(
  auth = taskclusterAuth,
  configPath = 'ci/config/role/branch-master.yaml',
  roleId = 'repo:github.com/mozilla-platform-ops/cloud-image-builder:branch:master')
updateWorkerPool(
  workerManager = taskclusterWorkerManager,
  configPath = 'ci/config/worker-pool/{}/relops-decision.yaml'.format(currentEnvironment),
  workerPoolId = 'relops/decision')
updateWorkerPool(
  workerManager = taskclusterWorkerManager,
  configPath = 'ci/config/worker-pool/{}/relops-win2019.yaml'.format(currentEnvironment),
  workerPoolId = 'relops/win2019')