Created
May 1, 2020 00:24
-
-
Save andymotta/c577cc9543e684be1e7b7688bf744446 to your computer and use it in GitHub Desktop.
Get all image sizes across your GCP organization with tags
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
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