Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra: enable building projects using cached images #12597

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions infra/build/functions/build_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ def image(self):
"""Returns the docker image for the project."""
return f'gcr.io/{build_lib.IMAGE_PROJECT}/{self.name}'

def cached_image(self, coverage):
sanitizer_mapping = {'address': 'asan', 'coverage': 'cov'}
san_lookup = sanitizer_mapping[sanitizer]
return ('us-central1-docker.pkg.dev/oss-fuzz/oss-fuzz-gen/'
f'{self.name}-ofg-cached-{san_lookup}')


def get_last_step_id(steps):
"""Returns the id of the last step in |steps|."""
Expand Down Expand Up @@ -308,10 +314,15 @@ def get_build_steps( # pylint: disable=too-many-locals, too-many-statements, to
project_yaml,
dockerfile,
config,
additional_env=None):
additional_env=None,
use_caching=False):
"""Returns build steps for project."""

project = Project(project_name, project_yaml, dockerfile)
if use_caching:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I'm unsure if this works, because I think the build steps will generate a step to build the image. We need to remove that as well.

project_image = project.cached_image()
else:
project_image = project.image

if project.disabled:
logging.info('Project "%s" is disabled.', project.name)
Expand All @@ -320,7 +331,7 @@ def get_build_steps( # pylint: disable=too-many-locals, too-many-statements, to
timestamp = get_datetime_now().strftime('%Y%m%d%H%M')
build_steps = build_lib.get_project_image_steps(
project.name,
project.image,
project_image,
project.fuzzing_language,
config=config,
architectures=project.architectures,
Expand Down Expand Up @@ -357,7 +368,7 @@ def get_build_steps( # pylint: disable=too-many-locals, too-many-statements, to
# Report the build failure if it happened.
build_steps.append({
'name':
project.image,
project_image,
'args': [
'bash', '-c',
f'cat {LOCAL_BUILD_LOG_PATH} && test -f {BUILD_SUCCESS_MARKER}'
Expand Down
10 changes: 7 additions & 3 deletions infra/build/functions/target_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

def run_experiment(project_name, target_name, args, output_path, errlog_path,
build_output_path, upload_corpus_path, upload_coverage_path,
experiment_name, upload_reproducer_path, tags):
experiment_name, upload_reproducer_path, tags, use_cached_image):
config = build_project.Config(testing=True,
test_image_suffix='',
repo=build_project.DEFAULT_OSS_FUZZ_REPO,
Expand Down Expand Up @@ -68,7 +68,8 @@ def run_experiment(project_name, target_name, args, output_path, errlog_path,
project_yaml,
dockerfile_contents,
config,
additional_env=jcc_env)
additional_env=jcc_env,
use_caching=use_cached_image)

build = build_project.Build('libfuzzer', 'address', 'x86_64')
local_output_path = '/workspace/output.log'
Expand Down Expand Up @@ -330,12 +331,15 @@ def main():
nargs='*',
help='Tags for cloud build.',
default=[])
parser.add_argument('--use_cached_image',
action='store_true',
help='Use cached images post build.')
args = parser.parse_args()

run_experiment(args.project, args.target, args.args, args.upload_output_log,
args.upload_err_log, args.upload_build_log, args.upload_corpus,
args.upload_coverage, args.experiment_name,
args.upload_reproducer, args.tags)
args.upload_reproducer, args.tags, args.use_cached_image)


if __name__ == '__main__':
Expand Down
Loading