aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra
diff options
context:
space:
mode:
authorGravatar jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2022-04-08 15:58:34 -0400
committerGravatar GitHub <noreply@github.com>2022-04-08 15:58:34 -0400
commit2fe1b0828d2f1a64466c4226f4bc74a35b69368c (patch)
treea3f4b2a6bb384bf172b9198dd93e3123bf291b5e /infra
parentcacd58c2222489577681c881031f1e606db31e31 (diff)
[trial-builds] Use buildkit caching (#7535)
Do this to make trial builds more interactive. By using buildkit caching, we won't need to rebuild every single image when a change is made to the PR.
Diffstat (limited to 'infra')
-rwxr-xr-xinfra/build/functions/build_and_push_test_images.py19
-rw-r--r--infra/build/functions/build_lib.py19
2 files changed, 28 insertions, 10 deletions
diff --git a/infra/build/functions/build_and_push_test_images.py b/infra/build/functions/build_and_push_test_images.py
index 323cc002..8fdcae52 100755
--- a/infra/build/functions/build_and_push_test_images.py
+++ b/infra/build/functions/build_and_push_test_images.py
@@ -48,17 +48,20 @@ def build_and_push_image(image, test_image_suffix):
main_tag = TAG_PREFIX + image
testing_tag = main_tag + '-' + test_image_suffix
tags = [main_tag, testing_tag]
- build_image(image, tags)
+ build_image(image, tags, testing_tag)
push_image(testing_tag)
-def build_image(image, tags):
+def build_image(image, tags, cache_from_tag):
"""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.extend([
+ '--build-arg', 'BUILDKIT_INLINE_CACHE=1', '--cache-from', cache_from_tag
+ ])
command.append(path)
subprocess.run(command, check=True)
logging.info('Built: %s', image)
@@ -74,7 +77,8 @@ def gcb_build_and_push_images(test_image_suffix):
test_images.append(test_image_name)
directory = os.path.join('infra', 'base-images', base_image)
step = build_lib.get_docker_build_step([image_name, test_image_name],
- directory)
+ directory,
+ buildkit_cache_image=test_image_name)
steps.append(step)
overrides = {'images': test_images}
@@ -103,13 +107,14 @@ def build_and_push_images(test_image_suffix):
'base-builder-rust',
],
]
+ os.environ['DOCKER_BUILDKIT'] = '1'
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:
- args_list = [(image, test_image_suffix) for image in image_list]
- pool.starmap(build_and_push_image, args_list)
+ with multiprocessing.Pool(proc_count) as pool:
+ for image_list in images:
+ args_list = [(image, test_image_suffix) for image in image_list]
+ pool.starmap(build_and_push_image, args_list)
def main():
diff --git a/infra/build/functions/build_lib.py b/infra/build/functions/build_lib.py
index c2b43fa2..05b1248f 100644
--- a/infra/build/functions/build_lib.py
+++ b/infra/build/functions/build_lib.py
@@ -319,7 +319,7 @@ def get_git_clone_step(repo_url='https://github.com/google/oss-fuzz.git',
return clone_step
-def get_docker_build_step(image_names, directory):
+def get_docker_build_step(image_names, directory, buildkit_cache_image=None):
"""Returns the docker build step."""
assert len(image_names) >= 1
directory = os.path.join('oss-fuzz', directory)
@@ -327,12 +327,25 @@ def get_docker_build_step(image_names, directory):
for image_name in image_names:
args.extend(['--tag', image_name])
- args.append('.')
- return {
+ step = {
'name': 'gcr.io/cloud-builders/docker',
'args': args,
'dir': directory,
}
+ # Note that we mutate "args" after making it a value in step.
+
+ if buildkit_cache_image is not None:
+ env = ['DOCKER_BUILDKIT=1']
+ step['env'] = env
+ assert buildkit_cache_image in args
+ additional_args = [
+ '--build-arg', 'BUILDKIT_INLINE_CACHE=1', '--cache-from',
+ buildkit_cache_image
+ ]
+ args.extend(additional_args)
+ args.append('.')
+
+ return step
def project_image_steps(name,