Skip to content

Instantly share code, notes, and snippets.

@vdice
Created March 13, 2024 23:54
Show Gist options
  • Save vdice/7a545cb7b9ad8b6144a3292741b49c29 to your computer and use it in GitHub Desktop.
Save vdice/7a545cb7b9ad8b6144a3292741b49c29 to your computer and use it in GitHub Desktop.
Spin App OCI Diagnostics

Spin App as OCI image diagnostics

Publish and pull app

Navigate to app directory and perform a roundtrip push/pull of the app to/from a registry (here using ttl.sh):

export IMAGE_NAME=$(uuidgen | tr '[:upper:]' '[:lower:]')
spin registry push ttl.sh/${IMAGE_NAME}:1h
spin registry pull ttl.sh/${IMAGE_NAME}:1h

Navigate to registry cache

Navigate to Spin's registry cache at $XDG_CACHE_HOME. On Mac, this is ~/Library/Caches/spin/registry

cd ~/Library/Caches/spin/registry

High-level layout can be seen.

$ tree -L 1
.
├── data
├── manifests
└── wasm

4 directories, 0 files
  • data holds data (eg static asset) layers
  • manifests holds OCI manifest (manifest.json) and Spin's locked app config (config.json) under image reference path
  • wasm holds wasm component layers

We're interested in the manifests under the sub-dir for our app in manifests, eg:

$ ls -l manifests/ttl.sh/bc445bdd-e571-4966-ad25-280d83b178b4/1h
total 24
-rw-r--r-- 1 vdice staff 10880 Mar 13 16:08 config.json
-rw-r--r-- 1 vdice staff 10270 Mar 13 16:08 manifest.json

config.json

The locked app config that Spin builds (config.json) contains Spin app metadata, trigger config, component listing along with the list of layers included with each, etc.

We can get a view into precisely which layers/assets are bundled in each component via:

cat manifests/ttl.sh/bc445bdd-e571-4966-ad25-280d83b178b4/1h/config.json | jq -r '.components'

manifest.json

The OCI manifest (manifest.json) contains a listing of all the layers, their types and their sizes:

$ cat manifests/ttl.sh/bc445bdd-e571-4966-ad25-280d83b178b4/1h/manifest.json | jq -r '.'
{
  "schemaVersion": 2,
  "config": {
    "mediaType": "application/vnd.oci.image.config.v1+json",
    "digest": "sha256:1c27590edc5daec38a8d418b95c56ad501dd7ce80a11bfbaab79fe3dfe5264aa",
    "size": 209
  },
  "layers": [
    {
      "mediaType": "application/vnd.wasm.content.layer.v1+wasm",
      "digest": "sha256:26211586b5373cbacc116be3f5c7b7d029894d7e27cf6c20cdd2a65e8b03a24c",
      "size": 3770121
    },
...

If we'd like to tally up the total size of all layers for this app/OCI image, we can use this one-liner that is sure to impress (or frighten)!

$ total=''; for size in $(cat manifests/ttl.sh/bc445bdd-e571-4966-ad25-280d83b178b4/1h/manifest.json | jq -r '.layers' | grep size | cut -d ':' -f 2 | tr -d " "); do total=`expr $total + $size`; done; echo $total
72428333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment