Skip to content

Commit e949a94

Browse files
committed
cmdlib: specify repo path for import_oci_archive()
Somehow hardcoding `tmp/repo` here isn't actually working. Here's what happens if I blow away my `tmp/` and then attempt to do another operation (like `cosa osbuild qemu`): ``` Wrote: ostree-unverified-image:oci-archive:/srv/tmp/cosa-import-op0cg6_c/out.ociarchive => e202ee3cb8a2a8d814bd2b325cdef5500459fd2381d4fa766cd15ab730ae0e80 2273 metadata, 8746 content objects imported; 1.2 GB content written 1471 metadata, 1534 content objects imported; 133.6 MB content written Imported OCI image as build 42.20250821.dev.0 Pruning build 44.20250826.dev.0 Deleting 5 blob refs [coreos-assembler]$ [coreos-assembler]$ rm -rf tmp/* [coreos-assembler]$ cosa osbuild qemu Config commit: e5f88e72120b3f89cf2c4d81b45bbe791d9bd79d Using manifest: /srv/src/config/manifest.yaml Will build qemu Extracting e202ee3cb8a2a8d814bd2b325cdef5500459fd2381d4fa766cd15ab730ae0e80 layers already present: 0; layers needed: 66 (975.9 MB) 3725 metadata, 21742 content objects imported; 1.7 GB content written 3 2603 metadata, 10508 content objects imported; 250.5 MB content written error: No such metadata object e202ee3cb8a2a8d814bd2b325cdef5500459fd2381d4fa766cd15ab730ae0e80.commit Traceback (most recent call last): File "<string>", line 10, in <module> cmdlib.import_ostree_commit(workdir, builddir, buildmeta, extract_json=('1' == '1')) ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/coreos-assembler/cosalib/cmdlib.py", line 362, in import_ostree_commit extract_image_json(workdir, commit) ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ File "/usr/lib/coreos-assembler/cosalib/cmdlib.py", line 272, in extract_image_json raise Exception("Failed to extract image.json") Exception: Failed to extract image.json failed to execute cmd-osbuild: exit status 1 ``` Let's just have the caller explicitly tell us the path to the repo we want to import into is.
1 parent 244e6de commit e949a94

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/cmd-import

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def main():
4747
tmp_oci_manifest = generate_oci_manifest(args, tmpd)
4848

4949
# import into the tmp/repo to get the ostree-commit but also so it's cached
50-
ostree_commit = import_oci_archive(tmpd, tmp_oci_archive, buildid)
50+
ostree_commit = import_oci_archive(tmpd, 'tmp/repo', tmp_oci_archive, buildid)
5151

5252
# artificially recreate generated lockfile
5353
tmp_lockfile = generate_lockfile(tmpd, ostree_commit)

src/cosalib/cmdlib.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def import_ostree_commit(workdir, buildpath, buildmeta, extract_json=True, parti
337337
if was_oci_imported:
338338
# This was initially imported using `cosa import`. Go through that
339339
# path again because it's not an encapsulated commit.
340-
import_oci_archive(tmpdir, tarfile, buildmeta['buildid'])
340+
import_oci_archive(tmpdir, repo, tarfile, buildmeta['buildid'])
341341
elif os.environ.get('COSA_PRIVILEGED', '') == '1':
342342
build_repo = os.path.join(repo, '../../cache/repo-build')
343343
# note: this actually is the same as `container unencapsulate` and
@@ -362,46 +362,46 @@ def import_ostree_commit(workdir, buildpath, buildmeta, extract_json=True, parti
362362
extract_image_json(workdir, commit)
363363

364364

365-
def import_oci_archive(parent_tmpd, ociarchive, ref):
365+
def import_oci_archive(parent_tmpd, repo, ociarchive, ref):
366366
'''
367-
Imports layered/non-encapsulated OCI archive into the tmp/repo. Returns
368-
the OSTree commit that was imported.
367+
Imports layered/non-encapsulated OCI archive into the repo
368+
(usually tmp/repo). Returns the OSTree commit that was imported.
369369
'''
370-
with tempfile.TemporaryDirectory(dir=parent_tmpd) as tmpd:
371-
subprocess.check_call(['ostree', 'init', '--repo', tmpd, '--mode=bare-user'])
370+
with tempfile.TemporaryDirectory(dir=parent_tmpd) as tmprepo:
371+
subprocess.check_call(['ostree', 'init', '--repo', tmprepo, '--mode=bare-user'])
372372

373373
# Init tmp/repo in case it doesn't exist.
374374
# If it exists, no problem. It's idempotent
375-
subprocess.check_call(['ostree', 'init', '--repo', 'tmp/repo', '--mode=archive'])
375+
subprocess.check_call(['ostree', 'init', '--repo', repo, '--mode=archive'])
376376

377377
# import all the blob refs for more efficient import into bare-user repo
378-
blob_refs = subprocess.check_output(['ostree', 'refs', '--repo', 'tmp/repo',
378+
blob_refs = subprocess.check_output(['ostree', 'refs', '--repo', repo,
379379
'--list', 'ostree/container/blob'],
380380
encoding='utf-8').splitlines()
381381
if len(blob_refs) > 0:
382-
subprocess.check_call(['ostree', 'pull-local', '--repo', tmpd, 'tmp/repo'] + blob_refs)
382+
subprocess.check_call(['ostree', 'pull-local', '--repo', tmprepo, repo] + blob_refs)
383383

384-
subprocess.check_call(['ostree', 'container', 'image', 'pull', tmpd,
384+
subprocess.check_call(['ostree', 'container', 'image', 'pull', tmprepo,
385385
f'ostree-unverified-image:oci-archive:{ociarchive}'])
386386

387387
# awkwardly work around the fact that there is no --write-ref equivalent
388388
# XXX: we can make this better once we can rely on --ostree-digestfile
389389
# https://github.com/bootc-dev/bootc/pull/1421
390-
refs = subprocess.check_output(['ostree', 'refs', '--repo', tmpd,
390+
refs = subprocess.check_output(['ostree', 'refs', '--repo', tmprepo,
391391
'--list', 'ostree/container/image'],
392392
encoding='utf-8').splitlines()
393393
assert len(refs) == 1
394-
subprocess.check_call(['ostree', 'refs', '--repo', tmpd, refs[0], '--create', ref])
395-
subprocess.check_call(['ostree', 'refs', '--repo', 'tmp/repo', ref, '--delete'])
396-
subprocess.check_call(['ostree', 'pull-local', '--repo', 'tmp/repo', tmpd, ref])
394+
subprocess.check_call(['ostree', 'refs', '--repo', tmprepo, refs[0], '--create', ref])
395+
subprocess.check_call(['ostree', 'refs', '--repo', repo, ref, '--delete'])
396+
subprocess.check_call(['ostree', 'pull-local', '--repo', repo, tmprepo, ref])
397397

398398
# export back all the blob refs for more efficient imports of next builds
399-
blob_refs = subprocess.check_output(['ostree', 'refs', '--repo', tmpd,
399+
blob_refs = subprocess.check_output(['ostree', 'refs', '--repo', tmprepo,
400400
'--list', 'ostree/container/blob'],
401401
encoding='utf-8').splitlines()
402-
subprocess.check_call(['ostree', 'pull-local', '--repo', 'tmp/repo', tmpd] + blob_refs)
402+
subprocess.check_call(['ostree', 'pull-local', '--repo', repo, tmprepo] + blob_refs)
403403

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

407407

0 commit comments

Comments
 (0)