Skip to content

Commit 7218634

Browse files
committed
push-container: Also inject baseos-container into meta.json
While I am trying to actively sever the dependence of the base container image build on `meta.json`, there's no reason not to inject it into `meta.json` in this flow too because the build system already requires it.
1 parent 071527b commit 7218634

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/cmd-push-container

+20-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import argparse
88
import json
99
import os
10+
import tempfile
11+
import shutil
1012
import subprocess
1113
import sys
1214

@@ -44,11 +46,23 @@ if args.authfile is not None:
4446
skopeoargs.extend(['--authfile', args.authfile])
4547
if args.format is not None:
4648
skopeoargs.extend(['--format', args.format])
47-
container_name = args.name
48-
if ":" not in container_name:
49-
container_name = f"{container_name}:{latest_build}-{arch}"
49+
container_name = container_name_and_tag = args.name
5050
if args.base_image_name:
5151
container_name = f"{container_name}-base-image"
52-
skopeoargs.extend([f"oci-archive:{ociarchive}", f"docker://{container_name}"])
53-
print(subprocess.list2cmdline(skopeoargs))
54-
os.execvp('skopeo', skopeoargs)
52+
if ":" not in container_name_and_tag:
53+
container_name_and_tag = f"{container_name}:{latest_build}-{arch}"
54+
if ":" in container_name:
55+
container_name = container_name.rsplit(':')[0]
56+
with tempfile.NamedTemporaryFile(dir='tmp', prefix='push-container-digestfile') as df:
57+
skopeoargs.append(f"--digestfile={df.name}")
58+
skopeoargs.extend([f"oci-archive:{ociarchive}", f"docker://{container_name}"])
59+
print(subprocess.list2cmdline(skopeoargs))
60+
subprocess.check_call(skopeoargs)
61+
df.seek(0)
62+
digest = df.read().decode('utf-8').strip()
63+
# Inject the oscontainer with SHA256 into the build metadata
64+
meta['baseos-container'] = {'image': f"{container_name}@{digest}"}
65+
metapath_new = f"{metapath}.new"
66+
with open(metapath_new, 'w') as f:
67+
json.dump(meta, f, sort_keys=True)
68+
shutil.move(metapath_new, metapath)

0 commit comments

Comments
 (0)