108 lines
2.6 KiB
Bash
108 lines
2.6 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
## depracted code for moving containers (what skopeo does)
|
||
|
|
||
|
#
|
||
|
# copy an image from one location to another
|
||
|
#
|
||
|
push_img() {
|
||
|
local src="${1}"
|
||
|
local dst="${2}"
|
||
|
|
||
|
_debug "pushing image ${src} to ${dst}"
|
||
|
## TODO: check for authfile, creds, and whether it's an insecure registry
|
||
|
skopeo copy --dest-tls-verify=false "$(ref_prefix "${src}")" "$(ref_prefix "${dst}")" # XXX for demo only
|
||
|
#skopeo copy "$(ref_prefix "${src}")" "$(ref_prefix "${dst}")"
|
||
|
ret=$?
|
||
|
return $ret
|
||
|
}
|
||
|
|
||
|
|
||
|
#
|
||
|
# call out to registry for the image reference's digest checksum
|
||
|
#
|
||
|
fetch_img_digest() {
|
||
|
local ref="${1}"
|
||
|
local dgst
|
||
|
local ret
|
||
|
|
||
|
## TODO: check for authfile, creds, and whether it's an insecure registry
|
||
|
dgst=$(skopeo inspect "$(ref_prefix "${ref}")" | jq .Digest | tr -d \")
|
||
|
ret=$?
|
||
|
if [ $ret -ne 0 ] ; then
|
||
|
echo "ERROR: check the image reference: ${ref}" >&2
|
||
|
return $ret
|
||
|
fi
|
||
|
|
||
|
echo -n "${dgst}"
|
||
|
}
|
||
|
|
||
|
|
||
|
#
|
||
|
# an inline prefixer for containers/image tools
|
||
|
#
|
||
|
ref_prefix() {
|
||
|
local ref="${1}"
|
||
|
local pfxs
|
||
|
local ret
|
||
|
|
||
|
# get the supported prefixes of the current version of skopeo
|
||
|
mapfile -t pfxs < <(skopeo copy --help | grep -A1 "Supported transports:" | grep -v "Supported transports" | sed 's/, /\n/g')
|
||
|
ret=$?
|
||
|
if [ ${ret} -ne 0 ] ; then
|
||
|
return ${ret}
|
||
|
fi
|
||
|
|
||
|
for pfx in "${pfxs[@]}" ; do
|
||
|
if echo "${ref}" | grep -q "^${pfx}:" ; then
|
||
|
# break if we match a known prefix
|
||
|
echo "${ref}"
|
||
|
return 0
|
||
|
fi
|
||
|
done
|
||
|
# else default
|
||
|
echo "docker://${ref}"
|
||
|
}
|
||
|
|
||
|
#
|
||
|
# pull down the image to an OCI layout
|
||
|
# arguments: image ref
|
||
|
# returns: path:tag to the OCI layout
|
||
|
#
|
||
|
# any commands should only output to stderr, so that the caller can receive the
|
||
|
# path reference to the OCI layout.
|
||
|
#
|
||
|
fetch_img() {
|
||
|
local ref="${1}"
|
||
|
local dst="${2}"
|
||
|
local base
|
||
|
local tag
|
||
|
local dgst
|
||
|
local from
|
||
|
local ret
|
||
|
|
||
|
_mkdir_p "${dst}"
|
||
|
|
||
|
base="$(parse_img_base "${ref}")"
|
||
|
tag="$(parse_img_tag "${ref}")"
|
||
|
dgst="$(parse_img_digest "${ref}")"
|
||
|
from=""
|
||
|
# skopeo currently only support _either_ tag _or_ digest, so we'll be specific.
|
||
|
if [ -n "${dgst}" ] ; then
|
||
|
from="$(ref_prefix "${base}")@${dgst}"
|
||
|
else
|
||
|
from="$(ref_prefix "${base}"):${tag}"
|
||
|
fi
|
||
|
|
||
|
## TODO: check for authfile, creds, and whether it's an insecure registry
|
||
|
## destination name must have the image tag included (umoci expects it)
|
||
|
skopeo \
|
||
|
copy \
|
||
|
"${from}" \
|
||
|
"oci:${dst}:${tag}" >&2
|
||
|
ret=$?
|
||
|
if [ ${ret} -ne 0 ] ; then
|
||
|
return ${ret}
|
||
|
fi
|
||
|
echo -n "${dst}:${tag}"
|
||
|
}
|