Skip to content

Commit

Permalink
stages/ostree.deploy/container: add aleph file
Browse files Browse the repository at this point in the history
Similar to the aleph file created for builds of FCOS based on ostree
commit inputs, this adds an aleph file builds based on container image
inputs.
  • Loading branch information
lukewarmtemp committed Oct 31, 2023
1 parent 5579257 commit c509abd
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion stages/org.osbuild.ostree.deploy.container
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ Create an OSTree deployment[1] for a given container image input
"""

import os
import subprocess
import sys

import osbuild.api
from osbuild.util import containers, ostree
from osbuild.util.mnt import MountGuard

import json

CAPABILITIES = ["CAP_MAC_ADMIN"]

SCHEMA_2 = """
Expand Down Expand Up @@ -80,6 +83,14 @@ 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"]:
Expand All @@ -92,7 +103,7 @@ def make_fs_identifier(desc):
def ostree_container_deploy(tree, inputs, osname, target_imgref, kopts):
images = containers.parse_containers_input(inputs)
for image in images.values():
with containers.container_source(image) as (_, image_source):
with containers.container_source(image) as (image_name, image_source):
extra_args = []
imgref = f"ostree-unverified-image:{image_source}"

Expand All @@ -109,6 +120,25 @@ def ostree_container_deploy(tree, inputs, osname, target_imgref, 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\" }}"')

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
}

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


def main(tree, inputs, options):
osname = options["osname"]
Expand Down

0 comments on commit c509abd

Please sign in to comment.