Skip to content

Instantly share code, notes, and snippets.

@nickboldt
Last active January 21, 2025 16:40
Show Gist options
  • Save nickboldt/29562f64bf3dd287bbdf331ae0060db9 to your computer and use it in GitHub Desktop.
Save nickboldt/29562f64bf3dd287bbdf331ae0060db9 to your computer and use it in GitHub Desktop.
remove-image-tag-expiry
### THESE DON'T WORK -- you ned up with a tiny image that replaces your own :(
# much simpler from https://docs.redhat.com/en/documentation/red_hat_quay/3.12/html/use_red_hat_quay/oci-intro#annotation-parsing-oras
# never expire
oras push --annotation "quay.expires-after=" --annotation "expiration = " quay.io/rhdh-community/rhdh:tmp
# expire in 200 days
oras push --annotation "quay.expires-after=200d" --annotation "expiration = 200d" quay.io/rhdh-community/rhdh:tmp
### may fail if your image is more complex than a scratch image :(
# script to use oras to pull, edit, and push a revised image, removing the value of '.Labels."quay.expires-after"'
# to test, take a good image like 1.5-20, copy it, and then manipulate it
# oras cp "quay.io/rhdh/rhdh-operator-bundle:1.5-20" quay.io/rhdh/rhdh-operator-bundle:oras-tmp-test
TAG=oras-tmp-test
TMP_DIR=/tmp/oras-tmp
rm -fr "${TMP_DIR}"
# pull image, to local path
oras cp "quay.io/rhdh/rhdh-operator-bundle:${TAG}" --to-oci-layout "${TMP_DIR}" -v
# find the config file
for d in "${TMP_DIR}/blobs/sha256/"*; do
if [[ $(cat $d | grep mediaType) ]]; then
# cp -f $d "${TMP_DIR}/config.json"
continue
elif [[ $(cat $d | grep quay.expires-after) ]]; then
echo "Found config.json file: $d"
chmod +w $d
# decompress the json, transform it, then recompress it
jq -r '.' $d | sed -r -e 's@ \\"quay.expires-after\\"=\\".+\\"@@' -e '/ +"quay.expires-after":.+/d' | jq -c '.' > ${d}.2
mv -f ${d}.2 ${d}
chmod -w $d
cp $d "${TMP_DIR}-config.json"
else
mkdir -p "${TMP_DIR}/unpack"; tar xzf $d -C "${TMP_DIR}/unpack"
fi
done
# push the revised container back to the registry
cd "${TMP_DIR}/unpack"
oras push -v --config "${TMP_DIR}-config.json":application/vnd.oci.image.config.v1+json \
"quay.io/rhdh/rhdh-operator-bundle:${TAG}" . \
&& rm -fr "${TMP_DIR}" "${TMP_DIR}-config.json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment