|
7 | 7 | import argparse
|
8 | 8 | import json
|
9 | 9 | import os
|
| 10 | +import tempfile |
| 11 | +import shutil |
10 | 12 | import subprocess
|
11 | 13 | import sys
|
12 | 14 |
|
@@ -44,11 +46,23 @@ if args.authfile is not None:
|
44 | 46 | skopeoargs.extend(['--authfile', args.authfile])
|
45 | 47 | if args.format is not None:
|
46 | 48 | 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 |
50 | 50 | if args.base_image_name:
|
51 | 51 | 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