diff --git a/.github/README_B.png b/.github/README_B.png new file mode 100644 index 0000000..473b804 Binary files /dev/null and b/.github/README_B.png differ diff --git a/.github/demo.gif b/.github/demo.gif new file mode 100644 index 0000000..aba99d2 Binary files /dev/null and b/.github/demo.gif differ diff --git a/README.md b/README.md index f0a5489..ccca188 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,16 @@ ## Features Easily create and manage container environments for interactive use. All host integration is strictly opt-in; you choose what (if anything) is shared with each container. - +

+ +

Bring your existing Docker-style container definitions... -{Image or ASCIInema} +

+ +

+ ... or take advantage of Fishtank's custom shell-based format that bundles together all the information needed to build *and* run your containers. @@ -33,15 +38,15 @@ Before installing, make sure you have the following packages on your system: - `coreutils` ```sh -curl --proto '=https' --tlsv1.2 -sSf $URL | source - install self +curl -Lf https://github.com/Colonial-Dev/fishtank/releases/latest/download/tankctl | source - install ``` This downloads the latest stable version of Fishtank and uses the self-update functionality to bootstrap a persistent install. -By default, this installs two scripts (`tankctl` and `tankcfg`) in `$XDG_CONFIG_HOME` (by default, `$HOME/.local/bin`) - to override the install location, simply pass your preferred path as the third argument: +By default, this installs two scripts (`tankctl` and `tankcfg`) in the XDG-specified `$HOME/.local/bin` directory - to override the install location, simply pass your preferred path as the third argument: ```sh -curl --proto '=https' --tlsv1.2 -sSf $URL | source - install self /usr/bin +curl -Lf https://github.com/Colonial-Dev/fishtank/releases/latest/download/tankctl | source - install /usr/bin ``` ### From Source diff --git a/src/common/20-trap.fish b/src/common/20-trap.fish index 304abc5..6e32c31 100644 --- a/src/common/20-trap.fish +++ b/src/common/20-trap.fish @@ -1,18 +1,16 @@ function arm -a victim -d "Arm a non-zero exit code trap for the provided executable." # This function remains in scope, even after 'trap' ends. function $victim -V victim -w $victim - # Capture both stderr and stdout, using quoted substitution - # to avoid splitting into a list. - set -l output "$(command $victim $argv 2>&1)" + command $victim $argv # Capture the status. - set -l stat $status + set -l s $status # If the status is not zero, we've trapped an error. - if [ "$stat" -ne 0 ] - error $victim $stat "$argv" "$output" + if [ $s -ne 0 ] + error $victim $s "$argv" else - # If the status is zero, all is well. Print the captured output and return. - printf "%s" "$(echo $output)" + # If the status is zero, all is well. + return 0 end end end @@ -30,30 +28,15 @@ function disarm -d "Remove a non-zero exit code trap for the provided executable end # Pretty-prints an error. -function error -a victim stat args output - # Split the output into a list (on newlines.) - set -l output (echo $output) - +function error -a victim stat args # Write out the command, arguments, and exit code. printf "%serror trapped%s\n" (set_color red -o) (set_color normal) >&2 printf "├── command\t%s\n" "$victim" >&2 printf "├── argv \t%s\n" "$args" >&2 - printf "├── code \t%s\n" "$stat" >&2 - printf "└── " >&2 + printf "└── code \t%s\n" "$stat" >&2 echo -n (set_color brblack) >&2 - # Write out the output (pretty-formatted) if any exists. - if [ -z "$output" ] - printf "(no output)\n" >&2 - else - printf "%s\n" $output[1] >&2 - - for line in $output[2..] - printf " %s\n" $line >&2 - end - end - # Print backtrace, if enabled. if [ -n "$fish_backtrace" ] echo -n (set_color normal) >&2 diff --git a/src/tankcfg/10-main.fish b/src/tankcfg/10-main.fish index 4ab0129..b49bc78 100644 --- a/src/tankcfg/10-main.fish +++ b/src/tankcfg/10-main.fish @@ -1,3 +1,4 @@ +# TODO use argparse to make these not suck function RUN buildah run $__FISHTANK_BUILD_CTR $argv end diff --git a/src/tankctl/10-podman.fish b/src/tankctl/10-podman.fish index b1a3ec8..71eb203 100644 --- a/src/tankctl/10-podman.fish +++ b/src/tankctl/10-podman.fish @@ -60,8 +60,10 @@ function check_ctr -a ctr end end -function make_ctr -a img replace +function make_ctr -a img set -l name (img_annotation $img "fishtank.name") + set -l hash (img_annotation $img "fishtank.hash") + set -l command podman run -d for a in $__ANNOTATIONS @@ -70,8 +72,10 @@ function make_ctr -a img replace end for entry in (img_annotation $img "fishtank.$a" | string split \x1F) - set -a command "--$a" - set -a command $entry + if [ -n "$entry" ] + set -a command "--$a" + set -a command $entry + end end end @@ -79,18 +83,22 @@ function make_ctr -a img replace set -a command --hostname $name for entry in (img_annotation $img "fishtank.args" | string split \x1F) - set -a command $entry + if [ -n "$entry" ] + set -a command $entry + end end set -a command --annotation "manager=fishtank" set -a command --annotation "fishtank.name=$name" + set -a command --annotation "fishtank.hash=$hash" - if set -q replace + if [ -n "$_flag_replace" ] set -a command --replace end - $command $img - printf " (%s)\n" $name + set -a command "$img" + + printf "(%s) (%s)\n" ($command) $name end function start_ctr -a ctr diff --git a/src/tankctl/30-main.fish b/src/tankctl/30-main.fish index 623e15e..032ebb1 100644 --- a/src/tankctl/30-main.fish +++ b/src/tankctl/30-main.fish @@ -77,24 +77,47 @@ end function tankctl_up argparse -i (fish_opt -s r -l replace) -- $argv + if set -q _flag_replace + set -x _flag_replace yes + end + if [ (count $argv) -gt 0 ] - map make_ctr $argv $_flag_replace + map make_ctr $argv return end for img in (enumerate_imgs) if podman ps --format "{{.ImageID}}" | grep -q $img if set -q _flag_replace - make_ctr $img $_flag_replace + make_ctr $img end else - make_ctr $img $_flag_replace + make_ctr $img end end end function tankctl_list + for ctr in (enumerate_ctrs) + set -a list (podman inspect --format "{{.Name}}" $ctr) + set -a list (podman inspect --format "{{.ImageName}}" $ctr) + set -a list (podman inspect --format "{{.State.Status}}" $ctr) + + + set -l img (podman inspect --format "{{.Image}}" $ctr) + set -l c_hash (ctr_annotation $ctr "fishtank.hash") + set -l i_hash (img_annotation $img "fishtank.hash") + + if [ $c_hash != $i_hash ] + set -a list no + else + set -a list yes + end + set -a list \n + end + + echo $list | column -t -N "Name,Image,Status,Up to date?" end function tankctl_edit @@ -157,13 +180,39 @@ function tankctl_enter -a container tankctl_exec $container /bin/sh -c "exec \$SHELL" end +function tankctl_install + set -l URL "https://github.com/Colonial-Dev/fishtank/releases/latest/download" + + if [ -n "$argv[1]" ] + set root "$argv[1]" + else + set root "$HOME/.local/bin" + end + + set root (string trim -r -c / $root) + + printf "Downloading component 1/2... " + curl --progress-bar -Lf "$URL/tankctl" > $root/tankctl + printf "Downloading component 2/2... " + curl --progress-bar -Lf "$URL/tankcfg" > $root/tankcfg + + chmod +x $root/tankctl + chmod +x $root/tankcfg + + if command -q tankcfg; and command -q tankctl + echo "Fishtank has been installed successfully - enjoy!" + else + echo "Fishtank was downloaded to $root, but it doesn't appear to be in your \$PATH - maybe check that?" + end +end + # --- EFFECTIVE ENTRYPOINT --- # require podman require buildah -trap rm cp mv ls ln mkdir podman -trap curl realpath find touch +trap rm cp mv ls ln mkdir chmod podman +trap curl realpath find touch curl if [ -n "$XDG_CONFIG_HOME" ] set -x __TANK_DIR "$XDG_CONFIG_HOME/fishtank/"