From 19b9ecc797d93465a9d5ee40089d93256b0eedd7 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Thu, 26 Sep 2019 12:20:46 -0400 Subject: [PATCH] BuildSourceImage: use umoci for OCI layout, if present Signed-off-by: Vincent Batts --- BuildSourceImage.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/BuildSourceImage.sh b/BuildSourceImage.sh index f75a3ef..e607c08 100755 --- a/BuildSourceImage.sh +++ b/BuildSourceImage.sh @@ -410,12 +410,62 @@ push_img() { # sets up a basic new OCI layout, for an image with the provided (or default 'latest') tag # layout_new() { + local out_dir="${1}" + local image_tag="${2:-latest}" + local ret + + if [ -n "$(command -v umoci)" ] ; then + layout_new_umoci "${out_dir}" "${image_tag}" + ret=$? + if [ ${ret} -ne 0 ] ; then + return ${ret} + fi + else + layout_new_bash "${out_dir}" "${image_tag}" + ret=$? + if [ ${ret} -ne 0 ] ; then + return ${ret} + fi + fi +} + +# +# sets up new OCI layout, using `umoci` +# +layout_new_umoci() { + local out_dir="${1}" + local image_tag="${2:-latest}" + local ret + + # umoci expects the layout path to _not_ exist and will fail if it does exist + _rm_rf "${out_dir}" + + umoci init --layout "${out_dir}" + ret=$? + if [ "${ret}" -ne 0 ] ; then + return "${ret}" + fi + + # XXX currently does not support adding the rich annotations like I've done with the _bash + # https://github.com/openSUSE/umoci/issues/298 + umoci new --image "${out_dir}:${image_tag}" + ret=$? + if [ "${ret}" -ne 0 ] ; then + return "${ret}" + fi +} + +# +# sets up new OCI layout, all with bash and jq +# +layout_new_bash() { local out_dir="${1}" local image_tag="${2:-latest}" local config local mnfst local config_sum local mnfst_sum + local ret _mkdir_p "${out_dir}/blobs/sha256" echo '{"imageLayoutVersion":"1.0.0"}' > "${out_dir}/oci-layout" @@ -432,7 +482,15 @@ layout_new() { } ' config_sum=$(echo "${config}" | jq -c | tr -d '\n' | sha256sum | awk '{ ORS=""; print $1 }') + ret=$? + if [ "${ret}" -ne 0 ] ; then + return "${ret}" + fi echo "${config}" | jq -c | tr -d '\n' > "${out_dir}/blobs/sha256/${config_sum}" + ret=$? + if [ "${ret}" -ne 0 ] ; then + return "${ret}" + fi mnfst=' {