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 support for unsortable tags (SHA tags) and non-standard :latest tag #866

Open
wants to merge 1 commit into
base: devspaces-3-rhel-8
Choose a base branch
from
Open
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
33 changes: 26 additions & 7 deletions product/getLatestImageTags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ SHOWLOG=0 # show URL of the console log
PUSHTOQUAY=0 # utility method to pull then push to quay
PUSHTOQUAYTAGS="" # utility method to pull then push to quay (extra tags to push)
PUSHTOQUAYFORCE=0 # normally, don't repush a tag if it's already in the registry (to avoid re-timestamping it and updating tag history)
SORTED=0 # if 0, use the order of containers in the DS*_CONTAINERS_* strings above; if 1, sort alphabetically
CONTAINERS_LIST_SORTED=0 # if 0, use the order of containers in the DS*_CONTAINERS_* strings above; if 1, sort alphabetically
TAGS_SORTED="true" # usually true for semver tags, but if tags are SHAs rather than semver, use false
latestNext="latest"; if [[ $DS_VERSION == "3.y" ]] || [[ $DWNSTM_BRANCH == "devspaces-3-rhel-8" ]]; then latestNext="next "; fi

# cleanup /tmp files
Expand Down Expand Up @@ -198,7 +199,8 @@ while [[ "$#" -gt 0 ]]; do
'--errata') if [[ ! $CONTAINERS ]]; then CONTAINERS="${DS_CONTAINERS}"; fi; SHOWNVR=1; ERRATA_NUM="$2"; HIDE_MISSING=1; shift 1;;
'--tagonly') TAGONLY=1;;
'--log') SHOWLOG=1;;
'--sort') SORTED=1;;
'--sort'|'--sort-containers') CONTAINERS_LIST_SORTED=1;;
'--sort-tags') TAGS_SORTED="$2"; shift 1;;
'-h'|'--help') usage; cleanup_temp; exit 1;;
esac
shift 1
Expand Down Expand Up @@ -238,6 +240,7 @@ if [[ $VERBOSE -eq 1 ]]; then
echo "[DEBUG] candidateTag = $candidateTag"
echo "[DEBUG] containers = $CONTAINERS"
echo "[DEBUG] latestNext = $latestNext"
echo "[DEBUG] TAGS_SORTED = $TAGS_SORTED"
fi

if [[ ${REGISTRY} != "" ]]; then
Expand Down Expand Up @@ -277,7 +280,7 @@ fi
if [[ ${CONTAINERS} == "" ]]; then usage; cleanup_temp; exit 5; fi

# sort the container list
if [[ $SORTED -eq 1 ]]; then CONTAINERS=$(tr ' ' '\n' <<< "${CONTAINERS}" | sort | uniq); fi
if [[ $CONTAINERS_LIST_SORTED -eq 1 ]]; then CONTAINERS=$(tr ' ' '\n' <<< "${CONTAINERS}" | sort | uniq); fi

