This commit is contained in:
parent
af6e989bea
commit
c7f6441bf9
1 changed files with 55 additions and 20 deletions
|
@ -1,6 +1,8 @@
|
||||||
def main [
|
def main [
|
||||||
input: string # tar.gz file containing container image to be pushed to repository
|
input: string # tar.gz file containing container image to be pushed to repository
|
||||||
...tags: string # Tags to be added to pushed container image
|
...tags: string # Tags to be added to pushed container image
|
||||||
|
--registry: string = "" # container registry
|
||||||
|
--repository: string = "" # container repository
|
||||||
--no-latest-tag # Don't add "latest" tag to list of tags
|
--no-latest-tag # Don't add "latest" tag to list of tags
|
||||||
--no-drone-tag # Don't add tag calculated from DRONE_BUILD_NUMBER and DRONE_COMMIT_SHA
|
--no-drone-tag # Don't add tag calculated from DRONE_BUILD_NUMBER and DRONE_COMMIT_SHA
|
||||||
--no-github-tag # Don't add tag calculated from GItHUB_RUN_NUMBER and GITHUB_SHA
|
--no-github-tag # Don't add tag calculated from GItHUB_RUN_NUMBER and GITHUB_SHA
|
||||||
|
@ -48,39 +50,72 @@ def main [
|
||||||
|
|
||||||
print $tags
|
print $tags
|
||||||
|
|
||||||
if ($env | get -i PLUGIN_PASSWORD | is-empty) {
|
let auth = {username: null, password: null}
|
||||||
print "No password specified!"
|
|
||||||
exit 1
|
let auth = (
|
||||||
}
|
if (
|
||||||
if ($env | get -i PLUGIN_USERNAME | is-empty) {
|
(not ($env | get -i GITHUB_ACTOR | is-empty))
|
||||||
print "No username specified!"
|
and
|
||||||
exit 1
|
(not ($env | get -i GITHUB_TOKEN | is-empty))
|
||||||
}
|
) {
|
||||||
if ($env | get -i PLUGIN_REGISTRY | is-empty) {
|
{username: $env.GITHUB_ACTOR, password: $env.GITHUB_TOKEN}
|
||||||
print "No registry specified!"
|
} else if (
|
||||||
exit 1
|
(not ($env | get -i PLUGIN_USERNAME | is-empty))
|
||||||
}
|
and
|
||||||
if ($env | get -i PLUGIN_REPOSITORY | is-empty) {
|
(not ($env | get -i PLUGIN_PASSWORD | is-empty))
|
||||||
print "No repositiory specified!"
|
) {
|
||||||
exit 1
|
{username: $env.PLUGIN_USERNAME, password: $env.PLUGIN_PASSWORD}
|
||||||
}
|
} else {
|
||||||
|
print "Unable to determine authentication parameters!"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
print $auth
|
||||||
|
|
||||||
|
let registry = (
|
||||||
|
if ($registry | is-empty) {
|
||||||
|
if not ($env | get -i PLUGIN_REGISTRY | is-empty) {
|
||||||
|
$env.PLUGIN_REGISTRY
|
||||||
|
} else {
|
||||||
|
print "No registry specified!"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$registry
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
let repositiory = (
|
||||||
|
if ($repository | is-empty) {
|
||||||
|
if not ($env | get -i PLUGIN_REPOSITIORY | is-empty) {
|
||||||
|
$env.PLUGIN_REPOSITIORY
|
||||||
|
} else {
|
||||||
|
print "No repository specified!"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$repository
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
alias podman = ^podman --log-level error
|
alias podman = ^podman --log-level error
|
||||||
|
|
||||||
$env.PLUGIN_PASSWORD | podman login --username $env.PLUGIN_USERNAME --password-stdin $env.PLUGIN_REGISTRY
|
$auth.password | podman login --username $auth.username --password-stdin $registry
|
||||||
|
|
||||||
let load_result = (do {podman load --input $input} | complete)
|
let load_result = (do {podman load --input $input} | complete)
|
||||||
if $load_result.exit_code != 0 {
|
if $load_result.exit_code != 0 {
|
||||||
print $load_result.stderr
|
print $load_result.stderr
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
let old_image = $load_result.stdout | str trim | parse "Loaded image: {image}" | get 0.image
|
|
||||||
|
let old_image = ($load_result.stdout | str trim | parse "Loaded image: {image}" | get 0.image)
|
||||||
|
|
||||||
print $old_image
|
print $old_image
|
||||||
podman images
|
podman images
|
||||||
$tags | each {
|
$tags | each {
|
||||||
|tag|
|
|tag|
|
||||||
let new_image = $"($env.PLUGIN_REGISTRY)/($env.PLUGIN_REPOSITORY):($tag)"
|
let new_image = $"($registry)/($repository):($tag)"
|
||||||
print $new_image
|
print $new_image
|
||||||
let tag_result = (do { podman tag $old_image $new_image } | complete)
|
let tag_result = (do { podman tag $old_image $new_image } | complete)
|
||||||
if $tag_result.exit_code != 0 {
|
if $tag_result.exit_code != 0 {
|
||||||
|
@ -94,5 +129,5 @@ def main [
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
podman images
|
podman images
|
||||||
podman logout $env.PLUGIN_REGISTRY
|
podman logout $registry
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue