mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-01-12 07:59:29 -05:00
hack: list versions with find-image script
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
c741ccfb4b
commit
65f7958430
@ -3,20 +3,37 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
# Usage: find-image.sh
|
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
shopt -s inherit_errexit
|
shopt -s inherit_errexit
|
||||||
|
|
||||||
ref="-"
|
ref="-"
|
||||||
stream="stable"
|
stream="stable"
|
||||||
|
json=false
|
||||||
|
cdn_url="https://cdn.confidential.cloud"
|
||||||
|
|
||||||
|
function usage() {
|
||||||
|
cat <<'EOF'
|
||||||
|
Usage: find-image.sh [options] [command]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-r, --ref <ref> Ref to search for (default: "-")
|
||||||
|
-s, --stream <stream> Stream to search for (default: "stable")
|
||||||
|
--json Output JSON instead of shortname(s)
|
||||||
|
--help Show this help
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
latest Find latest image for ref and stream
|
||||||
|
list List all images for ref and stream
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
POSITIONAL_ARGS=()
|
POSITIONAL_ARGS=()
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-r | --ref)
|
-r | --ref)
|
||||||
ref="$2"
|
# Canonicalize ref format (e.g. "feat/foo/bar" -> "feat-foo-bar")
|
||||||
|
ref=$(echo -n "$2" | tr -c '[:alnum:]' '-')
|
||||||
shift # past argument
|
shift # past argument
|
||||||
shift # past value
|
shift # past value
|
||||||
;;
|
;;
|
||||||
@ -25,8 +42,18 @@ while [[ $# -gt 0 ]]; do
|
|||||||
shift # past argument
|
shift # past argument
|
||||||
shift # past value
|
shift # past value
|
||||||
;;
|
;;
|
||||||
|
--json)
|
||||||
|
json=true
|
||||||
|
shift # past argument
|
||||||
|
;;
|
||||||
|
--help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
-*)
|
-*)
|
||||||
echo "Unknown option $1"
|
echo "Unknown option $1"
|
||||||
|
echo
|
||||||
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -38,25 +65,98 @@ done
|
|||||||
|
|
||||||
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
|
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
|
||||||
|
|
||||||
ref=$(echo -n "${ref}" | tr -c '[:alnum:]' '-')
|
# shortname <ref> <stream> <version>
|
||||||
|
function shortname() {
|
||||||
|
shortname=""
|
||||||
|
|
||||||
base_url="https://cdn.confidential.cloud"
|
if [[ ${ref} != "-" ]]; then
|
||||||
latest_path="constellation/v1/ref/${ref}/stream/${stream}/versions/latest/image.json"
|
shortname+="ref/${1}/"
|
||||||
latest_url="${base_url}/${latest_path}"
|
fi
|
||||||
latest_status=$(curl -s -o /dev/null -w "%{http_code}" "${latest_url}")
|
|
||||||
if [[ ${latest_status} != "200" ]]; then
|
|
||||||
echo "No image found for ref ${ref} and stream ${stream} (${latest_status})"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
latest_version=$(curl -sL "${latest_url}" | jq -r '.version')
|
|
||||||
|
|
||||||
shortname=""
|
if [[ ${stream} != "stable" ]]; then
|
||||||
if [[ ${ref} != "-" ]]; then
|
shortname+="stream/${2}/"
|
||||||
shortname+="ref/${ref}/"
|
fi
|
||||||
fi
|
|
||||||
if [[ ${stream} != "stable" ]]; then
|
|
||||||
shortname+="stream/${stream}/"
|
|
||||||
fi
|
|
||||||
shortname+="${latest_version}"
|
|
||||||
|
|
||||||
echo "${shortname}"
|
shortname+="${3}"
|
||||||
|
|
||||||
|
echo "${shortname}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function latest() {
|
||||||
|
latest_path="constellation/v1/ref/${ref}/stream/${stream}/versions/latest/image.json"
|
||||||
|
latest_url="${cdn_url}/${latest_path}"
|
||||||
|
|
||||||
|
latest_status=$(curl -s -o /dev/null -w "%{http_code}" "${latest_url}")
|
||||||
|
if [[ ${latest_status} != "200" ]]; then
|
||||||
|
echo "[Error] No image found for ref ${ref} and stream ${stream} (${latest_status})"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
latest_json=$(curl -sL "${latest_url}")
|
||||||
|
|
||||||
|
if [[ ${json} == true ]]; then
|
||||||
|
jq <<<"${latest_json}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
latest_version=$(echo "${latest_json}" | jq -r '.version')
|
||||||
|
|
||||||
|
shortname "${ref}" "${stream}" "${latest_version}"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function list() {
|
||||||
|
major="v2"
|
||||||
|
list_path="constellation/v1/ref/${ref}/stream/${stream}/versions/major/${major}/image.json"
|
||||||
|
list_url="${cdn_url}/${list_path}"
|
||||||
|
|
||||||
|
list_status=$(curl -s -o /dev/null -w "%{http_code}" "${list_url}")
|
||||||
|
if [[ ${list_status} != "200" ]]; then
|
||||||
|
echo "[Error] No minor image list found for ref ${ref} and stream ${stream} and version ${major} (${list_status})"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
minor_list=$(curl -sL "${list_url}" | jq -r '.versions[]')
|
||||||
|
|
||||||
|
for minor in ${minor_list}; do
|
||||||
|
list_path="constellation/v1/ref/${ref}/stream/${stream}/versions/minor/${minor}/image.json"
|
||||||
|
list_url="${cdn_url}/${list_path}"
|
||||||
|
|
||||||
|
list_status=$(curl -s -o /dev/null -w "%{http_code}" "${list_url}")
|
||||||
|
if [[ ${list_status} != "200" ]]; then
|
||||||
|
echo "[Error] No patch image list found for ref ${ref} and stream ${stream} and version ${minor} (${list_status})"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
patch_list="${patch_list-""} $(curl -sL "${list_url}" | jq -r '.versions[]')"
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${json} == true ]]; then
|
||||||
|
out="{}"
|
||||||
|
out=$(jq <<<"${out}" --arg ref "${ref}" '.ref = $ref')
|
||||||
|
out=$(jq <<<"${out}" --arg stream "${stream}" '.stream = $stream')
|
||||||
|
for patch in ${patch_list}; do
|
||||||
|
out=$(jq <<<"${out}" --arg patch "${patch}" '.versions += [$patch]')
|
||||||
|
done
|
||||||
|
jq <<<"${out}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
for version in ${patch_list}; do
|
||||||
|
shortname "${ref}" "${stream}" "${version}"
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
case ${1-"latest"} in
|
||||||
|
"list")
|
||||||
|
list
|
||||||
|
;;
|
||||||
|
"latest")
|
||||||
|
latest
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown command $1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user