@@ -56,8 +56,11 @@ def main():
5656 # create meta.json
5757 build_meta = generate_build_meta (tmp_oci_archive , tmp_oci_manifest , metadata , ostree_commit )
5858
59+ # create commitmeta.json
60+ tmp_commitmeta = generate_commitmeta (tmpd , ostree_commit , build_meta )
61+
5962 # move into official location
60- finalize_build (builds , build_meta , tmp_oci_archive , tmp_oci_manifest , tmp_lockfile )
63+ finalize_build (builds , build_meta , tmp_oci_archive , tmp_oci_manifest , tmp_lockfile , tmp_commitmeta )
6164
6265 if not args .skip_prune :
6366 subprocess .check_call (['/usr/lib/coreos-assembler/cmd-prune' ])
@@ -114,6 +117,38 @@ def generate_lockfile(tmpd, ostree_commit):
114117 return tmpf
115118
116119
120+ def generate_commitmeta (tmpd , ostree_commit , build_meta ):
121+ tmpf = os .path .join (tmpd , 'commitmeta.json' )
122+ out = subprocess .check_output (['rpm-ostree' , 'db' , 'list' , '--repo' , 'tmp/repo' , ostree_commit ], encoding = 'utf-8' )
123+ ostree_linux = ''
124+ rpmdb = []
125+ for line in out .splitlines ():
126+ if not line .startswith (' ' ):
127+ continue
128+
129+ # Do we have epoch in package names?
130+ n , v , ra = line .strip ().rsplit ('-' , 2 )
131+ r , a = ra .rsplit ('.' , 1 )
132+ rpmdb .append ([n , "0" , v , r , a ])
133+ if n == 'kernel' :
134+ ostree_linux = f"{ v } -{ r } .{ a } "
135+
136+ commitmeta = {
137+ 'coreos-assembler.config-gitrev' : build_meta .get ('coreos-assembler.container-config-git' , {}).get ('commit' , '' ),
138+ 'coreos-assembler.basearch' : build_meta .get ('coreos-assembler.basearch' , '' ),
139+ 'fedora-coreos.stream' : build_meta .get ('coreos-assembler.oci-imported-labels' , {}).get ('fedora-coreos.stream' , '' ),
140+ 'version' : build_meta .get ('buildid' , '' ),
141+ 'ostree.bootable' : True if build_meta .get ('coreos-assembler.oci-imported-labels' , {}).get ('ostree.bootable' , '0' ) == '1' else False ,
142+ 'ostree.linux' : ostree_linux ,
143+ 'rpmostree.rpmdb.pkglist' : rpmdb ,
144+ }
145+
146+ with open (tmpf , 'w' ) as f :
147+ json .dump (commitmeta , f , indent = 2 )
148+
149+ return tmpf
150+
151+
117152def generate_build_meta (tmp_oci_archive , tmp_oci_manifest , metadata , ostree_commit ):
118153 name = metadata ['Labels' ]['com.coreos.osname' ]
119154 buildid = metadata ['Labels' ]['org.opencontainers.image.version' ]
@@ -170,7 +205,7 @@ def generate_build_meta(tmp_oci_archive, tmp_oci_manifest, metadata, ostree_comm
170205 return meta
171206
172207
173- def finalize_build (builds , build_meta , tmp_oci_archive , tmp_oci_manifest , tmp_lockfile ):
208+ def finalize_build (builds , build_meta , tmp_oci_archive , tmp_oci_manifest , tmp_lockfile , tmp_commitmeta ):
174209 buildid = build_meta ['buildid' ]
175210 arch = build_meta ['coreos-assembler.basearch' ]
176211
@@ -180,6 +215,7 @@ def finalize_build(builds, build_meta, tmp_oci_archive, tmp_oci_manifest, tmp_lo
180215 shutil .move (tmp_oci_archive , f'{ destdir } /{ build_meta ['images' ]['ostree' ]['path' ]} ' )
181216 shutil .move (tmp_oci_manifest , f'{ destdir } /{ build_meta ['images' ]['oci-manifest' ]['path' ]} ' )
182217 shutil .move (tmp_lockfile , f'{ destdir } /manifest-lock.generated.{ arch } .json' )
218+ shutil .move (tmp_commitmeta , f'{ destdir } /commitmeta.json' )
183219
184220 with open (f'{ destdir } /meta.json' , 'w' ) as f :
185221 json .dump (build_meta , f , indent = 4 )
0 commit comments