mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
docker.nu : fix container-log and container-attach, add registry (#742)
- fix container-log - container-attach allow passing flag - add `registry delete` --------- Co-authored-by: nash <nash@iffy.me>
This commit is contained in:
parent
e5176370f6
commit
f75db6dc5f
1 changed files with 36 additions and 7 deletions
|
@ -160,7 +160,7 @@ export def container-log [ctn: string@"nu-complete docker containers"
|
|||
-l: int = 100 # line
|
||||
] {
|
||||
let l = if $l == 0 { [] } else { [--tail $l] }
|
||||
^$env.docker-cli logs -f $l $ctn
|
||||
^$env.docker-cli logs -f ...$l $ctn
|
||||
}
|
||||
|
||||
# container log with namespace
|
||||
|
@ -173,7 +173,7 @@ export def container-log-namespace [ctn: string@"nu-complete docker containers"
|
|||
}
|
||||
|
||||
# attach container
|
||||
export def container-attach [
|
||||
export def --wrapped container-attach [
|
||||
ctn: string@"nu-complete docker containers"
|
||||
-n: string@"nu-complete docker ns"
|
||||
...args
|
||||
|
@ -413,22 +413,51 @@ def "nu-complete registry show" [cmd: string, offset: int] {
|
|||
}
|
||||
|
||||
### docker registry show
|
||||
export def "registry show" [
|
||||
export def "docker registry show" [
|
||||
url: string
|
||||
reg?: string@"nu-complete registry show"
|
||||
tag?: string@"nu-complete registry show"
|
||||
] {
|
||||
let auth = if ($env | has 'REGISTRY_TOKEN') {
|
||||
let header = if ($env | has 'REGISTRY_TOKEN') {
|
||||
[-H $"Authorization: Basic ($env.REGISTRY_TOKEN)"]
|
||||
} else {
|
||||
[]
|
||||
}
|
||||
| append [-H 'Accept: application/vnd.oci.image.manifest.v1+json']
|
||||
if ($reg | is-empty) {
|
||||
curl -sSL ...$auth $"($url)/v2/_catalog" | from json | get repositories
|
||||
curl -sSL ...$header $"($url)/v2/_catalog" | from json | get repositories
|
||||
} else if ($tag | is-empty) {
|
||||
curl -sSL ...$auth $"($url)/v2/($reg)/tags/list" | from json | get tags
|
||||
curl -sSL ...$header $"($url)/v2/($reg)/tags/list" | from json | get tags
|
||||
} else {
|
||||
curl -sSL -H 'Accept: application/vnd.oci.image.manifest.v1+json' ...$auth $"($url)/v2/($reg)/manifests/($tag)" | from json
|
||||
curl -sSL ...$header $"($url)/v2/($reg)/manifests/($tag)" | from json
|
||||
}
|
||||
}
|
||||
|
||||
### docker registry delete
|
||||
export def "docker registry delete" [
|
||||
url: string
|
||||
reg: string@"nu-complete registry show"
|
||||
tag: string@"nu-complete registry show"
|
||||
] {
|
||||
let header = if ($env | has 'REGISTRY_TOKEN') {
|
||||
[-H $"Authorization: Basic ($env.REGISTRY_TOKEN)"]
|
||||
} else {
|
||||
[]
|
||||
}
|
||||
| append [-H 'Accept: application/vnd.oci.image.manifest.v1+json']
|
||||
#| append [-H 'Accept: application/vnd.docker.distribution.manifest.v2+json']
|
||||
let digest = do -i {
|
||||
curl -sSI ...$header $"($url)/v2/($reg)/manifests/($tag)"
|
||||
| rg docker-content-digest
|
||||
| split row ' '
|
||||
| get 1
|
||||
| str trim
|
||||
}
|
||||
print -e $digest
|
||||
if not ($digest | is-empty) {
|
||||
curl -sSL -X DELETE ...$header $"($url)/v2/($reg)/manifests/($digest)"
|
||||
} else {
|
||||
'not found'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue