Search code examples
google-cloud-storagegoogle-cloud-buildgoogle-cloud-registry

Google Cloud Container Registry - Check image size


I sent a docker file for Google Cloud Build. The build was created successfully.

The artifact URL is:

gcr.io/XXX/api/v1:abcdef017e651ee2b713828662801b36fc2c1

How I can check the image size? (MB\GB)


Solution

  • There isn't API for this. But I have a workaround, this Linux command line

    curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      https://gcr.io/v2/XXX/api/v1/manifests/abcdef017e651ee2b713828662801b36fc2c1 2>/dev/null | \
      jq ".layers[].size" | \
      awk '{s+=$1} END {print s}'
    

    Detail line by line

    1. Create a curl with a secure token from the GCLOUD CLI
    2. Get the image manifest, which describe all the layers and their size
    3. Get only the layers' sizes
    4. Sum the sizes

    -> Result is in Byte.