@@ -459,6 +459,22 @@ def build(self):
459459 dresult = job (component )
460460 dlines .extend (dresult )
461461
462+ if os .path .isdir (self ._workdir / "tmp_bin" ):
463+ # For every binary file that was copied to the tmp_bin directory by the jobs above, search for the existing file in the container and replace it.
464+ dlines .append ("ADD tmp_bin /tmpbin" )
465+ dlines .append ("RUN for i in tmpbin/*; do find /usr/bin /usr/sbin -name $(basename $i) -exec mv -f $i '{}' \;; echo $(basename $i); done && rm -rf tmpbin" )
466+
467+ if os .path .isdir (self ._workdir / "tmp_lib" ):
468+ # For every library file that was copied to the tmp_lib directory by the jobs above, search for the existing file in the container and replace it.
469+ dlines .append ("ADD tmp_lib /tmplib" )
470+ dlines .append ("RUN for i in tmplib/*; do find /usr/lib64 -name $(basename $i) -exec mv -f $i '{}' \;; echo $(basename $i); done && rm -rf tmplib" )
471+
472+ if os .path .isdir (self ._workdir / "tmp_bin" ):
473+ # by default locally built binaries assume /usr/local
474+ dlines .append ("RUN rm -rf /usr/local/lib64 && ln -sf /usr/lib64 /usr/local && ln -sf /usr/share/ceph /usr/local/share" )
475+ # locally built binaries assume libceph-common.so.2 is in /usr/lib64 - create link to library that was just copied
476+ dlines .append ("RUN ln -sf /usr/lib64/ceph/libceph-common.so.2 /usr/lib64/libceph-common.so.2" )
477+
462478 with open (self ._workdir / "Dockerfile" , "w" ) as fout :
463479 for line in dlines :
464480 print (line , file = fout )
@@ -502,7 +518,9 @@ def _copy_binary(self, src_path, dst_path):
502518 if self ._ctx .strip_binaries :
503519 log .debug ("copy and strip: %s" , dst_path )
504520 shutil .copy2 (src_path , dst_path )
505- _run (["strip" , str (dst_path )]).check_returncode ()
521+ output = _run (["file" , str (dst_path )], capture_output = True , text = True )
522+ if "ELF" in output .stdout :
523+ _run (["strip" , str (dst_path )]).check_returncode ()
506524 return
507525 log .debug ("hard linking: %s" , dst_path )
508526 try :
@@ -511,39 +529,29 @@ def _copy_binary(self, src_path, dst_path):
511529 pass
512530 os .link (src_path , dst_path )
513531
514- def _bins_and_libs (self , prefix , bin_patterns , lib_patterns ):
532+ def _bins_and_libs (self , prefix , bin_patterns , lib_patterns , exclude_prefixes = [] ):
515533 out = []
516534
517535 bin_src = self ._ctx .build_dir / "bin"
518536 bin_dst = self ._workdir / f"{ prefix } _bin"
519537 bin_dst .mkdir (parents = True , exist_ok = True )
520538 for path in bin_src .iterdir ():
521539 if any (path .match (m ) for m in bin_patterns ):
540+ if any (path .match (f"{ m } *" ) for m in exclude_prefixes ):
541+ continue
522542 self ._copy_binary (path , bin_dst / path .name )
523- out .append (f"ADD { prefix } _bin /usr/bin" )
524543
525544 lib_src = self ._ctx .build_dir / "lib"
526545 lib_dst = self ._workdir / f"{ prefix } _lib"
527546 lib_dst .mkdir (parents = True , exist_ok = True )
528547 for path in lib_src .iterdir ():
529548 if any (path .match (m ) for m in lib_patterns ):
549+ if any (path .match (f"{ m } *" ) for m in exclude_prefixes ):
550+ continue
530551 self ._copy_binary (path , lib_dst / path .name )
531- out .append (f"ADD { prefix } _lib /usr/lib64" )
532552
533553 return out
534554
535- def _conditional_libs (self , src_dir , name , destination , lib_patterns ):
536- lib_src = self ._ctx .build_dir / src_dir
537- lib_dst = self ._workdir / name
538- lib_dst .mkdir (parents = True , exist_ok = True )
539- try :
540- for path in lib_src .iterdir ():
541- if any (path .match (m ) for m in lib_patterns ):
542- self ._copy_binary (path , lib_dst / path .name )
543- except FileNotFoundError as err :
544- log .warning ("skipping lib %s: %s" , name , err )
545- return f"ADD { name } { destination } "
546-
547555 def _py_site_packages (self ):
548556 """Return the correct python site packages dir for the image."""
549557 if self ._cached_py_site_packages is not None :
@@ -583,7 +591,7 @@ def _py_mgr_job(self, component):
583591 exclude_dirs = ("tests" ,)
584592 else :
585593 log .debug ("Excluding dashboard from mgr" )
586- exclude_dirs = ("tests" , "node_modules" )
594+ exclude_dirs = ("tests" , "node_modules" , ".tox" , ".angular" )
587595 exclude_file_suffixes = (".pyc" , ".pyo" , ".tmp" , "~" )
588596 with tarfile .open (self ._workdir / name , mode = "w" ) as tar :
589597 with ChangeDir (self ._ctx .source_dir / "src/pybind/mgr" ):
@@ -596,7 +604,7 @@ def _py_mgr_job(self, component):
596604
597605 def _py_common_job (self , component ):
598606 name = "python_common.tar"
599- exclude_dirs = ("tests" , "node_modules" )
607+ exclude_dirs = ("tests" , "node_modules" , ".tox" )
600608 exclude_file_suffixes = (".pyc" , ".pyo" , ".tmp" , "~" )
601609 with tarfile .open (self ._workdir / name , mode = "w" ) as tar :
602610 with ChangeDir (self ._ctx .source_dir / "src/python-common" ):
@@ -637,60 +645,39 @@ def _core_job(self, component):
637645 # [Quoth the original script]:
638646 # binaries are annoying because the ceph version is embedded all over
639647 # the place, so we have to include everything but the kitchen sink.
640- out = []
641-
642- out .extend (
643- self ._bins_and_libs (
644- prefix = "core" ,
645- bin_patterns = ["ceph-mgr" , "ceph-mon" , "ceph-osd" , "rados" ],
646- lib_patterns = ["libceph-common.so*" , "librados.so*" ],
647- )
648- )
649-
650- out .append (
651- self ._conditional_libs (
652- src_dir = "lib" ,
653- name = "eclib" ,
654- destination = "/usr/lib64/ceph/erasure-code" ,
655- lib_patterns = ["libec_*.so*" ],
656- )
657- )
658- out .append (
659- self ._conditional_libs (
660- src_dir = "lib" ,
661- name = "clslib" ,
662- destination = "/usr/lib64/rados-classes" ,
663- lib_patterns = ["libcls_*.so*" ],
664- )
665- )
648+ if not self ._ctx .components_selected :
649+ log .warning ("Copying ALL locally built binaries over those that already exist in the image." )
650+ bins = ['*' ]
651+ else :
652+ bins = ["ceph-mgr" , "ceph-mon" , "ceph-osd" , "rados" ]
666653
667- # [Quoth the original script]:
668- # by default locally built binaries assume /usr/local
669- out .append (
670- "RUN rm -rf /usr/local/lib64 && ln -s /usr/lib64 /usr/local && ln -s /usr/share/ceph /usr/local/share"
654+ return self ._bins_and_libs (
655+ prefix = "tmp" ,
656+ bin_patterns = bins ,
657+ lib_patterns = ["*.so" ,"*.so.*" ],
658+ exclude_prefixes = ["ceph_test" ,"test_" ,"unittest_" ],
671659 )
672-
673660 return out
674661
675662 def _rgw_job (self , component ):
676663 return self ._bins_and_libs (
677- prefix = "rgw " ,
664+ prefix = "tmp " ,
678665 bin_patterns = ["radosgw" , "radosgw-admin" ],
679- lib_patterns = ["libradosgw .so*" ],
666+ lib_patterns = ["librados.so*" , "libceph-common .so*" ],
680667 )
681668 return out
682669
683670 def _cephfs_job (self , component ):
684671 return self ._bins_and_libs (
685- prefix = "cephfs " ,
672+ prefix = "tmp " ,
686673 bin_patterns = ["ceph-mds" ],
687674 lib_patterns = ["libcephfs.so*" ],
688675 )
689676 return out
690677
691678 def _rbd_job (self , component ):
692679 return self ._bins_and_libs (
693- prefix = "rbd " ,
680+ prefix = "tmp " ,
694681 bin_patterns = ["rbd" , "rbd-mirror" ],
695682 lib_patterns = ["librbd.so*" ],
696683 )
0 commit comments