Created
August 9, 2024 15:40
-
-
Save philroche/61312f1bd5b78bf9ddba03eadceff8db to your computer and use it in GitHub Desktop.
List images in local container image registry if using docker.io/library/registry image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set the registry URL | |
registry_url="http://localhost:5005" | |
# List repositories | |
repositories=$(curl -s "${registry_url}/v2/_catalog" | jq -r '.repositories[]') | |
# List tags for each repository | |
for repo in ${repositories}; do | |
echo "Repository: ${repo}" | |
curl -s "${registry_url}/v2/${repo}/tags/list" | jq -r '.tags[]' | while read tag; do | |
echo " Tag: ${tag}" | |
# Fetch the manifest or index | |
response=$(curl --silent --header "Accept: application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.v2+json" \ | |
--request GET ${registry_url}/v2/${repo}/manifests/${tag}) | |
response_including_headers=$(curl --silent --header "Accept: application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.v2+json" \ | |
--request GET ${registry_url}/v2/${repo}/manifests/${tag} --include) | |
# Check if it's an index or a manifest | |
if echo "${response_including_headers}" | grep -q "application/vnd.oci.image.index.v1+json"; then | |
# Parse index and fetch specific manifests (example might require modification based on your specific needs) | |
# This part depends on how you parse and what tool you use (e.g., jq, python, etc.) | |
tag_digest=$(echo "${response}" | jq --raw-output '.manifests[].digest') | |
echo -e "\t\tchecksum: ${tag_digest}" | |
image_size=$(echo "${response}" | jq --raw-output '.manifests[].size') | |
echo -e "\t\tsize: ${image_size}" | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment