Skip to content

Commit

Permalink
Use ostree commit metadata
Browse files Browse the repository at this point in the history
Calls ostree-rs-ext api instead of skopeo to get
the container image metadata
  • Loading branch information
lukewarmtemp committed Nov 7, 2023
1 parent c45569a commit 30f4a58
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 28 deletions.
2 changes: 1 addition & 1 deletion osbuild/buildroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def run(self, argv, monitor, timeout=None, binds=None, readonly_binds=None, extr

# Import directories from the caller-provided root.
imports = ["usr"]
if self.mount_boot:
if True:
imports.insert(0, "boot")

for p in imports:
Expand Down
8 changes: 8 additions & 0 deletions osbuild/objectstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,18 @@ def init(self):
# with just /usr mounted from the host
usr = os.path.join(root, "usr")
os.makedirs(usr)
boot = os.path.join(root, "boot")
os.makedirs(boot)
etc = os.path.join(root, "etc")
os.makedirs(etc)

# ensure / is read-only
mount(root, root)
mount("/etc", etc)
mount("/usr", usr)
mount("/boot", boot)



@property
def tree(self) -> os.PathLike:
Expand Down
54 changes: 33 additions & 21 deletions stages/org.osbuild.ostree.deploy.container
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ SCHEMA_2 = """
}
"""

def skopeo_cli(*args):
"""Thin wrapper for running the skopeo CLI"""
args = list(args)
print("skopeo " + " ".join(args), file=sys.stderr)
return subprocess.run(["skopeo"] + args,
check=True,
capture_output=True,
text=True).stdout.rstrip().strip('\"')

def make_fs_identifier(desc):
for key in ["uuid", "label"]:
val = desc.get(key)
Expand All @@ -116,26 +107,47 @@ def ostree_container_deploy(tree, inputs, osname, target_imgref, kopts):
extra_args.append(f'--target-imgref={target_imgref}')

kargs = [f'--karg={v}' for v in kopts]

ostree.cli("container", "image", "deploy",
*extra_args, sysroot=tree, *kargs)

aleph_image_digest = skopeo_cli("inspect", f"{image_source}", "--format", '"{{ .Digest }}"')
aleph_image_revision = skopeo_cli("inspect", f"{image_source}", "--format", '"{{ index .Labels \"org.opencontainers.image.revision\" }}"')
aleph_image_source = skopeo_cli("inspect", f"{image_source}", "--format", '"{{ index .Labels \"org.opencontainers.image.source\" }}"')
aleph_image_version = skopeo_cli("inspect", f"{image_source}", "--format", '"{{ index .Labels \"org.opencontainers.image.version\" }}"')

container_data = subprocess.run(["ostree", "container", "image", "metadata", f"--repo={tree}/ostree/repo", f"{image_source}"],
check=True,
capture_output=True,
text=True).stdout.rstrip().strip('\"')

container_data_config = subprocess.run(["ostree", "container", "image", "metadata", f"--repo={tree}/ostree/repo", f"{image_source}", "--config"],
check=True,
capture_output=True,
text=True).stdout.rstrip().strip('\"')

container_data_json = json.loads(container_data)
container_data_config_json = json.loads(container_data_config)

aleph_digest = container_data_json['config']['digest']
aleph_ref = f"docker://{target_imgref}@{aleph_digest}"
aleph_ostree_version = container_data_config_json['config']['Labels']['version']
aleph_ostree_commit = container_data_config_json['config']['Labels']['ostree.commit']
aleph_platform = "" # still up for discussion
aleph_imgid = "" # still up for discussion
aleph_container_image = container_data_config_json['config']['Labels']

aleph_version_data = {
"osbuild-version": osbuild.__version__,
"image-name": image_name,
"image-digest": aleph_image_digest,
"image-revision": aleph_image_revision,
"image-source": aleph_image_source,
"image-version": aleph_image_version
"ref": aleph_ref,
"build": aleph_ostree_version,
"ostree-version": aleph_ostree_version,
"ostree-commit": aleph_ostree_commit,
"platform": aleph_platform,
"imgid": aleph_imgid,
"container-image": {
"image-name": image_name,
"image-digest": aleph_digest,
"image-labels": aleph_container_image
}
}

aleph_json = json.dumps(aleph_version_data, indent=4)
with open(tree + "/.coreos-aleph-version.json", "w") as outfile:
with open(tree + "/.osbuild-container-aleph.json", "w") as outfile:
outfile.write(aleph_json + "\n")
outfile.close()

Expand Down
21 changes: 15 additions & 6 deletions test/data/manifests/fedora-coreos-container.mpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ mpp-define-image:
pipelines:
- mpp-import-pipelines:
path: fedora-vars.ipp.yaml
- mpp-import-pipeline:
path: fedora-build-v2.ipp.yaml
id: build
# - mpp-import-pipeline:
# path: fedora-build-v2.ipp.yaml
# id: build
runner:
mpp-format-string: org.osbuild.fedora{release}
- name: image-tree
build: name:build
# build: name:build
source-epoch: 1659397331
stages:
- type: org.osbuild.ostree.init-fs
Expand Down Expand Up @@ -75,6 +75,15 @@ pipelines:
images:
- source: registry.gitlab.com/redhat/services/products/image-builder/ci/images/fedora-coreos
tag: stable
# - type: org.osbuild.ostree.aleph
# inputs:
# images:
# type: org.osbuild.containers
# origin: org.osbuild.source
# mpp-resolve-images:
# images:
# - source: registry.gitlab.com/redhat/services/products/image-builder/ci/images/fedora-coreos
# tag: stable
- type: org.osbuild.ostree.selinux
options:
deployment:
Expand All @@ -94,7 +103,7 @@ pipelines:
greenboot: false
ignition: true
- name: image
build: name:build
# build: name:build
stages:
- type: org.osbuild.truncate
options:
Expand Down Expand Up @@ -218,7 +227,7 @@ pipelines:
mpp-format-int: '{image.layout[''boot''].index}'
path: /grub2
- name: qcow2
build: name:build
# build: name:build
stages:
- type: org.osbuild.qemu
inputs:
Expand Down

0 comments on commit 30f4a58

Please sign in to comment.