Add script to check for podman image updates
parent
ddbe85b19d
commit
d3d7659bca
@ -0,0 +1,18 @@
|
||||
export def get_image_digest [image: string] {
|
||||
let token = ( get_token $image )
|
||||
mut headers = ( []
|
||||
| append [Accept "application/vnd.docker.distribution.manifest.v2+json"]
|
||||
| append [Authorization $"Bearer ($token)"]
|
||||
)
|
||||
print $headers
|
||||
|
||||
( http get -H $headers $"https://registry.hub.docker.com/v2/($image)/manifests/latest"
|
||||
| from json
|
||||
| get config
|
||||
| get digest
|
||||
)
|
||||
}
|
||||
|
||||
def get_token [image: string] {
|
||||
http get $"https://auth.docker.io/token?scope=repository:($image):pull&service=registry.docker.io" | get token
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
#!/bin/env nu
|
||||
use ./lib/cntfy.nu
|
||||
use ./lib/dockerhub.nu
|
||||
|
||||
def main [
|
||||
--ntfy: bool
|
||||
] {
|
||||
let images = ( get_images )
|
||||
let image_count = ( $images | length )
|
||||
if $image_count == 0 {
|
||||
print "No images found"
|
||||
return
|
||||
}
|
||||
print $"($image_count) local image[s] found"
|
||||
|
||||
( $images
|
||||
| where { |$it| $it.Names? != null }
|
||||
| insert Name {|$it| $it.Names | first }
|
||||
| where {|| needs_update }
|
||||
| each {|| print_needs_update $ntfy }
|
||||
)
|
||||
}
|
||||
|
||||
def get_images [] {
|
||||
podman images --no-trunc --format json | from json
|
||||
}
|
||||
|
||||
export def needs_update [] {
|
||||
let data = $in
|
||||
let name_parts = ( $data.Name | split row "/" --number 2 )
|
||||
let host = ( $name_parts | first )
|
||||
let image = ( $name_parts | last | split row ":" | get 0 )
|
||||
let digest = $data.Digest
|
||||
|
||||
if $host == "docker.io/" {
|
||||
( dockerhub get_image_digest $image ) == digest
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
def print_needs_update [ntfy: bool] {
|
||||
let data = $in
|
||||
print $"Image `($data.Name)` needs to be updated."
|
||||
|
||||
if $ntfy {
|
||||
cntfy publish --tags [ podman $data.Name ] --title $"($data.Name) outdated" "updates" $"Container ($data.Name) needs to be updated."
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue