1#!/usr/bin/python2 2"""Build base images on Google Cloud Builder. 3 4Usage: build_base_images.py 5""" 6 7import datetime 8import os 9import yaml 10import sys 11 12from oauth2client.client import GoogleCredentials 13from googleapiclient.discovery import build 14 15import build_base_images 16 17 18def main(): 19 options = {} 20 if 'GCB_OPTIONS' in os.environ: 21 options = yaml.safe_load(os.environ['GCB_OPTIONS']) 22 23 image = 'gcr.io/oss-fuzz-base/msan-builder' 24 steps = build_base_images.get_steps(['base-msan-builder', 'msan-builder']) 25 ts = datetime.datetime.utcnow().strftime('%Y%m%d%H%M') 26 upload_name = 'msan-libs-' + ts + '.zip' 27 28 steps.extend([{ 29 'name': image, 30 'args': [ 31 'bash', 32 '-c', 33 'cd /msan && zip -r /workspace/libs.zip .', 34 ], 35 }, { 36 'name': 37 'gcr.io/cloud-builders/gsutil', 38 'args': [ 39 'cp', 40 '/workspace/libs.zip', 41 'gs://oss-fuzz-msan-libs/' + upload_name, 42 ], 43 }]) 44 45 build_body = { 46 'steps': steps, 47 'timeout': str(6 * 3600) + 's', 48 'options': options, 49 'images': [ 50 'gcr.io/oss-fuzz-base/base-msan-builder', 51 image, 52 ], 53 } 54 55 credentials = GoogleCredentials.get_application_default() 56 cloudbuild = build('cloudbuild', 'v1', credentials=credentials) 57 build_info = cloudbuild.projects().builds().create( 58 projectId='oss-fuzz-base', body=build_body).execute() 59 build_id = build_info['metadata']['build']['id'] 60 61 print >> sys.stderr, 'Logs:', build_base_images.get_logs_url(build_id) 62 print build_id 63 64 65if __name__ == '__main__': 66 main() 67