@@ -24,6 +24,7 @@ from cosalib.cmdlib import (
2424 get_basearch ,
2525 sha256sum_file ,
2626 import_oci_archive )
27+ from cosalib .meta import GenericBuildMeta
2728
2829
2930def main ():
@@ -63,6 +64,14 @@ def main():
6364 # move into official location
6465 finalize_build (builds , build_meta , tmp_oci_archive , tmp_oci_manifest , tmp_lockfile , tmp_commitmeta )
6566
67+ # Now that the build has been created (i.e. files put into the
68+ # right places) let's use `cosa diff` to insert package and
69+ # advisory diffs into the meta.json and log the RPM diff, but
70+ # only if we have something to diff against.
71+ if args .parent_build or len (builds .get_builds ()) > 1 :
72+ starting_buildid = args .parent_build if args .parent_build else builds .get_previous ()
73+ calculate_and_log_diffs (builds , buildid , arch , starting_buildid )
74+
6675 if not args .skip_prune :
6776 subprocess .check_call (['/usr/lib/coreos-assembler/cmd-prune' ])
6877
@@ -73,6 +82,8 @@ def parse_args():
7382 help = "image to import (containers-transports(5) format)" )
7483 parser .add_argument ("--skip-prune" , action = 'store_true' ,
7584 help = "Skip prunning previous builds" )
85+ parser .add_argument ("--parent-build" ,
86+ help = "The parent build to diff against" )
7687 return parser .parse_args ()
7788
7889
@@ -228,6 +239,28 @@ def finalize_build(builds, build_meta, tmp_oci_archive, tmp_oci_manifest, tmp_lo
228239 print (f'Imported OCI image as build { buildid } ' )
229240
230241
242+ def calculate_and_log_diffs (builds , buildid , arch , starting_buildid ):
243+ # Get the RPM/Advisory diff info
244+ diff_cmd_json = ['/usr/lib/coreos-assembler/cmd-diff' , '--rpms-json' ,
245+ '--from' , starting_buildid , '--to' , buildid ]
246+ diff_json_str = subprocess .check_output (diff_cmd_json )
247+ diff_data = json .loads (diff_json_str )
248+
249+ # Update the meta.json file with the RPM/Advisory diff info. Yes we
250+ # just created this file, but let's use the library now for access.
251+ meta = GenericBuildMeta (workdir = os .getcwd (), build = buildid , basearch = arch )
252+ meta .update ({
253+ 'pkgdiff' : diff_data .get ('pkgdiff' ),
254+ 'advisories-diff' : diff_data .get ('advisories' )
255+ })
256+ meta .write ()
257+
258+ # For the logs let's output the RPM diff
259+ diff_cmd_log = ['/usr/lib/coreos-assembler/cmd-diff' , '--rpms' ,
260+ '--from' , starting_buildid , '--to' , buildid ]
261+ subprocess .check_call (diff_cmd_log )
262+
263+
231264def skopeo_inspect (image ):
232265 return json .loads (subprocess .check_output (['skopeo' , 'inspect' , '-n' , image ]))
233266
0 commit comments