diff --git a/container-registry.nu b/container-registry.nu new file mode 100755 index 0000000..3ea570f --- /dev/null +++ b/container-registry.nu @@ -0,0 +1,24 @@ +#!/bin/env nu + +export def main [] { + get_info "docker.io/itzg/minecraft-server" +} + +export def get_info [image_name: string] { + let info = ( parse_name $image_name ) + let token = ( get_token $info.registry $info.group $info.image ) + http get -H [Authorization $"Bearer ($token)"] $"https://index.($info.registry)/v2/($info.group)/($info.image)/manifests/latest" | from json +} + +def parse_name [image_name: string] { + let parts = ( $image_name | split row "/" ) + { + registry: $parts.0 + group: $parts.1 + image: $parts.2 + } +} + +def get_token [registry: string, group: string, image: string] { + http get $"https://auth.($registry)/token?service=registry.($registry)&scope=repository:($group)/($image):pull" | get token +} \ No newline at end of file