Skip to content

Commit fcaa877

Browse files
committed
create-legacy-oscontainer: use runvm not nested containers
This also changes the push to create a oci-archive that will be pushed with `cosa push-container-manifest` by the pipeline. Renamed upload-oscontainer to create-legacy-oscontainer as the behavior has changed. The argument `--name` is not required anymore, before it was being used to pass a repository now it reads the name from the meta.json by default.
1 parent 3d742f1 commit fcaa877

15 files changed

+80
-56
lines changed

cmd/coreos-assembler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
// commands we'd expect to use in the local dev path
1515
var buildCommands = []string{"init", "fetch", "build", "run", "prune", "clean", "list"}
16-
var advancedBuildCommands = []string{"buildfetch", "buildupload", "oc-adm-release", "push-container", "upload-oscontainer", "buildextend-extensions"}
16+
var advancedBuildCommands = []string{"buildfetch", "buildupload", "oc-adm-release", "push-container", "create-legacy-oscontainer", "buildextend-extensions"}
1717
var buildextendCommands = []string{"aliyun", "aws", "azure", "digitalocean", "exoscale", "gcp", "ibmcloud", "kubevirt", "live", "metal", "metal4k", "nutanix", "openstack", "qemu", "secex", "virtualbox", "vmware", "vultr"}
1818
var utilityCommands = []string{"aws-replicate", "build-extensions-container", "compress", "generate-hashlist", "koji-upload", "kola", "push-container-manifest", "remote-build-container", "remote-prune", "remote-session", "sign", "update-variant"}
1919
var otherCommands = []string{"shell", "meta"}

