@@ -24,6 +24,7 @@ from cosalib.cmdlib import (
24
24
get_basearch ,
25
25
sha256sum_file ,
26
26
import_oci_archive )
27
+ from cosalib .meta import GenericBuildMeta
27
28
28
29
29
30
def main ():
@@ -63,6 +64,14 @@ def main():
63
64
# move into official location
64
65
finalize_build (builds , build_meta , tmp_oci_archive , tmp_oci_manifest , tmp_lockfile , tmp_commitmeta )
65
66
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
+
66
75
if not args .skip_prune :
67
76
subprocess .check_call (['/usr/lib/coreos-assembler/cmd-prune' ])
68
77
@@ -73,6 +82,8 @@ def parse_args():
73
82
help = "image to import (containers-transports(5) format)" )
74
83
parser .add_argument ("--skip-prune" , action = 'store_true' ,
75
84
help = "Skip prunning previous builds" )
85
+ parser .add_argument ("--parent-build" ,
86
+ help = "The parent build to diff against" )
76
87
return parser .parse_args ()
77
88
78
89
@@ -228,6 +239,28 @@ def finalize_build(builds, build_meta, tmp_oci_archive, tmp_oci_manifest, tmp_lo
228
239
print (f'Imported OCI image as build { buildid } ' )
229
240
230
241
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
+
231
264
def skopeo_inspect (image ):
232
265
return json .loads (subprocess .check_output (['skopeo' , 'inspect' , '-n' , image ]))
233
266
0 commit comments