• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2
2"""Build base images on Google Cloud Builder.
3
4Usage: build_base_images.py
5"""
6
7import os
8import sys
9import yaml
10
11from oauth2client.client import GoogleCredentials
12from googleapiclient.discovery import build
13
14BASE_IMAGES = [
15    'base-image',
16    'base-clang',
17    'base-builder',
18    'base-runner',
19    'base-runner-debug',
20    'base-msan-builder',
21]
22
23TAG_PREFIX = 'gcr.io/oss-fuzz-base/'
24
25
26def get_steps(images):
27  steps = [{
28      'args': [
29          'clone',
30          'https://github.com/google/oss-fuzz.git',
31      ],
32      'name': 'gcr.io/cloud-builders/git',
33  }]
34
35  for base_image in images:
36    steps.append({
37        'args': [
38            'build',
39            '-t',
40            TAG_PREFIX + base_image,
41            '.',
42        ],
43        'dir': 'oss-fuzz/infra/base-images/' + base_image,
44        'name': 'gcr.io/cloud-builders/docker',
45    })
46
47  return steps
48
49
50def get_logs_url(build_id):
51  URL_FORMAT = ('https://console.developers.google.com/logs/viewer?'
52                'resource=build%2Fbuild_id%2F{0}&project=oss-fuzz-base')
53  return URL_FORMAT.format(build_id)
54
55
56def main():
57  options = {}
58  if 'GCB_OPTIONS' in os.environ:
59    options = yaml.safe_load(os.environ['GCB_OPTIONS'])
60
61  build_body = {
62      'steps': get_steps(BASE_IMAGES),
63      'timeout': str(4 * 3600) + 's',
64      'options': options,
65      'images': [TAG_PREFIX + base_image for base_image in BASE_IMAGES],
66  }
67
68  credentials = GoogleCredentials.get_application_default()
69  cloudbuild = build('cloudbuild', 'v1', credentials=credentials)
70  build_info = cloudbuild.projects().builds().create(
71      projectId='oss-fuzz-base', body=build_body).execute()
72  build_id = build_info['metadata']['build']['id']
73
74  print >> sys.stderr, 'Logs:', get_logs_url(build_id)
75  print build_id
76
77
78if __name__ == '__main__':
79  main()
80