gcb: Upload build to test bucket. (#450)

This commit is contained in:
Oliver Chang 2017-03-10 22:23:44 -08:00 committed by GitHub
parent f11c245ec1
commit adcf1d8b0c
3 changed files with 63 additions and 6 deletions

View File

@ -5,14 +5,19 @@
Usage: build.py <project_dir> Usage: build.py <project_dir>
""" """
import base64
import datetime import datetime
import os import os
import subprocess
import sys import sys
import time
import urllib
import yaml import yaml
from google.cloud import logging from google.cloud import logging
from google.cloud import pubsub from google.cloud import pubsub
from oauth2client.client import GoogleCredentials from oauth2client.client import GoogleCredentials
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build from googleapiclient.discovery import build
@ -23,6 +28,7 @@ CONFIGURATIONS = {
} }
DEFAULT_SANITIZERS = ['address', 'undefined'] DEFAULT_SANITIZERS = ['address', 'undefined']
UPLOAD_BUCKET = 'clusterfuzz-builds-test'
def usage(): def usage():
@ -75,6 +81,25 @@ def create_sink(log_topic, build_id):
return sink return sink
def get_signed_url(path):
timestamp = int(time.time() + 60 * 60 * 5)
blob = 'PUT\n\n\n{0}\n{1}'.format(
timestamp, path)
creds = ServiceAccountCredentials.from_json_keyfile_name(
os.environ['GOOGLE_APPLICATION_CREDENTIALS'])
client_id = creds.service_account_email
signature = base64.b64encode(creds.sign_blob(blob)[1])
values = {
'GoogleAccessId': client_id,
'Expires': timestamp,
'Signature': signature,
}
return ('https://storage.googleapis.com{0}?'.format(path) +
urllib.urlencode(values))
def get_build_steps(project_yaml): def get_build_steps(project_yaml):
name = project_yaml['name'] name = project_yaml['name']
image = project_yaml['image'] image = project_yaml['image']
@ -106,7 +131,13 @@ def get_build_steps(project_yaml):
for sanitizer in project_yaml['sanitizers']: for sanitizer in project_yaml['sanitizers']:
env = CONFIGURATIONS["sanitizer-" + sanitizer] env = CONFIGURATIONS["sanitizer-" + sanitizer]
out = '/workspace/out/' + sanitizer out = '/workspace/out/' + sanitizer
zip_file = name + "-" + sanitizer + "-" + ts + ".zip" stamped_name = name + '-' + sanitizer + '-' + ts
zip_file = stamped_name + '.zip'
stamped_srcmap_file = stamped_name + '.srcmap.json'
upload_url = get_signed_url('/{0}/{1}/{2}'.format(
UPLOAD_BUCKET, name, zip_file))
srcmap_url = get_signed_url('/{0}/{1}/{2}'.format(
UPLOAD_BUCKET, name, stamped_srcmap_file))
build_steps.extend([ build_steps.extend([
{'name': image, {'name': image,
@ -123,7 +154,27 @@ def get_build_steps(project_yaml):
'-c', '-c',
'cd {0} && zip -r {1} *'.format(out, zip_file) 'cd {0} && zip -r {1} *'.format(out, zip_file)
], ],
}]) },
{'name': 'gcr.io/clusterfuzz-external/uploader',
'args': [
os.path.join(out, zip_file),
upload_url,
],
},
{'name': 'gcr.io/clusterfuzz-external/uploader',
'args': [
'/workspace/srcmap.json',
srcmap_url,
],
},
{'name': image,
'args': [
'bash',
'-c',
'rm -r ' + out,
],
},
])
return build_steps return build_steps

View File

@ -2,4 +2,3 @@ google-api-python-client
PyYAML PyYAML
google-cloud-pubsub google-cloud-pubsub
google-cloud-logging google-cloud-logging

View File

@ -0,0 +1,7 @@
from ubuntu:16.04
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y curl
ENTRYPOINT ["curl", "-X", "PUT", "-T"]