2020-07-08 04:16:01 +00:00
|
|
|
# Copyright 2020 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""Cloud function to build base images on Google Cloud Builder."""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import google.auth
|
2022-04-04 21:47:21 +00:00
|
|
|
|
|
|
|
import build_lib
|
2020-07-08 04:16:01 +00:00
|
|
|
|
2020-08-05 23:36:47 +00:00
|
|
|
BASE_IMAGES = [
|
|
|
|
'base-image',
|
|
|
|
'base-clang',
|
|
|
|
'base-builder',
|
2021-08-30 13:57:23 +00:00
|
|
|
'base-builder-go',
|
2022-01-31 00:47:36 +00:00
|
|
|
'base-builder-go-codeintelligencetesting',
|
2021-08-30 13:51:24 +00:00
|
|
|
'base-builder-jvm',
|
2021-08-30 18:47:04 +00:00
|
|
|
'base-builder-python',
|
|
|
|
'base-builder-rust',
|
2021-08-19 23:52:44 +00:00
|
|
|
'base-builder-swift',
|
2020-08-05 23:36:47 +00:00
|
|
|
'base-runner',
|
|
|
|
'base-runner-debug',
|
|
|
|
]
|
2022-01-20 01:22:50 +00:00
|
|
|
INTROSPECTOR_BASE_IMAGES = ['base-clang', 'base-builder']
|
2020-07-29 02:39:49 +00:00
|
|
|
BASE_PROJECT = 'oss-fuzz-base'
|
2020-08-05 23:36:47 +00:00
|
|
|
TAG_PREFIX = f'gcr.io/{BASE_PROJECT}/'
|
2022-01-20 01:22:50 +00:00
|
|
|
MAJOR_TAG = 'v1'
|
|
|
|
INTROSPECTOR_TAG = 'introspector'
|
2022-04-04 21:47:21 +00:00
|
|
|
TIMEOUT = str(6 * 60 * 60)
|
2020-08-05 23:36:47 +00:00
|
|
|
|
|
|
|
|
2022-04-04 21:47:21 +00:00
|
|
|
def get_base_image_steps(images, tag_prefix=TAG_PREFIX):
|
2020-08-05 23:36:47 +00:00
|
|
|
"""Returns build steps for given images."""
|
2022-04-04 21:47:21 +00:00
|
|
|
steps = [build_lib.get_git_clone_step()]
|
2020-08-05 23:36:47 +00:00
|
|
|
|
|
|
|
for base_image in images:
|
2021-09-16 01:12:25 +00:00
|
|
|
image = tag_prefix + base_image
|
2022-04-04 21:47:21 +00:00
|
|
|
tagged_image = image + ':' + MAJOR_TAG
|
|
|
|
steps.append(
|
|
|
|
build_lib.get_docker_build_step([image, tagged_image],
|
|
|
|
'infra/base-images/' + base_image))
|
2020-08-05 23:36:47 +00:00
|
|
|
return steps
|
|
|
|
|
|
|
|
|
2022-01-20 01:22:50 +00:00
|
|
|
def _get_introspector_base_images_steps(images, tag_prefix=TAG_PREFIX):
|
|
|
|
"""Returns build steps for given images version of introspector"""
|
|
|
|
steps = [{
|
2022-01-21 01:12:16 +00:00
|
|
|
'args': [
|
|
|
|
'clone',
|
|
|
|
'https://github.com/google/oss-fuzz.git',
|
|
|
|
],
|
|
|
|
'name': 'gcr.io/cloud-builders/git',
|
2022-03-23 05:12:19 +00:00
|
|
|
}, {
|
|
|
|
'name': 'gcr.io/cloud-builders/docker',
|
|
|
|
'args': ['pull', 'gcr.io/oss-fuzz-base/base-clang:introspector'],
|
|
|
|
}, {
|
2022-01-20 01:22:50 +00:00
|
|
|
'name':
|
2022-03-23 05:12:19 +00:00
|
|
|
'gcr.io/cloud-builders/docker',
|
2022-01-20 01:22:50 +00:00
|
|
|
'args': [
|
2022-03-23 05:12:19 +00:00
|
|
|
'tag', 'gcr.io/oss-fuzz-base/base-clang:introspector',
|
|
|
|
'gcr.io/oss-fuzz-base/base-clang:latest'
|
|
|
|
],
|
|
|
|
}]
|
2022-01-20 01:22:50 +00:00
|
|
|
|
|
|
|
for base_image in images:
|
|
|
|
image = tag_prefix + base_image
|
|
|
|
args_list = ['build']
|
|
|
|
|
|
|
|
if base_image == 'base-clang':
|
|
|
|
args_list.extend(['--build-arg', 'introspector=1'])
|
|
|
|
|
|
|
|
args_list.extend([
|
|
|
|
'-t',
|
|
|
|
f'{image}:{INTROSPECTOR_TAG}',
|
|
|
|
'.',
|
|
|
|
])
|
|
|
|
steps.append({
|
|
|
|
'args': args_list,
|
|
|
|
'dir': 'oss-fuzz/infra/base-images/' + base_image,
|
|
|
|
'name': 'gcr.io/cloud-builders/docker',
|
|
|
|
})
|
|
|
|
|
|
|
|
return steps
|
|
|
|
|
|
|
|
|
2020-07-08 04:16:01 +00:00
|
|
|
# pylint: disable=no-member
|
2022-04-04 21:47:21 +00:00
|
|
|
def run_build(steps, images, tags=None, build_version=MAJOR_TAG):
|
|
|
|
"""Execute the retrieved build steps in gcb."""
|
2020-07-29 02:39:49 +00:00
|
|
|
credentials, _ = google.auth.default()
|
2022-04-04 21:47:21 +00:00
|
|
|
body_overrides = {
|
2022-01-20 01:22:50 +00:00
|
|
|
'images': images + [f'{image}:{build_version}' for image in images]
|
2020-07-08 04:16:01 +00:00
|
|
|
}
|
2022-04-04 21:47:21 +00:00
|
|
|
return build_lib.run_build(steps, credentials, BASE_PROJECT, body_overrides,
|
|
|
|
tags)
|
2020-07-31 04:42:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def base_builder(event, context):
|
|
|
|
"""Cloud function to build base images."""
|
|
|
|
del event, context
|
2022-04-04 21:47:21 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
2020-07-31 04:42:09 +00:00
|
|
|
|
2022-04-04 21:47:21 +00:00
|
|
|
steps = get_base_image_steps(BASE_IMAGES)
|
|
|
|
images = [TAG_PREFIX + base_image for base_image in BASE_IMAGES]
|
2020-07-31 04:42:09 +00:00
|
|
|
run_build(steps, images)
|
2022-01-20 01:22:50 +00:00
|
|
|
|
|
|
|
introspector_steps = _get_introspector_base_images_steps(
|
2022-04-04 21:47:21 +00:00
|
|
|
INTROSPECTOR_BASE_IMAGES)
|
2022-01-20 01:22:50 +00:00
|
|
|
introspector_images = [
|
2022-04-04 21:47:21 +00:00
|
|
|
TAG_PREFIX + base_image for base_image in INTROSPECTOR_BASE_IMAGES
|
2022-01-20 01:22:50 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
run_build(introspector_steps, introspector_images, INTROSPECTOR_TAG)
|