infra: Only pull images corresponding to project language (#6459)

infra/helper.py build_image foobar should, when asked to pull base
images, only pull the generic images as well as the base-builder for the
language declared in foobar.
This commit is contained in:
Fabian Meumertzheim 2021-09-17 17:39:57 +02:00 committed by GitHub
parent f6c699acab
commit e91f809c27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 21 deletions

View File

@ -37,18 +37,20 @@ BUILD_DIR = os.path.join(OSS_FUZZ_DIR, 'build')
BASE_RUNNER_IMAGE = 'gcr.io/oss-fuzz-base/base-runner'
BASE_IMAGES = [
'gcr.io/oss-fuzz-base/base-image',
'gcr.io/oss-fuzz-base/base-clang',
'gcr.io/oss-fuzz-base/base-builder',
'gcr.io/oss-fuzz-base/base-builder-go',
'gcr.io/oss-fuzz-base/base-builder-jvm',
'gcr.io/oss-fuzz-base/base-builder-python',
'gcr.io/oss-fuzz-base/base-builder-rust',
'gcr.io/oss-fuzz-base/base-builder-swift',
BASE_RUNNER_IMAGE,
'gcr.io/oss-fuzz-base/base-runner-debug',
]
BASE_IMAGES = {
'generic': [
'gcr.io/oss-fuzz-base/base-image',
'gcr.io/oss-fuzz-base/base-clang',
'gcr.io/oss-fuzz-base/base-builder',
BASE_RUNNER_IMAGE,
'gcr.io/oss-fuzz-base/base-runner-debug',
],
'go': ['gcr.io/oss-fuzz-base/base-builder-go'],
'jvm': ['gcr.io/oss-fuzz-base/base-builder-jvm'],
'python': ['gcr.io/oss-fuzz-base/base-builder-python'],
'rust': ['gcr.io/oss-fuzz-base/base-builder-rust'],
'swift': ['gcr.io/oss-fuzz-base/base-builder-swift'],
}
VALID_PROJECT_NAME_REGEX = re.compile(r'^[a-zA-Z0-9_-]+$')
MAX_PROJECT_NAME_LENGTH = 26
@ -471,7 +473,7 @@ def build_image_impl(project, cache=True, pull=False):
docker_build_dir = project.path
image_project = 'oss-fuzz'
if pull and not pull_images():
if pull and not pull_images(project.language):
return False
build_args = []
@ -1128,11 +1130,15 @@ def shell(args):
return True
def pull_images():
"""Pulls base images."""
for base_image in BASE_IMAGES:
if not docker_pull(base_image):
return False
def pull_images(language=None):
"""Pulls base images used to build projects in language lang (or all if lang
is None)."""
for base_image_lang, base_images in BASE_IMAGES.items():
if (language is None or base_image_lang == 'generic' or
base_image_lang == language):
for base_image in base_images:
if not docker_pull(base_image):
return False
return True

View File

@ -59,9 +59,9 @@ class BuildImageImplTest(unittest.TestCase):
def test_pull(self, mock_pull_images, _):
"""Tests that pull=True is handled properly."""
image_name = 'base-image'
self.assertTrue(
helper.build_image_impl(helper.Project(image_name), pull=True))
mock_pull_images.assert_called_with()
project = helper.Project(image_name, is_external=True)
self.assertTrue(helper.build_image_impl(project, pull=True))
mock_pull_images.assert_called_with('c++')
@mock.patch('helper.docker_build')
def test_base_image(self, mock_docker_build):