nu-modules/dk.nu

58 lines
1.3 KiB
Plaintext

def parse-time [] {
parse "{value} {unit} ago" | each {|x|
match $x.unit {
"hours" => "hr",
"days" => "d"
}
}
}
# list images. The result of this can be piped into the most other commands for dk
export def images [] {
^docker images --format "{{json . }}"
| from json --objects
| select CreatedSince Repository ID Size Tag
| each {|row|
let splitted_repo = ($row.Repository | split row '/' -n 2)
{
created-since: $row.CreatedSince,
host: ($splitted_repo | first),
tag: ($splitted_repo | last),
version: $row.Tag,
size: ($row.Size | into filesize)
id: $row.ID
}
}
}
# like "tag" but based on image specs
export def "batch tag" [call] {
each {|image_spec|
let old = $image_spec
let new = (do $call $image_spec)
{old: $old, new: $new}
} | each {|x|
tag ($x.old | to docker path) ($x.new | to docker path)
$x.new
}
}
# "rename" a docker image
export def tag [old:string, new:string] {
^docker tag $old $new
}
export def "push" [] {
each {|image_spec|
^docker push ($image_spec | to docker path)
}
}
# == implementation ==
def "to docker path" [] {
let image_spec = ($in)
$"($image_spec.host)/($image_spec.tag):($image_spec.version)"
}