docs/cosa.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ Those less commonly used commands are listed here:
7171
| [supermin-shell](https://github.com/coreos/coreos-assembler/blob/main/src/cmd-supermin-shell) | Get a supermin shell
7272
| [tag](https://github.com/coreos/coreos-assembler/blob/main/src/cmd-tag) | Operate on the tags in `builds.json`
7373
| [test-coreos-installer](https://github.com/coreos/coreos-assembler/blob/main/src/cmd-test-coreos-installer) | Automate an end-to-end run of coreos-installer with the metal image
74-
| [upload-oscontainer](https://github.com/coreos/coreos-assembler/blob/main/src/cmd-upload-oscontainer) | Upload an oscontainer (historical wrapper for `cosa oscontainer`)
74+
| [create-legacy-oscontainer](https://github.com/coreos/coreos-assembler/blob/main/src/cmd-create-legacy-oscontainer) | Create an oscontainer oci-archive (historical wrapper for `cosa oscontainer`)

gangplank/internal/ocp/worker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ func pushOstreeToRegistry(ctx ClusterContext, push *spec.Registry, build *cosa.B
394394

395395
// pushArgs invokes cosa upload code which creates a named tag
396396
pushArgs := []string{
397-
"/usr/bin/coreos-assembler", "upload-oscontainer",
397+
"/usr/bin/coreos-assembler", "create-legacy-oscontainer",
398398
fmt.Sprintf("--name=%s", pushPath),
399399
}
400400
// copy the pushed image to the expected tag

mantle/vendor/github.com/coreos/coreos-assembler/pkg/builds/build.go

+2-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mantle/vendor/github.com/coreos/coreos-assembler/pkg/builds/cosa_v1.go

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mantle/vendor/github.com/coreos/coreos-assembler/pkg/builds/schema_doc.go

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/builds/cosa_v1.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package builds
22

33
// generated by 'make schema'
4-
// source hash: 144450d458f89f637ca487d353af3dfd60096ddbf3179da8e2b42b2bd2d0a6eb
4+
// source hash: 3508b2f150e72b8e24151d870789809cf4070cec6b4716966a4e8bc585e0c5f1
55

66
type AdvisoryDiff []AdvisoryDiffItems
77

@@ -101,6 +101,7 @@ type BuildArtifacts struct {
101101
Iso *Artifact `json:"iso,omitempty"`
102102
Kernel *Artifact `json:"kernel,omitempty"`
103103
KubeVirt *Artifact `json:"kubevirt,omitempty"`
104+
LegacyOscontainer *Artifact `json:"legacy-oscontainer,omitempty"`
104105
LiveInitramfs *Artifact `json:"live-initramfs,omitempty"`
105106
LiveIso *Artifact `json:"live-iso,omitempty"`
106107
LiveKernel *Artifact `json:"live-kernel,omitempty"`

pkg/builds/schema_doc.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Generated by ./generate-schema.sh
2-
// Source hash: 144450d458f89f637ca487d353af3dfd60096ddbf3179da8e2b42b2bd2d0a6eb
2+
// Source hash: 3508b2f150e72b8e24151d870789809cf4070cec6b4716966a4e8bc585e0c5f1
33
// DO NOT EDIT
44

55
package builds
@@ -446,6 +446,7 @@ var generatedSchemaJSON = `{
446446
"digitalocean",
447447
"exoscale",
448448
"extensions-container",
449+
"legacy-oscontainer",
449450
"gcp",
450451
"kubevirt",
451452
"ibmcloud",
@@ -492,6 +493,12 @@ var generatedSchemaJSON = `{
492493
"title": "extensions-container",
493494
"$ref": "#/definitions/artifact"
494495
},
496+
"legacy-oscontainer": {
497+
"$id": "#/properties/images/properties/legacy-oscontainer",
498+
"type": "object",
499+
"title": "legacy-oscontainer",
500+
"$ref": "#/definitions/artifact"
501+
},
495502
"qemu": {
496503
"$id": "#/properties/images/properties/qemu",
497504
"type": "object",

src/build-legacy-oscontainer.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC1091
3+
set -euo pipefail
4+
# Start VM and call buildah
5+
. /usr/lib/coreos-assembler/cmdlib.sh
6+
prepare_build
7+
runvm -- /usr/lib/coreos-assembler/oscontainer-deprecated-legacy-format.py "$@"

src/cmd-upload-oscontainer-deprecated-legacy-format renamed to src/cmd-create-legacy-oscontainer

+26-27
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,13 @@ import os
1212
import shutil
1313
import subprocess
1414
import sys
15+
from cosalib.cmdlib import sha256sum_file
1516

1617
cosa_dir = os.path.dirname(os.path.abspath(__file__))
1718
sys.path.insert(0, cosa_dir)
1819

1920
from cosalib import cmdlib
2021

21-
parser = argparse.ArgumentParser()
22-
parser.add_argument("--arch-tag", help="append arch name to push tag",
23-
action='store_true')
24-
parser.add_argument("--name", help="oscontainer name",
25-
action='store', required=True)
26-
parser.add_argument("--from", help="Base image", default='scratch',
27-
dest='from_image')
28-
parser.add_argument("--format", help="Format to use for push")
29-
parser.add_argument("--add-directory", help="Copy in all content from referenced directory DIR",
30-
metavar='DIR', action='append', default=[])
31-
32-
args = parser.parse_args()
3322

3423
with open('builds/builds.json') as f:
3524
builds = json.load(f)['builds']
@@ -43,6 +32,20 @@ metapath = f"{latest_build_path}/meta.json"
4332
with open(metapath) as f:
4433
meta = json.load(f)
4534

35+
name = meta['name'] + '-' + meta['buildid'] + '-oscontainer.' + arch + '.ociarchive'
36+
parser = argparse.ArgumentParser()
37+
parser.add_argument("--arch-tag", help="append arch name to push tag",
38+
action='store_true')
39+
parser.add_argument("--name", help="oscontainer name",
40+
action='store', default=f'{name}')
41+
parser.add_argument("--from", help="Base image", default='scratch',
42+
dest='from_image')
43+
parser.add_argument("--format", help="Format to use for push")
44+
parser.add_argument("--add-directory", help="Copy in all content from referenced directory DIR",
45+
metavar='DIR', action='append', default=[])
46+
47+
args = parser.parse_args()
48+
4649
# for backcompat, we auto-build extensions if they're missing
4750
if os.path.exists('src/config/extensions.yaml'):
4851
if 'extensions' not in meta:
@@ -101,19 +104,15 @@ if args.arch_tag:
101104
# every time we want to poll.
102105
# TODO: Remove --from
103106
digestfile = "tmp/oscontainer-digest"
104-
# We need to pass the auth file from the unpriv user to the root process
105-
cosa_argv = ['sudo', '--preserve-env=container,DISABLE_TLS_VERIFICATION,SSL_CERT_DIR,SSL_CERT_FILE,REGISTRY_AUTH_FILE,OSCONTAINER_CERT_DIR']
106-
authfile = os.environ.get("REGISTRY_AUTH_FILE", os.path.expanduser('~/.docker/config.json'))
107-
if not os.path.isfile(authfile):
108-
raise SystemExit(f"Missing {authfile}")
109-
os.environ['REGISTRY_AUTH_FILE'] = authfile
110-
cosa_argv.extend(['/usr/lib/coreos-assembler/oscontainer.py', '--workdir=./tmp', 'build', f"--from={args.from_image}"])
107+
print("Entering vm to build oscontainer for build: {}".format(latest_build))
108+
109+
cosa_argv = (['/usr/lib/coreos-assembler/build-legacy-oscontainer.sh', '--workdir=./tmp', 'build', f'--from={args.from_image}'])
111110
for d in args.add_directory:
112-
cosa_argv.append(f"--add-directory={d}")
113-
cosa_argv.append(f"--display-name={display_name}")
111+
cosa_argv.append(f'--add-directory="{d}"')
112+
cosa_argv.append(f'--display-name="{display_name}"')
114113
if 'labeled-packages' in configyaml:
115114
pkgs = ' '.join(configyaml['labeled-packages'])
116-
cosa_argv.append(f"--labeled-packages={pkgs}")
115+
cosa_argv.append(f'--labeled-packages="{pkgs}"')
117116
if args.format is not None:
118117
cosa_argv.append(f'--format={args.format}')
119118
subprocess.check_call(cosa_argv +
@@ -122,12 +121,12 @@ subprocess.check_call(cosa_argv +
122121
meta['ostree-commit'],
123122
osc_name_and_tag])
124123

125-
with open(digestfile) as f:
126-
osc_digest = f.read().strip()
127-
128124
# Inject the oscontainer with SHA256 into the build metadata
129-
meta['oscontainer'] = {'image': args.name,
130-
'digest': osc_digest}
125+
oci_archive = f"{latest_build_path}/{args.name}"
126+
meta['images']['legacy-oscontainer'] = {'path': args.name,
127+
'sha256': sha256sum_file(oci_archive),
128+
'size': os.path.getsize(oci_archive),
129+
"skip-compression": True}
131130
metapath_new = f"{metapath}.new"
132131
with open(metapath_new, 'w') as f:
133132
json.dump(meta, f, sort_keys=True)

src/cmd-push-container

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python3 -u
22
# Upload the container to a registry. Note this
3-
# is distinct from `upload-oscontainer` which
3+
# is distinct from `create-legacy-oscontainer` which
44
# only applies to (hopefully soon only older)
55
# versions of RHCOS but not FCOS.
66

src/cmd-upload-oscontainer

-1
This file was deleted.

src/oscontainer-deprecated-legacy-format.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def oscontainer_build(containers_storage, tmpdir, src, ref, image_name_and_tag,
108108
else:
109109
ostree_version = None
110110

111-
buildah_base_argv = buildah_base_args(containers_storage)
111+
buildah_base_argv = buildah_base_args(None)
112112

113113
# In general, we just stick with the default tmpdir set up. But if a
114114
# workdir is provided, then we want to be sure that all the heavy I/O work
@@ -207,28 +207,25 @@ def oscontainer_build(containers_storage, tmpdir, src, ref, image_name_and_tag,
207207
subprocess.call(buildah_base_argv + ['rm', bid], stdout=subprocess.DEVNULL)
208208

209209
if push:
210-
print("Pushing container")
210+
print("Saving container to oci-archive")
211211
podCmd = buildah_base_argv + ['push']
212-
if not tls_verify:
213-
tls_arg = '--tls-verify=false'
214-
else:
215-
tls_arg = '--tls-verify'
216-
podCmd.append(tls_arg)
217-
218-
if authfile != "":
219-
podCmd.append("--authfile={}".format(authfile))
220-
221-
if cert_dir != "":
222-
podCmd.append("--cert-dir={}".format(cert_dir))
223212

224213
if digestfile is not None:
225214
podCmd.append(f'--digestfile={digestfile}')
226215

227216
if pushformat is not None:
228217
podCmd.append(f'--format={pushformat}')
229218

219+
# Historically upload-oscontainer would require --name which was in our
220+
# pipeline a repository URL. Going forward create-legacy-oscontainer
221+
# just creates an oci-archive and a url is not a valid name/tag combination.
222+
if '/' in image_name_and_tag:
223+
image_name_and_tag = image_name_and_tag.rsplit('/', 1)[1]
224+
230225
podCmd.append(image_name_and_tag)
231226

227+
podCmd.append(f'oci-archive:{builddir}/{image_name_and_tag}')
228+
232229
cmdlib.runcmd(podCmd)
233230
elif digestfile is not None:
234231
inspect = run_get_json(buildah_base_argv + ['inspect', image_name_and_tag])[0]

src/v1.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@
440440
"digitalocean",
441441
"exoscale",
442442
"extensions-container",
443+
"legacy-oscontainer",
443444
"gcp",
444445
"kubevirt",
445446
"ibmcloud",
@@ -486,6 +487,12 @@
486487
"title": "extensions-container",
487488
"$ref": "#/definitions/artifact"
488489
},
490+
"legacy-oscontainer": {
491+
"$id": "#/properties/images/properties/legacy-oscontainer",
492+
"type": "object",
493+
"title": "legacy-oscontainer",
494+
"$ref": "#/definitions/artifact"
495+
},
489496
"qemu": {
490497
"$id": "#/properties/images/properties/qemu",
491498
"type": "object",
@@ -970,4 +977,4 @@
970977
"$ref": "#/definitions/image"
971978
}
972979
}
973-
}
980+
}

src/vmdeps.txt

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ selinux-policy selinux-policy-targeted policycoreutils
2020
# coreos-assembler
2121
python3 python3-gobject-base buildah podman skopeo iptables iptables-libs
2222

23+
# legacy-oscontainer
24+
python3-pyyaml python3-botocore python3-flufl-lock python3-tenacity
25+
2326
# luks
2427
cryptsetup
2528
# filesystems/storage

0 commit comments

Comments
 (0)