@@ -71,6 +71,7 @@ class Installer(object):
7171 'additional_rpms_path' ,
7272 'ansible' ,
7373 'arch' ,
74+ 'archives' ,
7475 'autopartition' ,
7576 'bootmode' ,
7677 'build_mounts' ,
@@ -863,6 +864,7 @@ def _unsafe_install(self):
863864 self ._write_manifest ()
864865 self ._selinux_label () # run after last possible file creation
865866 self ._cleanup_install_repo ()
867+ self ._create_archive ()
866868 self ._unmount_all ()
867869
868870 def exit_gracefully (self , signal1 = None , frame1 = None ):
@@ -1053,6 +1055,34 @@ def _write_manifest(self):
10531055 f .write (json .dumps (manifest ))
10541056 subprocess .run (["gzip" , mf_file ])
10551057
1058+ def _create_archive (self ):
1059+ if 'archives' not in self .install_config :
1060+ return
1061+
1062+ archives = self .install_config ['archives' ]
1063+ for archive in archives :
1064+ filename = archive .get ('filename' , "rootfs.tar.gz" )
1065+ skip_mounts = archive .get ('skip_mounts' , False )
1066+ exclude_paths = archive .get ('exclude_paths' , [])
1067+ exclude_paths .extend (["/proc" , "/dev" , "/sys" , "/run" , "/tmp" ])
1068+ root = archive .get ('root' , "/" ).strip ("/" )
1069+
1070+ # filename may be an absolute path, os.path.join() will do as intended
1071+ dest_path = os .path .join (self .cwd , filename )
1072+ command = ["tar" , "--numeric-owner" , "-czf" , dest_path ]
1073+ src_path = os .path .join (self .photon_root , root )
1074+ command .extend (["-C" , src_path ])
1075+ for path in exclude_paths :
1076+ command .extend (["--exclude" , "." + path ])
1077+ if skip_mounts :
1078+ command .append ("--one-file-system" )
1079+ command .append ("." )
1080+ retval = self .cmd .run (command )
1081+ if retval != 0 :
1082+ self .logger .error (f"Failed to create archive { filename } " )
1083+ self .exit_gracefully ()
1084+ self .logger .info (f"Created archive { filename } " )
1085+
10561086 def _unmount_all (self ):
10571087 """
10581088 Unmount partitions and special folders
0 commit comments