Skip to content

Instantly share code, notes, and snippets.

@andymotta
Created May 1, 2020 00:24
Show Gist options
  • Save andymotta/c577cc9543e684be1e7b7688bf744446 to your computer and use it in GitHub Desktop.
Save andymotta/c577cc9543e684be1e7b7688bf744446 to your computer and use it in GitHub Desktop.
Get all image sizes across your GCP organization with tags
import google.auth
from google.auth.transport.requests import AuthorizedSession
### Global vars
REGISTRY_BASE = 'https://us.gcr.io/v2'
###
try:
credentials, project = google.auth.default(scopes=['https://www.googleapis.com/auth/cloud-platform'])
authed_session = AuthorizedSession(credentials)
except Exception as e:
print(e)
response = authed_session.get(f'{REGISTRY_BASE}/_catalog')
repos = response.json()['repositories']
for repo in repos:
url = f'{REGISTRY_BASE}/{repo}/tags/list'
tags = authed_session.get(url).json()
for digest_id, digest_meta in tags.get('manifest').items():
print(tags.get('name'),digest_meta['imageSizeBytes'],digest_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment