Skip to content

Commit

Permalink
More bug squashing
Browse files Browse the repository at this point in the history
Implement list and install
Add some images to README
  • Loading branch information
Colonial-Dev committed Sep 9, 2024
1 parent 0b50bb4 commit ce2e4fe
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 42 deletions.
Binary file added .github/README_B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


<p align="center">
<img src=".github/demo.gif">
</p>

Bring your existing Docker-style container definitions...

{Image or ASCIInema}
<p align="center">
<img src=".github/README_B.png">
</p>


... or take advantage of Fishtank's custom shell-based format that bundles together all the information needed to build *and* run your containers.

Expand All @@ -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
Expand Down
33 changes: 8 additions & 25 deletions src/common/20-trap.fish
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/tankcfg/10-main.fish
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO use argparse to make these not suck
function RUN
buildah run $__FISHTANK_BUILD_CTR $argv
end
Expand Down
22 changes: 15 additions & 7 deletions src/tankctl/10-podman.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,27 +72,33 @@ 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

set -a command --name $name
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
Expand Down
59 changes: 54 additions & 5 deletions src/tankctl/30-main.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/"
Expand Down

0 comments on commit ce2e4fe

Please sign in to comment.