use nushell script for pushing container image
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Jeffrey C. Ollie 2023-04-15 17:22:48 -05:00
parent b9d1389444
commit 4e0a91235a
Signed by: jeff
GPG key ID: 6F86035A6D97044E
2 changed files with 96 additions and 12 deletions

View file

@ -35,6 +35,7 @@
pkgs.gnused pkgs.gnused
pkgs.nix pkgs.nix
pkgs.nodejs-16_x pkgs.nodejs-16_x
pkgs.nushell
pkgs.podman pkgs.podman
]; ];
@ -365,18 +366,14 @@
apps = { apps = {
push-container = push-container =
let let
script = pkgs.writeScript "push-container" '' script = pkgs.writeTextFile
set | grep -i plugin {
set | grep -i DRONE name = "push-container";
ls -l "''${1}" text = ''
echo -n "''${PLUGIN_PASSWORD}" | podman login --username "''${PLUGIN_USERNAME}" --password-stdin "''${PLUGIN_REGISTRY}" #!${pkgs.nushell}/bin/nu
image=''$(podman load --input "''${1}" | sed -n -e "s/Loaded image:.\\(.*\\)/\\1/p") '' + (builtins.readFile ./push-container.nu);
podman images executable = true;
podman tag "''${image}" "''${PLUGIN_REGISTRY}/''${PLUGIN_REPOSITORY}:''${DRONE_BUILD_NUMBER}-''${DRONE_COMMIT_SHA:0:8}" };
podman tag "''${image}" "''${PLUGIN_REGISTRY}/''${PLUGIN_REPOSITORY}:latest"
podman images
podman logout "''${PLUGIN_REGISTRY}"
'';
in in
{ {
type = "app"; type = "app";

87
push-container.nu Normal file
View file

@ -0,0 +1,87 @@
def main [
input: string # tar.gz file containing container to be pushed to repository
...tags: string # Tags to be added to pushed container
--no-latest-tag # Don't add latest tag
--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
] {
env
print $input
print $tags
print $no_latest_tag
print $no_drone_tag
print $no_github_tag
if not ($input | path exists) {
print $"($input) does not exist!"
exit 1
}
let tags = if not ($env | get -i PLUGIN_TAGS | is-empty) {
$tags | append ($env.PLUGIN_TAGS | split row ',' | str trim)
} else {
$tags
}
let tags = if (not $no_latest_tag) {
$tags | append "latest"
} else {
$tags
}
let tags = if (
(not $no_drone_tag)
and
(not ($env | get -i DRONE_BUILD_NUMBER | is-empty))
and
(not ($env | get -i DRONE_COMMIT_SHA | is-empty))
) {
$tags | append $"($env.DRONE_BUILD_NUMBER)-($env.DRONE_COMMIT_SHA | str substring 0..8)"
} else {
$tags
}
let tags = if (
(not $no_github_tag)
and
(not ($env | get -i GITHUB_RUN_NUMBER | is-empty))
and
(not ($env | get -i GITHUB_SHA | is-empty))
) {
$tags | append $"($env.DRONE_BUILD_NUMBER)-($env.DRONE_COMMIT_SHA | str substring 0..8)"
} else {
$tags
}
print $tags
if ($env | get -i PLUGIN_PASSWORD | is-empty) {
print "No password specified!"
exit 1
}
if ($env | get -i PLUGIN_USERNAME | is-empty) {
print "No username specified!"
exit 1
}
if ($env | get -i PLUGIN_REGISTRY | is-empty) {
print "No registry specified!"
exit 1
}
if ($env | get -i PLUGIN_REPOSITORY | is-empty) {
print "No repositiory specified!"
exit 1
}
$env.PLUGIN_PASSWORD | podman login --username $env.PLUGIN_USERNAME --password-stdin $env.PLUGIN_REGISTRY
let old_image = (podman load --input $input | parse "Loaded image: {image}" | get 0.image)
print $old_image
podman images
$tags | each {
|tag|
let new_image = $"($env.PLUGIN_REGISTRY)/($env.PLUGIN_REPOSITORY):($tag)"
podman tag $old_image $new_image
podman push $new_image
}
podman images
podman logout "''${PLUGIN_REGISTRY}"
}