65
65
_CACHED_IMAGE = ('us-central1-docker.pkg.dev/oss-fuzz/oss-fuzz-gen/'
66
66
'{name}-ofg-cached-{sanitizer}' )
67
67
_CACHED_SANITIZERS = ('address' , 'coverage' )
68
+ _INDEXED_CONTAINER_NAME = 'indexed-container'
68
69
69
70
70
71
@dataclass
@@ -503,6 +504,12 @@ def get_build_steps_for_project(project,
503
504
return build_steps
504
505
505
506
507
+ def _indexer_built_image_name (name : str ):
508
+ # TODO(ochang): Write this to a tar (via docker image save) and upload this to
509
+ # GCS.
510
+ return f'us-docker.pkg.dev/oss-fuzz/indexer/{ name } '
511
+
512
+
506
513
def get_indexer_build_steps (project_name ,
507
514
project_yaml ,
508
515
dockerfile ,
@@ -533,6 +540,7 @@ def get_indexer_build_steps(project_name,
533
540
build = Build ('none' , 'address' , 'x86_64' )
534
541
env = get_env (project .fuzzing_language , build , project .name )
535
542
env .append ('INDEXER_BUILD=1' )
543
+ env .append ('CAPTURE_REPLAY_SCRIPT=1' )
536
544
537
545
prefix = f'indexer_indexes/{ project .name } /{ timestamp } /'
538
546
signed_policy_document = build_lib .get_signed_policy_document_upload_prefix (
@@ -543,14 +551,60 @@ def get_indexer_build_steps(project_name,
543
551
index_step = {
544
552
'name' : project .image ,
545
553
'args' : [
546
- 'bash' , '-c' ,
547
- f'cd /src && cd { project .workdir } && mkdir -p { build .out } && /opt/indexer/index_build.py'
554
+ 'bash' ,
555
+ '-c' ,
556
+ f'cd /src && cd { project .workdir } && mkdir -p { build .out } && '
557
+ '/opt/indexer/index_build.py && '
558
+ # Enable re-building both the project and the indexes.
559
+ 'cp -n /usr/local/bin/replay_build.sh $$SRC/ && '
560
+ # Save the CDB fragments so we can re-use them for rebuilding indexes.
561
+ 'cp -r $$OUT/cdb /cdb && '
562
+ # Link /out to the actual $OUT and actually create it in the
563
+ # container's filesystem since it's a mount.
564
+ 'rm -rf /out && ln -s $$OUT /out && '
565
+ 'umount /workspace && mkdir -p $$OUT'
548
566
],
549
567
'env' : env ,
550
568
}
551
569
build_lib .dockerify_run_step (index_step ,
552
570
build ,
553
- use_architecture_image_name = build .is_arm )
571
+ use_architecture_image_name = build .is_arm ,
572
+ container_name = _INDEXED_CONTAINER_NAME )
573
+ push_image_steps = [
574
+ {
575
+ 'name' :
576
+ build_lib .DOCKER_TOOL_IMAGE ,
577
+ 'args' : [
578
+ 'container' ,
579
+ 'commit' ,
580
+ '-c' ,
581
+ 'ENV REPLAY_ENABLED 1' ,
582
+ # Add CFLAGS that enable debugging (this should match the
583
+ # index_build.py CFLAGS)
584
+ '-c' ,
585
+ 'ENV CFLAGS "$$CFLAGS -O0 -glldb"' ,
586
+ _INDEXED_CONTAINER_NAME ,
587
+ _indexer_built_image_name (project .name ) + f':{ timestamp } '
588
+ ],
589
+ },
590
+ {
591
+ 'name' :
592
+ build_lib .DOCKER_TOOL_IMAGE ,
593
+ 'args' : [
594
+ 'tag' ,
595
+ _indexer_built_image_name (project .name ) + f':{ timestamp } ' ,
596
+ _indexer_built_image_name (project .name )
597
+ ],
598
+ },
599
+ {
600
+ 'name' :
601
+ build_lib .DOCKER_TOOL_IMAGE ,
602
+ 'args' : [
603
+ 'push' , '--all-tags' ,
604
+ _indexer_built_image_name (project .name )
605
+ ],
606
+ },
607
+ ]
554
608
555
609
# TODO: Don't upload anything if we're in trial build.
556
610
build_steps .extend ([
@@ -565,12 +619,13 @@ def get_indexer_build_steps(project_name,
565
619
f'https://{ signed_policy_document .bucket } .storage.googleapis.com;'
566
620
' done'
567
621
],
568
- 'entrypoint' : 'bash'
622
+ 'entrypoint' : 'bash' ,
623
+ 'allowFailure' : True ,
569
624
},
570
625
build_lib .upload_using_signed_policy_document ('/workspace/srcmap.json' ,
571
626
f'{ prefix } srcmap.json' ,
572
627
signed_policy_document ),
573
- ])
628
+ ] + push_image_steps )
574
629
return build_steps
575
630
576
631
0 commit comments