Skip to content

Commit 9429405

Browse files
committed
cmdlib.py: Read ostree commit from digestfile
1 parent f6371b6 commit 9429405

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/cosalib/cmdlib.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ 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+
371+
ostree_commit = ''
370372
with tempfile.TemporaryDirectory(dir=parent_tmpd) as tmpd:
371373
subprocess.check_call(['ostree', 'init', '--repo', tmpd, '--mode=bare-user'])
372374

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

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])
386+
subprocess.check_call(['ostree', 'container', 'image', 'pull',
387+
'--ostree-digestfile', f'{parent_tmpd}/digestfile',
388+
tmpd, f'ostree-unverified-image:oci-archive:{ociarchive}'])
389+
390+
# Read the digestfile and get the ref
391+
with open(f'{parent_tmpd}/digestfile', 'r') as f:
392+
ostree_commit = f.read().splitlines()[0]
393+
394+
subprocess.check_call(['ostree', 'refs', '--repo', tmpd, ostree_commit, '--create', ref])
395395
subprocess.check_call(['ostree', 'refs', '--repo', 'tmp/repo', ref, '--delete'])
396396
subprocess.check_call(['ostree', 'pull-local', '--repo', 'tmp/repo', tmpd, ref])
397397

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

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

407406

0 commit comments

Comments
 (0)