Skip to content

Commit c332caf

Browse files
committed
cmdlib.py: Read ostree commit from digestfile
1 parent 7769949 commit c332caf

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/cosalib/cmdlib.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ def import_oci_archive(parent_tmpd, ociarchive, ref):
367367
Imports layered/non-encapsulated OCI archive into the tmp/repo. Returns
368368
the OSTree commit that was imported.
369369
'''
370+
370371
with tempfile.TemporaryDirectory(dir=parent_tmpd) as tmpd:
371372
subprocess.check_call(['ostree', 'init', '--repo', tmpd, '--mode=bare-user'])
372373

@@ -381,17 +382,15 @@ def import_oci_archive(parent_tmpd, ociarchive, ref):
381382
if len(blob_refs) > 0:
382383
subprocess.check_call(['ostree', 'pull-local', '--repo', tmpd, 'tmp/repo'] + blob_refs)
383384

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])
395394
subprocess.check_call(['ostree', 'refs', '--repo', 'tmp/repo', ref, '--delete'])
396395
subprocess.check_call(['ostree', 'pull-local', '--repo', 'tmp/repo', tmpd, ref])
397396

@@ -401,7 +400,6 @@ def import_oci_archive(parent_tmpd, ociarchive, ref):
401400
encoding='utf-8').splitlines()
402401
subprocess.check_call(['ostree', 'pull-local', '--repo', 'tmp/repo', tmpd] + blob_refs)
403402

404-
ostree_commit = subprocess.check_output(['ostree', 'rev-parse', '--repo', 'tmp/repo', ref], encoding='utf-8').strip()
405403
return ostree_commit
406404

407405

0 commit comments

Comments
 (0)