oci/justfile

116 lines
2.9 KiB
Makefile

#!/usr/bin/env -S just --justfile
set fallback := false
mod dev
mod ci
[private]
default:
@just help
# show this help
help:
@just --list
# provide an additional shell into the container
[group('Interactive')]
shell *id:
#!/usr/bin/env bash
name={{ id }}
declare -a args=()
# if no name was provided, fall back to the last project container created
args+=( --all )
if [[ -z $name ]]; then
args+=( --filter=label="PROJECT=oci" --latest )
else
args+=( --filter=name="${name}" )
fi
id=$(podman ps "${args[@]}" --format="{{{{ .Names }}")
suffix=$(podman ps "${args[@]}" --format='{{{{ index (split .Labels.NAME "-") 1 }}')
if [[ -v TMUX_PANE && -n $suffix ]]; then
tmux rename-window "$suffix"
fi
podman exec --interactive --tty "$id" /usr/bin/zsh --login
if [[ -v TMUX_PANE ]]; then
tmux set-option -w automatic-rename on
fi
# attach to the just created container
[group('Interactive')]
attach *id:
#!/usr/bin/env bash
name={{ id }}
declare -a args=()
# if no name was provided, fall back to the last project container created
args+=( --all )
if [[ -z $name ]]; then
args+=( --filter=label="PROJECT=oci" --latest )
else
args+=( --filter=name="${name}" )
fi
id=$(podman ps "${args[@]}" --format="{{{{ .Names }}")
suffix=$(podman ps "${args[@]}" --format='{{{{ index (split .Labels.NAME "-") 1 }}')
if [[ -v TMUX_PANE && -n $suffix ]]; then
tmux rename-window "$suffix"
fi
podman start --attach --interactive "$id"
if [[ -v TMUX_PANE ]]; then
tmux set-option -w automatic-rename on
fi
# remove all containers
[confirm('Remove all containers?')]
[group('Cleanup')]
rm:
@-podman container ls --all --filter=label="PROJECT=oci" --quiet | \
xargs podman container rm --volumes --
# remove all images
[confirm('Remove all images?')]
[group('Cleanup')]
rmi:
@-podman image ls --filter=label="PROJECT=oci" --quiet | \
xargs podman image rm --
# remove dangling images
[group('Cleanup')]
podman-prune:
@podman image prune --force
# removes all build artifacts possibly left by buildah
[group('Cleanup')]
buildah-prune:
@buildah rm --all
# clean oci container and images
[group('Cleanup')]
clean: rm rmi podman-prune
# list built images by label
[group('Status')]
list-images:
@podman image list --filter=label="PROJECT=oci" --noheading --sort=created
# list created container by label
[group('Status')]
ps:
@podman container list --filter=label="PROJECT=oci" --noheading --all
# enumerate build targets
[group('Status')]
find:
@find ci dev -mindepth 1 -maxdepth 1 -type d -print
# remove buildah and podman dangling images
[group('Cleanup')]
[no-exit-message]
prune: podman-prune buildah-prune
alias ls := list-images
# vi: set ft=just ts=4 sw=4 sts=-1 nosr et si tw=0 fdm=manual: