oss-fuzz/infra/gcb/build_base_images.py

80 lines
1.8 KiB
Python
Raw Normal View History

2017-03-11 06:44:08 +00:00
#!/usr/bin/python2
"""Build base images on Google Cloud Builder.
Usage: build_base_images.py
"""
import os
import sys
2017-03-11 06:44:08 +00:00
import yaml
from oauth2client.client import GoogleCredentials
from googleapiclient.discovery import build
BASE_IMAGES = [
'base-image',
'base-clang',
'base-builder',
'base-runner',
'base-runner-debug',
'base-msan-builder',
2017-03-11 06:44:08 +00:00
]
TAG_PREFIX = 'gcr.io/oss-fuzz-base/'
2017-03-11 06:44:08 +00:00
2017-12-07 02:20:01 +00:00
def get_steps(images):
steps = [{
'args': [
2018-07-27 03:32:09 +00:00
'clone',
'https://github.com/google/oss-fuzz.git',
],
'name': 'gcr.io/cloud-builders/git',
}]
2017-03-11 06:44:08 +00:00
2017-12-07 03:04:07 +00:00
for base_image in images:
2017-03-11 06:44:08 +00:00
steps.append({
'args': [
'build',
'-t',
TAG_PREFIX + base_image,
'.',
],
'dir': 'oss-fuzz/infra/base-images/' + base_image,
2017-03-11 06:44:08 +00:00
'name': 'gcr.io/cloud-builders/docker',
})
return steps
def get_logs_url(build_id):
URL_FORMAT = ('https://console.developers.google.com/logs/viewer?'
'resource=build%2Fbuild_id%2F{0}&project=oss-fuzz-base')
return URL_FORMAT.format(build_id)
2017-03-11 06:44:08 +00:00
def main():
options = {}
2018-07-27 03:32:09 +00:00
if 'GCB_OPTIONS' in os.environ:
options = yaml.safe_load(os.environ['GCB_OPTIONS'])
2017-03-11 06:44:08 +00:00
build_body = {
2017-12-07 02:20:01 +00:00
'steps': get_steps(BASE_IMAGES),
2017-03-11 06:44:08 +00:00
'timeout': str(4 * 3600) + 's',
'options': options,
2018-07-27 03:32:09 +00:00
'images': [TAG_PREFIX + base_image for base_image in BASE_IMAGES],
2017-03-11 06:44:08 +00:00
}
credentials = GoogleCredentials.get_application_default()
cloudbuild = build('cloudbuild', 'v1', credentials=credentials)
2018-07-27 03:32:09 +00:00
build_info = cloudbuild.projects().builds().create(
projectId='oss-fuzz-base', body=build_body).execute()
build_id = build_info['metadata']['build']['id']
2017-03-11 06:44:08 +00:00
print >> sys.stderr, 'Logs:', get_logs_url(build_id)
2017-03-11 06:44:08 +00:00
print build_id
2018-07-27 03:32:09 +00:00
if __name__ == '__main__':
2017-03-11 06:44:08 +00:00
main()