BuildSourceImage: expose "unpack" as subcommand
This may be a pattern we can do for some of the more useful functions. But for now, folks can build, push, etc. and once they skopeo copy an image to their host, they can ```bash ./BuildSourceImage unpack <src> <dest> ``` and it will be nicely exposed in the container build too Also included, exporting the defaults into the bats test for easier direct running. Perhaps we can move the srpm caching into bats too, so the Makefile target isn't strictly required. Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
e565987415
commit
8e438c7a6d
5 changed files with 82 additions and 5 deletions
|
@ -28,6 +28,10 @@ _usage() {
|
|||
echo -e " -D\t\tdebuging output. Can be set via DEBUG env variable"
|
||||
echo -e " -h\t\tthis usage information"
|
||||
echo -e " -v\t\tversion"
|
||||
echo -e ""
|
||||
echo -e " Subcommands:"
|
||||
echo -e " unpack\tUnpack an OCI layout to a rootfs directory"
|
||||
echo -e ""
|
||||
}
|
||||
|
||||
# sanity checks on startup
|
||||
|
@ -44,6 +48,23 @@ _init() {
|
|||
done
|
||||
}
|
||||
|
||||
# enable access to some of functions as subcommands!
|
||||
_subcommand() {
|
||||
local command="${1}"
|
||||
local ret
|
||||
|
||||
shift
|
||||
|
||||
case "${command}" in
|
||||
unpack)
|
||||
# (vb) i'd prefer this subcommand directly match the function name, but it isn't as pretty.
|
||||
unpack_img "${@}"
|
||||
ret=$?
|
||||
exit "${ret}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# _is_sourced tests whether this script is being source, or executed directly
|
||||
_is_sourced() {
|
||||
# https://unix.stackexchange.com/a/215279
|
||||
|
@ -292,6 +313,20 @@ unpack_img() {
|
|||
local unpack_dir="${2}"
|
||||
local ret
|
||||
|
||||
while getopts ":h" opts; do
|
||||
case "${opts}" in
|
||||
*)
|
||||
echo "$0 unpack <oci layout path> <unpack path>"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if [ -z "${image_dir}" ] || [ -z "${unpack_dir}" ] ; then
|
||||
_error "[unpack_img] blank arguments provided"
|
||||
fi
|
||||
|
||||
if [ -d "${unpack_dir}" ] ; then
|
||||
_rm_rf "${unpack_dir}"
|
||||
fi
|
||||
|
@ -336,9 +371,10 @@ unpack_img_bash() {
|
|||
return ${ret}
|
||||
fi
|
||||
|
||||
# Since we're landing the reference as an OCI layout, this mediaType is fairly predictable
|
||||
# TODO don't always assume +gzip
|
||||
layer_dgsts="$(jq '.layers[] | select(.mediaType == "application/vnd.oci.image.layer.v1.tar+gzip") | .digest' "${image_dir}"/blobs/"${mnfst_dgst/:/\/}" | tr -d \")"
|
||||
# TODO this will need to be refactored when we start seeing +zstd layers.
|
||||
# Then it will be better to no just get a list of digests, but maybe to
|
||||
# iterate on each descriptor independently?
|
||||
layer_dgsts="$(jq '.layers | map(select(.mediaType == "application/vnd.oci.image.layer.v1.tar+gzip"),select(.mediaType == "application/vnd.oci.image.layer.v1.tar"),select(.mediaType == "application/vnd.docker.image.rootfs.diff.tar.gzip")) | .[] | .digest' "${image_dir}"/blobs/"${mnfst_dgst/:/\/}" | tr -d \")"
|
||||
ret=$?
|
||||
if [ ${ret} -ne 0 ] ; then
|
||||
return ${ret}
|
||||
|
@ -1026,8 +1062,9 @@ main() {
|
|||
local work_dir
|
||||
|
||||
_init "${@}"
|
||||
_subcommand "${@}"
|
||||
|
||||
base_dir="$(pwd)/${ABV_NAME}"
|
||||
base_dir="${BASE_DIR:-$(pwd)/${ABV_NAME}}"
|
||||
# using the bash builtin to parse
|
||||
while getopts ":hlvDi:c:s:e:o:b:d:p:" opts; do
|
||||
case "${opts}" in
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue