@@ -367,6 +367,7 @@ def import_oci_archive(parent_tmpd, ociarchive, ref):
367
367
Imports layered/non-encapsulated OCI archive into the tmp/repo. Returns
368
368
the OSTree commit that was imported.
369
369
'''
370
+
370
371
with tempfile .TemporaryDirectory (dir = parent_tmpd ) as tmpd :
371
372
subprocess .check_call (['ostree' , 'init' , '--repo' , tmpd , '--mode=bare-user' ])
372
373
@@ -381,17 +382,15 @@ def import_oci_archive(parent_tmpd, ociarchive, ref):
381
382
if len (blob_refs ) > 0 :
382
383
subprocess .check_call (['ostree' , 'pull-local' , '--repo' , tmpd , 'tmp/repo' ] + blob_refs )
383
384
384
- subprocess .check_call (['ostree' , 'container' , 'image' , 'pull' , tmpd ,
385
- f'ostree-unverified-image:oci-archive:{ ociarchive } ' ])
386
-
387
- # awkwardly work around the fact that there is no --write-ref equivalent
388
- # XXX: we can make this better once we can rely on --ostree-digestfile
389
- # https://github.com/bootc-dev/bootc/pull/1421
390
- refs = subprocess .check_output (['ostree' , 'refs' , '--repo' , tmpd ,
391
- '--list' , 'ostree/container/image' ],
392
- encoding = 'utf-8' ).splitlines ()
393
- assert len (refs ) == 1
394
- subprocess .check_call (['ostree' , 'refs' , '--repo' , tmpd , refs [0 ], '--create' , ref ])
385
+ subprocess .check_call (['ostree' , 'container' , 'image' , 'pull' ,
386
+ '--ostree-digestfile' , f'{ tmpd } /digestfile' ,
387
+ tmpd , f'ostree-unverified-image:oci-archive:{ ociarchive } ' ])
388
+
389
+ # Read the digestfile and get the ref
390
+ with open (f'{ tmpd } /digestfile' , 'r' ) as f :
391
+ ostree_commit = f .read ()
392
+
393
+ subprocess .check_call (['ostree' , 'refs' , '--repo' , tmpd , ostree_commit , '--create' , ref ])
395
394
subprocess .check_call (['ostree' , 'refs' , '--repo' , 'tmp/repo' , ref , '--delete' ])
396
395
subprocess .check_call (['ostree' , 'pull-local' , '--repo' , 'tmp/repo' , tmpd , ref ])
397
396
@@ -401,7 +400,6 @@ def import_oci_archive(parent_tmpd, ociarchive, ref):
401
400
encoding = 'utf-8' ).splitlines ()
402
401
subprocess .check_call (['ostree' , 'pull-local' , '--repo' , 'tmp/repo' , tmpd ] + blob_refs )
403
402
404
- ostree_commit = subprocess .check_output (['ostree' , 'rev-parse' , '--repo' , 'tmp/repo' , ref ], encoding = 'utf-8' ).strip ()
405
403
return ostree_commit
406
404
407
405
0 commit comments