From 17e2f96e6a47fff34092da4041da5d57f35be8cb Mon Sep 17 00:00:00 2001 From: jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com> Date: Thu, 19 Aug 2021 20:05:32 -0700 Subject: [infra] Add a script for building all base-images with "-testing" (#6248) suffix and pushing them to gcr.io/oss-fuzz-base. This is useful for testing changes to images. I used it to test changes I made for #6180. This does not support msan as that image is being removed. Also lint. --- infra/build_and_push_test_images.py | 84 +++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 infra/build_and_push_test_images.py (limited to 'infra/build_and_push_test_images.py') diff --git a/infra/build_and_push_test_images.py b/infra/build_and_push_test_images.py new file mode 100644 index 000000000..89fd6b65c --- /dev/null +++ b/infra/build_and_push_test_images.py @@ -0,0 +1,84 @@ +# Copyright 2021 Google LLC +# +# 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. +# +################################################################################ +"""Script for building and pushing base-images to gcr.io/oss-fuzz-base/ with +"-test" suffix. This is useful for reusing the build infra to test image +changes.""" +import logging +import multiprocessing +import os +import subprocess + +TAG_PREFIX = 'gcr.io/oss-fuzz-base/' +TESTING_TAG_SUFFIX = '-testing' +INFRA_DIR = os.path.dirname(__file__) +IMAGES_DIR = os.path.join(INFRA_DIR, 'base-images') + + +def push_image(tag): + """Pushes image with |tag| to docker registry.""" + logging.info('Pushing: %s', tag) + command = ['docker', 'push', tag] + subprocess.run(command, check=True) + logging.info('Pushed: %s', tag) + + +def build_and_push_image(image): + """Builds and pushes |image| to docker registry with "-testing" suffix.""" + main_tag = TAG_PREFIX + image + testing_tag = main_tag + TESTING_TAG_SUFFIX + tags = [main_tag, testing_tag] + build_image(image, tags) + push_image(testing_tag) + + +def build_image(image, tags): + """Builds |image| and tags it with |tags|.""" + logging.info('Building: %s', image) + command = ['docker', 'build'] + for tag in tags: + command.extend(['--tag', tag]) + path = os.path.join(IMAGES_DIR, image) + command.append(path) + subprocess.run(command, check=True) + logging.info('Built: %s', image) + + +def build_and_push_images(): + """Builds and pushes base-images.""" + images = [ + ['base-image'], + ['base-clang', 'base-runner'], + ['base-builder', 'base-runner-debug', 'base-builder-new'], + ['base-runner-debug', 'base-sanitizer-build-libs', 'base-builder-swift'], + ] + max_parallelization = max([len(image_list) for image_list in images]) + proc_count = min(multiprocessing.cpu_count(), max_parallelization) + pool = multiprocessing.Pool(proc_count) + for image_list in images: + pool.map(build_and_push_image, image_list) + + +def main(): + """"Builds base-images tags them with "-testing" suffix (in addition to normal + tag) and pushes "-testing" suffixed images to docker registry.""" + logging.basicConfig(level=logging.DEBUG) + logging.info('Doing simple gcloud command to ensure 2FA passes.') + subprocess.run(['gcloud', 'projects', 'list', '--limit=1'], check=True) + build_and_push_images() + + +if __name__ == '__main__': + main() -- cgit v1.2.3 From a3f8ac1403e7332a70ae9a7978d82cd7b908187d Mon Sep 17 00:00:00 2001 From: jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com> Date: Sun, 22 Aug 2021 17:18:11 -0700 Subject: Fix coverage command and misc fixes (#6262) --- infra/build_and_push_test_images.py | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 infra/build_and_push_test_images.py (limited to 'infra/build_and_push_test_images.py') diff --git a/infra/build_and_push_test_images.py b/infra/build_and_push_test_images.py old mode 100644 new mode 100755 index 89fd6b65c..df1f647e6 --- a/infra/build_and_push_test_images.py +++ b/infra/build_and_push_test_images.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # Copyright 2021 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); -- cgit v1.2.3 From 2e3962d122040c32a196b3096a8ac4234363d805 Mon Sep 17 00:00:00 2001 From: jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com> Date: Tue, 31 Aug 2021 08:32:11 -0700 Subject: [languages] Handle language builders in cifuzz and build_and_push_test_images. (#6359) --- infra/build_and_push_test_images.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'infra/build_and_push_test_images.py') diff --git a/infra/build_and_push_test_images.py b/infra/build_and_push_test_images.py index df1f647e6..2b81b7c8f 100755 --- a/infra/build_and_push_test_images.py +++ b/infra/build_and_push_test_images.py @@ -63,7 +63,11 @@ def build_and_push_images(): ['base-image'], ['base-clang', 'base-runner'], ['base-builder', 'base-runner-debug', 'base-builder-new'], - ['base-runner-debug', 'base-sanitizer-build-libs', 'base-builder-swift'], + [ + 'base-runner-debug', 'base-sanitizer-build-libs', 'base-builder-go', + 'base-builder-jvm', 'base-builder-python', 'base-builder-rust', + 'base-builder-swift' + ], ] max_parallelization = max([len(image_list) for image_list in images]) proc_count = min(multiprocessing.cpu_count(), max_parallelization) -- cgit v1.2.3 From 5ef1f7b5881fa86c663b18216594971bd0b3c969 Mon Sep 17 00:00:00 2001 From: jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com> Date: Wed, 1 Sep 2021 13:36:17 -0700 Subject: [language builders] Get rid of base-builder-new (#6361) Build all C/C++ projects in an image without rust, java, atheris (python), or go. --- infra/build_and_push_test_images.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'infra/build_and_push_test_images.py') diff --git a/infra/build_and_push_test_images.py b/infra/build_and_push_test_images.py index 2b81b7c8f..44c65ae2c 100755 --- a/infra/build_and_push_test_images.py +++ b/infra/build_and_push_test_images.py @@ -21,9 +21,9 @@ import logging import multiprocessing import os import subprocess +import sys TAG_PREFIX = 'gcr.io/oss-fuzz-base/' -TESTING_TAG_SUFFIX = '-testing' INFRA_DIR = os.path.dirname(__file__) IMAGES_DIR = os.path.join(INFRA_DIR, 'base-images') @@ -36,10 +36,10 @@ def push_image(tag): logging.info('Pushed: %s', tag) -def build_and_push_image(image): +def build_and_push_image(image, test_image_suffix): """Builds and pushes |image| to docker registry with "-testing" suffix.""" main_tag = TAG_PREFIX + image - testing_tag = main_tag + TESTING_TAG_SUFFIX + testing_tag = main_tag + '-' + test_image_suffix tags = [main_tag, testing_tag] build_image(image, tags) push_image(testing_tag) @@ -57,32 +57,35 @@ def build_image(image, tags): logging.info('Built: %s', image) -def build_and_push_images(): +def build_and_push_images(test_image_suffix): """Builds and pushes base-images.""" images = [ ['base-image'], - ['base-clang', 'base-runner'], - ['base-builder', 'base-runner-debug', 'base-builder-new'], + ['base-clang'], + # base-runner is also dependent on base-clang. + ['base-builder', 'base-runner'], [ - 'base-runner-debug', 'base-sanitizer-build-libs', 'base-builder-go', - 'base-builder-jvm', 'base-builder-python', 'base-builder-rust', - 'base-builder-swift' + 'base-runner-debug', 'base-builder-go', 'base-builder-jvm', + 'base-builder-python', 'base-builder-rust', 'base-builder-swift' ], ] max_parallelization = max([len(image_list) for image_list in images]) proc_count = min(multiprocessing.cpu_count(), max_parallelization) + logging.info('Using %d parallel processes.', proc_count) pool = multiprocessing.Pool(proc_count) for image_list in images: - pool.map(build_and_push_image, image_list) + args_list = [(image, test_image_suffix) for image in image_list] + pool.starmap(build_and_push_image, args_list) def main(): """"Builds base-images tags them with "-testing" suffix (in addition to normal - tag) and pushes "-testing" suffixed images to docker registry.""" + tag) and pushes testing suffixed images to docker registry.""" + test_image_suffix = sys.argv[1] logging.basicConfig(level=logging.DEBUG) logging.info('Doing simple gcloud command to ensure 2FA passes.') subprocess.run(['gcloud', 'projects', 'list', '--limit=1'], check=True) - build_and_push_images() + build_and_push_images(test_image_suffix) if __name__ == '__main__': -- cgit v1.2.3