|
|
|
#!/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 registry = ( $name_parts | first )
|
|
|
|
let img_parts = ( $name_parts | last | split row ":" )
|
|
|
|
let image = ( $img_parts | get 0 )
|
|
|
|
let tag = ( $img_parts | get 1 )
|
|
|
|
let digest = $data.Id
|
|
|
|
print $"Checking if ($image):($tag) has updates on ($registry)"
|
|
|
|
|
|
|
|
if $registry == "docker.io" {
|
|
|
|
try {
|
|
|
|
( dockerhub get_image_digest $image $tag ) != $digest
|
|
|
|
} catch {
|
|
|
|
print "Failed to get image information"
|
|
|
|
false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print $"Host ($registry) is not supported"
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def print_needs_update [ntfy: bool] {
|
|
|
|
let data = $in
|
|
|
|
let containers = ( containers_for_image $data.Name )
|
|
|
|
print $"Image `($data.Name)` needs to be updated. Used by ($containers | str join ', ')"
|
|
|
|
|
|
|
|
if $ntfy {
|
|
|
|
(
|
|
|
|
cntfy publish
|
|
|
|
--tags [ podman $data.Name ]
|
|
|
|
--priority 4
|
|
|
|
--title $"($data.Name) outdated"
|
|
|
|
"updates" $"Container ($data.Name) needs to be updated. Used by ($data.Containers) containers. Used by: ( $containers | str join '\n' )"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def containers_for_image [image: string] {
|
|
|
|
( podman container ls --all --format json
|
|
|
|
| from json
|
|
|
|
| where Image == $image
|
|
|
|
| insert Name {|$it| $it.Names? | get 0 }
|
|
|
|
| get Name
|
|
|
|
)
|
|
|
|
}
|