make nu script generic
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Jeffrey C. Ollie 2023-08-27 15:33:25 -05:00
parent 0270656c45
commit 1aa22d2416
Signed by: jeff
GPG key ID: 6F86035A6D97044E
2 changed files with 48 additions and 17 deletions

View file

@ -21,8 +21,12 @@
]; ];
}; };
lib = pkgs.lib; lib = pkgs.lib;
docker-client = pkgs.docker_24.override {
clientOnly = true;
};
in in
{ {
packages = { packages = {
nixos-runner = nixos-runner =
let let
@ -47,12 +51,11 @@
pkgs.podman pkgs.podman
pkgs.stdenv.cc.cc.lib pkgs.stdenv.cc.cc.lib
(pkgs.docker_24.override { docker-client
clientOnly = true;
})
self.packages.${system}.login-script self.packages.${system}.login-script
self.packages.${system}.push-container self.packages.${system}.podman-push-container
self.packages.${system}.docker-push-container
]; ];
flake-registry = null; flake-registry = null;
@ -379,13 +382,34 @@
]; ];
}; };
}; };
push-container = pkgs.writeTextFile { podman-push-container = pkgs.writeTextFile {
name = "push-container"; name = "podman-push-container";
destination = "/bin/push-container"; destination = "/bin/podman-push-container";
text = lib.concatStringsSep "\n" [ text = builtins.replaceStrings
"#!${pkgs.nushell}/bin/nu" [
(builtins.readFile ./push-container.nu) "@nushell"
]; "@client@"
]
[
"${pkgs.nushell}/bin/nu"
"${pkgs.podman}/bin/podman"
]
(builtins.readFile ./push-container.nu);
executable = true;
};
docker-push-container = pkgs.writeTextFile {
name = "docker-push-container";
destination = "/bin/docker-push-container";
text = builtins.replaceStrings
[
"@nushell"
"@client@"
]
[
"${pkgs.nushell}/bin/nu"
"${docker-client}/bin/docker"
]
(builtins.readFile ./push-container.nu);
executable = true; executable = true;
}; };
login-script = pkgs.writeScriptBin "login-script" '' login-script = pkgs.writeScriptBin "login-script" ''

View file

@ -1,3 +1,4 @@
#!@nushell@
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
@ -84,6 +85,12 @@ def main [
$env.PLUGIN_REGISTRY $env.PLUGIN_REGISTRY
} else if not ($env | get -i REGISTRY | is-empty) { } else if not ($env | get -i REGISTRY | is-empty) {
$env.REGISTRY $env.REGISTRY
} else if (
(not ($env | get -i GITHUB_SERVER_URL | is-empty))
and
(not ($env | get -i GITHUB_ACTOR | is-empty))
) {
$"($env.GITHUB_SERVER_URL)/($env.GITHUB_ACTOR)"
} else { } else {
print "No registry specified!" print "No registry specified!"
exit 1 exit 1
@ -108,11 +115,11 @@ def main [
} }
) )
alias podman = ^podman --log-level debug alias client = ^@client@ --log-level debug
$auth.password | podman login --username $auth.username --password-stdin $registry $auth.password | client login --username $auth.username --password-stdin $registry
let load_result = (do { podman load --input $input } | complete) let load_result = (do { client 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
@ -123,12 +130,12 @@ def main [
$tags | each { $tags | each {
|tag| |tag|
let new_image = $"($registry)/($repository):($tag)" let new_image = $"($registry)/($repository):($tag)"
let tag_result = (do { podman tag $old_image $new_image } | complete) let tag_result = (do { client tag $old_image $new_image } | complete)
if $tag_result.exit_code != 0 { if $tag_result.exit_code != 0 {
print $tag_result.stderr print $tag_result.stderr
exit 1 exit 1
} }
let push_result = (do { podman push $new_image } | complete) let push_result = (do { client push $new_image } | complete)
if $push_result.exit_code != 0 { if $push_result.exit_code != 0 {
print $push_result.stderr print $push_result.stderr
exit 1 exit 1
@ -136,5 +143,5 @@ def main [
print $"Pushed ($new_image)" print $"Pushed ($new_image)"
} }
podman logout $registry client logout $registry
} }