# special case!
if [[ ${SHOWNVR} -eq 1 ]]; then
Expand Down Expand Up @@ -366,15 +369,31 @@ for URLfrag in $CONTAINERS; do
# shellcheck disable=SC2001
QUERY="$(echo "$URL" | sed -e "s#.\+\(registry.redhat.io\|registry.access.redhat.com\)/#skopeo inspect ${ARCH_OVERRIDE} docker://${REGISTRYPRE}#g")${searchTag}"
if [[ $VERBOSE -eq 1 ]]; then
echo ""; echo -n "LATESTTAGs=\"\$($QUERY | jq -r .RepoTags[] | grep -E -v '${EXCLUDES}' | grep -E '${BASETAG}' | sort -V)\"; "
if [[ $TAGS_SORTED == "true" ]]; then
echo ""; echo -n "LATESTTAGs=\"\$($QUERY | jq -r .RepoTags[] | grep -E -v '${EXCLUDES}' | grep -E '${BASETAG}' | sort -V)\"; "
else
echo ""; echo -n "LATESTTAGs=\"\$($QUERY | jq -r .RepoTags[] | grep -E -v '${EXCLUDES}' | grep -E '${BASETAG}')\"; "
fi
fi
if [[ $TAGS_SORTED == "true" ]]; then
LATESTTAGs="$(${QUERY} 2>/dev/null | jq -r .RepoTags[] | grep -E -v "${EXCLUDES}" | grep -E "${BASETAG}" | sort -V)"
else
LATESTTAGs="$(${QUERY} 2>/dev/null | jq -r .RepoTags[] | grep -E -v "${EXCLUDES}" | grep -E "${BASETAG}")"
fi
LATESTTAGs="$(${QUERY} 2>/dev/null | jq -r .RepoTags[] | grep -E -v "${EXCLUDES}" | grep -E "${BASETAG}" | sort -V)"
if [[ ! ${LATESTTAGs} ]]; then # try again with -container suffix
QUERY="$(echo "${URL}-container" | sed -e "s#.\+\(registry.redhat.io\|registry.access.redhat.com\)/#skopeo inspect ${ARCH_OVERRIDE} docker://${REGISTRYPRE}#g")"
if [[ $VERBOSE -eq 1 ]]; then
echo ""; echo -n "LATESTTAGs=\"\$($QUERY | jq -r .RepoTags[] | grep -E -v '${EXCLUDES}' | grep -E '${BASETAG}' | sort -V)\"; "
if [[ $TAGS_SORTED == "true" ]]; then
echo ""; echo -n "LATESTTAGs=\"\$($QUERY | jq -r .RepoTags[] | grep -E -v '${EXCLUDES}' | grep -E '${BASETAG}' | sort -V)\"; "
else
echo ""; echo -n "LATESTTAGs=\"\$($QUERY | jq -r .RepoTags[] | grep -E -v '${EXCLUDES}' | grep -E '${BASETAG}')\"; "
fi
fi
if [[ $TAGS_SORTED == "true" ]]; then
LATESTTAGs="$(${QUERY} 2>/dev/null | jq -r .RepoTags[] | grep -E -v "${EXCLUDES}" | grep -E "${BASETAG}" | sort -V)"
else
LATESTTAGs="$(${QUERY} 2>/dev/null | jq -r .RepoTags[] | grep -E -v "${EXCLUDES}" | grep -E "${BASETAG}")"
fi
LATESTTAGs="$(${QUERY} 2>/dev/null | jq -r .RepoTags[] | grep -E -v "${EXCLUDES}" | grep -E "${BASETAG}" | sort -V)"
fi

# exclude freshmaker containers and/or sort and grab only the last n tags
Expand Down
6 changes: 5 additions & 1 deletion product/updateBaseImages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ if [[ $# -lt 1 ]]; then usage; exit; fi
BASETAG="."
# suppress latest and -source (RHEC); suppress next and nightly (quay)
EXCLUDES="latest|-source|next|nightly"
latestNext="latest" # or next
TAGS_SORTED="true" # usually true for semver tags, but if tags are SHAs rather than semver, use false
while [[ "$#" -gt 0 ]]; do
case $1 in
'-w') WORKDIR="$2"; shift 1;;
Expand All @@ -121,6 +123,8 @@ while [[ "$#" -gt 0 ]]; do
'-q') QUIET=1; shift 0;;
'-v') QUIET=0; VERBOSE=1; shift 0;;
'--check-recent-updates-only') QUIET=0; VERBOSE=1; checkrecentupdates; shift 0; exit;;
'--latestNext') latestNext="$2"; shift 1;;
'--sort-tags') TAGS_SORTED="$2"; shift 1;;
'--help'|'-h') usage; exit;;
*) OTHER="${OTHER} $1"; shift 0;;
esac
Expand Down Expand Up @@ -258,7 +262,7 @@ for d in $(find "${WORKDIR}/" -maxdepth "${MAXDEPTH}" -name "${DOCKERFILE}" | so
GLIT="/tmp/getLatestImageTags.sh -b ${SCRIPTS_BRANCH}"
if [[ $QUIET -eq 1 ]];then GLIT="${GLIT} -q"; fi
if [[ $VERBOSE -eq 1 ]];then GLIT="${GLIT} -v"; fi
GLIT="${GLIT} ${GLIT_REPOFLAG} -c ${FROMPREFIX} -x ${EXCLUDES} --tag ${GLIT_TAG}"
GLIT="${GLIT} ${GLIT_REPOFLAG} -c ${FROMPREFIX} -x ${EXCLUDES} --tag ${GLIT_TAG} --latestNext ${latestNext} --sort-tags ${TAGS_SORTED}"
if [[ $VERBOSE -eq 1 ]]; then echo "[DEBUG] $GLIT"; fi
LATESTTAG=$(${GLIT})
if [[ $VERBOSE -eq 1 ]]; then echo "[DEBUG] ============>"; echo "$LATESTTAG"; echo "[DEBUG] <============"; fi
Expand Down