Skip to content

Commit

Permalink
Add deploy-via-container and container-imgref keys for image.yaml
Browse files Browse the repository at this point in the history
This builds on the `image-format: oci` key to switch to using
the new ostree-container code to do the deployment (via rpm-ostree).

Unlike the above though, this is not something we can turn on
by default until we intend to hard cut over to fetching updates
via containers.

The intention is to use this to produce image builds that are
initially provisioned via a container image so that we can more
easily experiment with the "container native" flow.

A side note; I suspect this will indirectly fix
openshift/os#594
because now we're opening a single large file and pulling that
over virtio instead of lots of smaller files.
  • Loading branch information
cgwalters committed Nov 9, 2021
1 parent d1eefa4 commit faed8f3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
8 changes: 8 additions & 0 deletions src/cmd-buildextend-metal
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ cat image-default.json "${image_json}" | jq -s add > image-configured.json
# We do some extra handling of the rootfs here; it feeds into size estimation.
rootfs_type=$(jq -re .rootfs < image-configured.json)

deploy_container=
container_imgref=$(jq -r '.["container-imgref"]//""' < image-configured.json)
if test -n "${container_imgref}" || jq -re '.["deploy-via-container"]' < image-configured.json >/dev/null; then
deploy_container=ostree-unverified-image:oci-archive:$builddir/$(meta_key images.ostree.path)
fi

# fs-verity requires block size = page size. We need to take that into account
# in the disk size estimation due to higher fragmentation on larger blocks.
BLKSIZE=""
Expand Down Expand Up @@ -204,6 +210,8 @@ cat >image-dynamic.json << EOF
"osname": "${name}",
"buildid": "${build}",
"imgid": "${img}",
"deploy-container": "${deploy_container}",
"container-imgref": "${container_imgref}",
"ostree-commit": "${commit}",
"ostree-ref": "${ref}",
"ostree-repo": "${ostree_repo}"
Expand Down
47 changes: 34 additions & 13 deletions src/create_disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ commit=$(getconfig "ostree-commit")
ref=$(getconfig "ostree-ref")
# We support not setting a remote name (used by RHCOS)
remote_name=$(getconfig_def "ostree-remote" "")
deploy_container=$(getconfig "deploy-container" "")
container_imgref=$(getconfig "container-imgref" "")
os_name=$(getconfig "osname")
rootfs_size=$(getconfig "rootfs-size")
buildid=$(getconfig "buildid")
Expand Down Expand Up @@ -249,26 +251,45 @@ fi
ostree admin init-fs --modern $rootfs
# Initialize the "stateroot"
ostree admin os-init "$os_name" --sysroot $rootfs

# Propagate flags into target repository
if [ "${rootfs_type}" = "ext4verity" ]; then
ostree config --repo=$rootfs/ostree/repo set ex-fsverity.required 'true'
fi
time ostree pull-local --repo $rootfs/ostree/repo "$ostree" "$commit"
if test -n "${remote_name}"; then
deploy_ref="${remote_name}:${ref}"
ostree refs --repo $rootfs/ostree/repo --create "${deploy_ref}" "${commit}"
else
deploy_ref=$commit
fi

# Compute kargs
# Note that $ignition_firstboot is interpreted by grub at boot time,
# *not* the shell here. Hence the backslash escape.
allkargs="$extrakargs \$ignition_firstboot"
kargsargs=""
for karg in $allkargs
do
kargsargs+="--karg-append=$karg "
done
ostree admin deploy "${deploy_ref}" --sysroot $rootfs --os "$os_name" $kargsargs

if test -n "${deploy_container}"; then
kargsargs=""
for karg in $allkargs
do
kargsargs+="--karg=$karg "
done
rpm-ostree ex-container image deploy --imgref "${deploy_container}" \
${container_imgref:+--target-imgref $container_imgref} \
--stateroot "$os_name" --sysroot $rootfs $kargsargs
else
# Pull the commit
time ostree pull-local --repo $rootfs/ostree/repo "$ostree" "$commit"
# Deploy it, using an optional remote prefix
if test -n "${remote_name}"; then
deploy_ref="${remote_name}:${ref}"
ostree refs --repo $rootfs/ostree/repo --create "${deploy_ref}" "${commit}"
else
deploy_ref=$commit
fi
kargsargs=""
for karg in $allkargs
do
kargsargs+="--karg-append=$karg "
done
ostree admin deploy "${deploy_ref}" --sysroot $rootfs --os "$os_name" $kargsargs
fi
# Note that at the current time, this only supports deploying non-layered
# container images; xref https://github.com/ostreedev/ostree-rs-ext/issues/143
deploy_root="$rootfs/ostree/deploy/${os_name}/deploy/${commit}.0"
test -d "${deploy_root}"

Expand Down
4 changes: 4 additions & 0 deletions src/image-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
bootfs: "ext4"
rootfs: "xfs"
grub-script: "/usr/lib/coreos-assembler/grub.cfg"
# True if we should use `rpm-ostree ex-container image deploy`
deploy-via-container: false
# Set this to a target container reference, e.g. ostree-unverified-registry:quay.io/example/os:latest
# container-imgref: ""

0 comments on commit faed8f3

Please sign in to comment.