Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deploy-via-container key for image.yaml #2523

Merged
merged 2 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
50 changes: 36 additions & 14 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 @@ -247,27 +249,47 @@ fi
# Now that we have the basic disk layout, initialize the basic
# OSTree layout, load in the ostree commit and deploy it.
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
ostree admin os-init "$os_name" --sysroot $rootfs

# 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: ""