Skip to content

Instantly share code, notes, and snippets.

@nickboldt
Created January 22, 2021 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickboldt/ca5abf442ff1a22b3a2e3c7445eb7297 to your computer and use it in GitHub Desktop.
Save nickboldt/ca5abf442ff1a22b3a2e3c7445eb7297 to your computer and use it in GitHub Desktop.
obtainImageVersions.sh :: get server + registry images from an OCP 4.x CRW 2.x deployment and compare those digests to the latest in Quay
#!/bin/bash
NAMESPACE=$1
function obtainPodName(){
local podPartialName=$1
echo "$(oc get pods -n $NAMESPACE | grep $podPartialName | awk '{print $1;}' | awk 'NR==1{print $1}')"
}
function obtainImageVersion(){
local podName=$1
echo "$(oc get pod $podName -o json -n $NAMESPACE | jq .status.containerStatuses[].imageID)"
}
SERVER_POD_NAME=$(obtainPodName codeready)
DEVFILE_REGISTRY_POD_NAME=$(obtainPodName devfile-registry)
PLUGIN_REGISTRY_POD_NAME=$(obtainPodName plugin-registry)
SERVER_IMAGE=$(obtainImageVersion $SERVER_POD_NAME | tr -d "\"")
DEVFILE_REGISTRY_IMAGE=$(obtainImageVersion $DEVFILE_REGISTRY_POD_NAME | tr -d "\"")
PLUGIN_REGISTRY_IMAGE=$(obtainImageVersion $PLUGIN_REGISTRY_POD_NAME | tr -d "\"")
echo ""
echo "############ Deployed images in $NAMESPACE"
#echo ""
#echo "Server"
echo " $SERVER_IMAGE"
#echo ""
#echo "Devfile registry"
echo " $DEVFILE_REGISTRY_IMAGE"
#echo ""
#echo "Plugin registry"
echo " $PLUGIN_REGISTRY_IMAGE"
echo "############"
echo ""
getDigest () {
image=$1
tag=$2
skopeo inspect docker://${image}:${tag} | jq -r '.Digest' | sed -r -e "s#sha256#${image}@sha256#"
}
diffDigests () {
deployedImage=$1
quayImage=$2
deployedImageDigest=${deployedImage##*sha256}
quayImageDigest=${quayImage##*sha256}
# echo "deployedImageDigest=$deployedImageDigest"
# echo "quayImageDigest=$quayImageDigest"
if [[ "$deployedImageDigest" != "$quayImageDigest" ]]; then
echo ":: Digests are different!"
else
echo ":: Digests match!"
fi
}
echo "############ quay.io/crw :latest images"
#echo ""
#echo "Server"
SERVER_IMAGE_QUAY=$(getDigest quay.io/crw/server-rhel8 latest)
echo -n " https://${SERVER_IMAGE_QUAY/@/ @} "
diffDigests $SERVER_IMAGE $SERVER_IMAGE_QUAY
#echo ""
#echo "Devfile registry"
DEVFILE_REGISTRY_IMAGE_QUAY=$(getDigest quay.io/crw/devfileregistry-rhel8 latest)
echo -n " https://${DEVFILE_REGISTRY_IMAGE_QUAY/@/ @} "
diffDigests $DEVFILE_REGISTRY_IMAGE $DEVFILE_REGISTRY_IMAGE_QUAY
#echo ""
#echo "Plugin registry"
PLUGIN_REGISTRY_IMAGE_QUAY=$(getDigest quay.io/crw/pluginregistry-rhel8 latest)
echo -n " https://${PLUGIN_REGISTRY_IMAGE_QUAY/@/ @} "
diffDigests $PLUGIN_REGISTRY_IMAGE $PLUGIN_REGISTRY_IMAGE_QUAY
#echo ""
echo "############"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment