def build_base_images(): """Build base images on GCB.""" buildable_images = _get_buildable_images() image_templates = { image: buildable_images[image] for image in ['base-image', 'worker'] } config = generate_cloudbuild.create_cloudbuild_spec(image_templates, build_base_images=True) _build(config, 'base-images')
def build_coverage(benchmark): """Build coverage image for benchmark on GCB.""" buildable_images = _get_buildable_images(benchmark=benchmark) image_templates = { image_name: image_specs for image_name, image_specs in buildable_images.items() if (image_name == (benchmark + '-project-builder') or image_specs['type'] == 'coverage') } config = generate_cloudbuild.create_cloudbuild_spec(image_templates, benchmark=benchmark) config_name = 'benchmark-{benchmark}-coverage'.format(benchmark=benchmark) _build(config, config_name)
def build_fuzzer_benchmark(fuzzer: str, benchmark: str): """Builds |benchmark| for |fuzzer|.""" image_templates = {} buildable_images = _get_buildable_images(fuzzer=fuzzer, benchmark=benchmark) for image_name, image_specs in buildable_images.items(): if image_specs['type'] in ('base', 'coverage', 'dispatcher'): continue image_templates[image_name] = image_specs config = generate_cloudbuild.create_cloudbuild_spec(image_templates) config_name = 'benchmark-{benchmark}-fuzzer-{fuzzer}'.format( benchmark=benchmark, fuzzer=fuzzer) _build(config, config_name)
def test_generate_cloudbuild_spec_other_registry(experiment): """Tests generation of cloud build configuration yaml for the base image when a registry other than gcr.io/fuzzbench is specified. """ os.environ['DOCKER_REGISTRY'] = 'gcr.io/not-fuzzbench' image_templates = { 'base-image': { 'dockerfile': 'docker/base-image/Dockerfile', 'context': 'docker/base-image', 'tag': 'base-image', 'type': 'base' } } generated_spec = generate_cloudbuild.create_cloudbuild_spec( image_templates, build_base_images=True) expected_spec = { 'steps': [{ 'id': 'pull-ubuntu-xenial', 'env': ['DOCKER_BUILDKIT=1'], 'name': 'docker:19.03.12', 'args': ['pull', 'ubuntu:xenial'] }, { 'id': 'base-image', 'env': ['DOCKER_BUILDKIT=1'], 'name': 'docker:19.03.12', 'args': [ 'build', '--tag', 'gcr.io/not-fuzzbench/base-image' ':test-experiment', '--tag', 'gcr.io/fuzzbench/base-image', '--tag', 'gcr.io/not-fuzzbench/base-image', '--cache-from', 'gcr.io/not-fuzzbench/base-image', '--build-arg', 'BUILDKIT_INLINE_CACHE=1', '--file', 'docker/base-image/Dockerfile', 'docker/base-image' ], 'wait_for': [] }], 'images': [ 'gcr.io/not-fuzzbench/base-image:test-experiment', 'gcr.io/not-fuzzbench/base-image' ] } assert generated_spec == expected_spec
def test_generate_cloudbuild_spec_build_fuzzer_benchmark(experiment): """Tests generation of cloud build configuration yaml for a fuzzer-benchmark build.""" image_templates = { 'afl-zlib-builder-intermediate': { 'build_arg': ['parent_image=gcr.io/fuzzbench/builders/benchmark/zlib'], 'depends_on': ['zlib-project-builder'], 'dockerfile': 'fuzzers/afl/builder.Dockerfile', 'context': 'fuzzers/afl', 'tag': 'builders/afl/zlib-intermediate', 'type': 'builder' } } generated_spec = generate_cloudbuild.create_cloudbuild_spec( image_templates) expected_spec = { 'steps': [{ 'id': 'afl-zlib-builder-intermediate', 'env': ['DOCKER_BUILDKIT=1'], 'name': 'docker:19.03.12', 'args': [ 'build', '--tag', 'gcr.io/fuzzbench/builders/afl/zlib-intermediate' ':test-experiment', '--tag', 'gcr.io/fuzzbench/builders/afl/zlib-intermediate', '--tag', 'gcr.io/fuzzbench/builders/afl/zlib-intermediate', '--cache-from', 'gcr.io/fuzzbench/builders/afl/zlib-intermediate', '--build-arg', 'BUILDKIT_INLINE_CACHE=1', '--build-arg', 'parent_image=gcr.io/fuzzbench/builders/benchmark/zlib', '--file', 'fuzzers/afl/builder.Dockerfile', 'fuzzers/afl' ], 'wait_for': ['zlib-project-builder'] }], 'images': [ 'gcr.io/fuzzbench/builders/afl/zlib-intermediate:test-experiment', 'gcr.io/fuzzbench/builders/afl/zlib-intermediate' ] } assert generated_spec == expected_spec
def test_generate_cloudbuild_spec_build_benchmark_coverage(experiment): """Tests cloud build configuration yaml for a benchmark coverage build.""" image_templates = { 'zlib-project-builder': { 'dockerfile': 'benchmarks/zlib/Dockerfile', 'context': 'benchmarks/zlib', 'tag': 'builders/benchmark/zlib', 'type': 'builder' }, 'coverage-zlib-builder-intermediate': { 'build_arg': ['parent_image=gcr.io/fuzzbench/builders/benchmark/zlib'], 'depends_on': ['zlib-project-builder'], 'dockerfile': 'fuzzers/coverage/builder.Dockerfile', 'context': 'fuzzers/coverage', 'tag': 'builders/coverage/zlib-intermediate', 'type': 'coverage' }, 'coverage-zlib-builder': { 'build_arg': [ 'benchmark=zlib', 'fuzzer=coverage', 'parent_image=gcr.io/fuzzbench/builders/coverage/' 'zlib-intermediate' ], 'depends_on': ['coverage-zlib-builder-intermediate'], 'dockerfile': 'docker/benchmark-builder/Dockerfile', 'context': '.', 'tag': 'builders/coverage/zlib', 'type': 'coverage' } } generated_spec = generate_cloudbuild.create_cloudbuild_spec( image_templates, benchmark='zlib') expected_spec = { 'steps': [{ 'id': 'zlib-project-builder', 'env': ['DOCKER_BUILDKIT=1'], 'name': 'docker:19.03.12', 'args': [ 'build', '--tag', 'gcr.io/fuzzbench/builders/benchmark/zlib', '--tag', 'gcr.io/fuzzbench/builders/benchmark/zlib:test-experiment', '--cache-from', 'gcr.io/fuzzbench/builders/benchmark/zlib', '--build-arg', 'BUILDKIT_INLINE_CACHE=1', '--file', 'benchmarks/zlib/Dockerfile', 'benchmarks/zlib' ], 'wait_for': [] }, { 'id': 'coverage-zlib-builder-intermediate', 'env': ['DOCKER_BUILDKIT=1'], 'name': 'docker:19.03.12', 'args': [ 'build', '--tag', 'gcr.io/fuzzbench/builders/coverage/zlib-intermediate', '--tag', 'gcr.io/fuzzbench/builders/coverage/zlib-intermediate' ':test-experiment', '--cache-from', 'gcr.io/fuzzbench/builders/coverage/zlib-intermediate', '--build-arg', 'BUILDKIT_INLINE_CACHE=1', '--build-arg', 'parent_image=gcr.io/fuzzbench/builders/benchmark/zlib', '--file', 'fuzzers/coverage/builder.Dockerfile', 'fuzzers/coverage' ], 'wait_for': ['zlib-project-builder'] }, { 'id': 'coverage-zlib-builder', 'env': ['DOCKER_BUILDKIT=1'], 'name': 'docker:19.03.12', 'args': [ 'build', '--tag', 'gcr.io/fuzzbench/builders/coverage/zlib', '--tag', 'gcr.io/fuzzbench/builders/coverage/zlib:test-experiment', '--cache-from', 'gcr.io/fuzzbench/builders/coverage/zlib', '--build-arg', 'BUILDKIT_INLINE_CACHE=1', '--build-arg', 'benchmark=zlib', '--build-arg', 'fuzzer=coverage', '--build-arg', 'parent_image=gcr.io/fuzzbench/builders/coverage/' 'zlib-intermediate', '--file', 'docker/benchmark-builder/Dockerfile', '.' ], 'wait_for': ['coverage-zlib-builder-intermediate'] }, { 'name': 'docker:19.03.12', 'args': [ 'run', '-v', '/workspace/out:/host-out', 'gcr.io/fuzzbench/builders/coverage/zlib:test-experiment', '/bin/bash', '-c', 'cd /out; tar -czvf /host-out/coverage-build-zlib.tar.gz * ' '/src /work' ] }, { 'name': 'gcr.io/cloud-builders/gsutil', 'args': [ '-m', 'cp', '/workspace/out/coverage-build-zlib.tar.gz', 'gs://experiment-data/test-experiment/coverage-binaries/' ] }], 'images': [ 'gcr.io/fuzzbench/builders/benchmark/zlib:test-experiment', 'gcr.io/fuzzbench/builders/benchmark/zlib', 'gcr.io/fuzzbench/builders/coverage/zlib-intermediate' ':test-experiment', 'gcr.io/fuzzbench/builders/coverage/zlib-intermediate', 'gcr.io/fuzzbench/builders/coverage/zlib:test-experiment', 'gcr.io/fuzzbench/builders/coverage/zlib' ] } assert generated_spec == expected_spec
def build_base_images(): """Build base images on GCB.""" image_templates = {'base-image': _get_buildable_images()['base-image']} config = generate_cloudbuild.create_cloudbuild_spec(image_templates, build_base_images=True) _build(config, 'base-images')