bin/stack: update commands and template

This commit is contained in:
xeruf 2022-09-01 14:10:42 +01:00
parent 00b57be064
commit 58d5f34019
3 changed files with 74 additions and 20 deletions

View File

@ -16,6 +16,7 @@ _stackspin_cluster_cache=/var/tmp/stackspin-cluster
# Hostname [IP] # Hostname [IP]
# This is a function so it can change directory. # This is a function so it can change directory.
stack() { stack() {
local pod_suffix='-\(0\|[0-f]\+\)'
test $# -lt 1 && test $# -lt 1 &&
builtin cd "$STACKSPIN" && builtin cd "$STACKSPIN" &&
echo "Usage: $0 <COMMAND> [args...]" && echo "Usage: $0 <COMMAND> [args...]" &&
@ -54,27 +55,59 @@ stack() {
echo "Initialized user '$*' with email '$mail'" echo "Initialized user '$*' with email '$mail'"
else "$0" sso cli "$command" "$@" else "$0" sso cli "$command" "$@"
fi;; fi;;
# app clis via kubectl
(occ) "$0" exec nc-nextcloud -c nextcloud -it -- su www-data -s /bin/bash -c "php $command $*";;
(exec) "$0" kube exec "$@";;
(logs) "$0" kube logs "$@";;
(kube)
if ! pod=$("$0" pod "$2-\(0\|[0-f]\+\)")
then echo "No pod found for $2" >&2
return 1
fi
local subcommand=$1
shift 2
kubectl "$subcommand" -n $(echo $pod) "$@";;
(pod)
local podname=$1
shift
kubectl get pods --all-namespaces --field-selector="status.phase=Running" -o=custom-columns=S:.metadata.namespace,N:.metadata.name --no-headers "$@" | grep --color=never "$podname";;
(push) (push)
git commit -a "$@" git commit -a "$@"
git push && git push &&
flux reconcile source git -n flux-system "$(basename $(git rev-parse --show-toplevel))" flux reconcile source git -n flux-system "$(basename $(git rev-parse --show-toplevel))"
flux reconcile kustomization -n flux-system "$(basename $(git rev-parse --show-toplevel))";; flux reconcile kustomization -n flux-system "$(basename $(git rev-parse --show-toplevel))";;
# KUBE
# app clis
(occ) "$0" exec nc-nextcloud -c nextcloud -it -- su www-data -s /bin/bash -c "php $command $*";;
(vikunja) local pod=${2:-vikunja}
case "$1" in
(dump|export) cd $PROJECTS/vikunja
"$0" exec "$pod" -c api -- sh -c 'rm -f *.zip && ./vikunja dump >/dev/null && ls --color -lAhF >&2 && cat *.zip' >"$pod-dump_$(date +%F).zip"
;;
(restore) "$0" upload "$pod" "$3" -c api
"$0" exec "$pod" -c api -it -- ./vikunja restore "$3"
;;
(psql) kubectl exec -it -n $("$0" pod "$pod-postgresql") -- sh -c "PGPASSWORD=$(kubectl get secret --namespace stackspout $pod-postgresql -o jsonpath='{.data.postgresql-password}' | base64 --decode) psql -h localhost -U vikunja -p 5432 vikunja"
esac
;;
# high-level
(shell) "$0" exec "$1" -it -- /bin/sh "${@:2}";;
(ls)
if test $# -gt 1 && ! [[ "$2" =~ ".*/.*" ]]
then "$0" exec "$1" "$2" "$3" -it -- ls -lAhF --group-directories-first "${@:4}"
else for container in $("$0" kube get "$1" pod -o "jsonpath={.spec.containers[*].name}")
do #highlight "Listing content of $container" &&
"$0" ls "$1" -c "$container" "${@:2}"
done
fi;;
(upload)
kubectl cp "$2" -n $("$0" pod "$1$pod_suffix"):$2 "${@:3}"
"$0" ls "$1" "${@:3}";;
(exec) "$0" kube exec "$@";;
(logs) "$0" kube logs "$@" | less -RF;;
# low-level
(kube)
if ! namespacedpod=$("$0" pod "$2$pod_suffix")
then echo "No pod found for $2" >&2
return 1
fi
local subcommand=$1
shift 2
local commands=()
for arg;
do case "$arg" in (-*) break;; (*) commands+="$arg"; shift;; esac
done
test "$subcommand" = get ||
highlight "Running $subcommand on $namespacedpod" >&2
kubectl "$subcommand" "$commands[@]" -n $(echo $namespacedpod) "$@";;
(pod)
local podname=$1
shift
kubectl get pods --all-namespaces --field-selector="status.phase=Running" -o=custom-columns=S:.metadata.namespace,N:.metadata.name --no-headers "$@" | grep --color=never "$podname";;
# stackspin bare # stackspin bare
(*) if which "$0-$command" >/dev/null 2>&1 (*) if which "$0-$command" >/dev/null 2>&1
then "$0-$command" "$@" then "$0-$command" "$@"

View File

@ -3,7 +3,7 @@
# adapted and improved from the commonly circulating version # adapted and improved from the commonly circulating version
# detects whether unpacking into a subfolder is sensible # detects whether unpacking into a subfolder is sensible
# and shows progress indications for some operations # and shows progress indications for some operations
# optdepends: rewrite(part of my dotfiles, for unzip line rewriting) # optdepends: rewrite(part of my dotfiles, for unzip line rewriting) 7z p7zip unzip
for arg do for arg do
case $arg in case $arg in
(-d) del=$(expr ${del:-0} + 1);; (-d) del=$(expr ${del:-0} + 1);;
@ -12,6 +12,9 @@ case $arg in
if test -r "$arg"; then if test -r "$arg"; then
fullpath="$(realpath "$arg")" fullpath="$(realpath "$arg")"
name="$(basename "${fullpath%.*}")" name="$(basename "${fullpath%.*}")"
ls --color -dlhF "$name" >&2 2>/dev/null &&
echo "Target directory exists - archive already extracted?" >&2 &&
continue
namepart="$name.part" namepart="$name.part"
( (
# Create temporary subfolder if current folder contains stuff # Create temporary subfolder if current folder contains stuff
@ -45,7 +48,7 @@ case $arg in
then if test $# -lt 2 -a "$(ls -U | wc -l)" -lt 3 then if test $# -lt 2 -a "$(ls -U | wc -l)" -lt 3
then test "$(ls)" && mv -iv * .. then test "$(ls)" && mv -iv * ..
cd .. && rm -d "$namepart" cd .. && rm -d "$namepart"
else cd .. && mv -iv "$namepart" "$name" else cd .. && mv -ivT "$namepart" "$name"
fi fi
fi fi
case $del in case $del in

View File

@ -87,7 +87,8 @@ data:
hostname: "$subdomain.\${domain}" hostname: "$subdomain.\${domain}"
tls: true tls: true
certManager: true certManager: true
# TODO Adjust Mailer config # TODO Configure PVC for data & database
# TODO Adjust $app Mailing config
# mailer: # mailer:
# enabled: "\${outgoing_mail_enabled}" # enabled: "\${outgoing_mail_enabled}"
# host: "\${outgoing_mail_smtp_host}" # host: "\${outgoing_mail_smtp_host}"
@ -95,10 +96,27 @@ data:
# username: "\${outgoing_mail_smtp_user}" # username: "\${outgoing_mail_smtp_user}"
# password: "\${outgoing_mail_smtp_password}" # password: "\${outgoing_mail_smtp_password}"
# fromemail: "\${outgoing_mail_from_address}" # fromemail: "\${outgoing_mail_from_address}"
# TODO Adjust OpenID Connect Single Sign-On Configuration # TODO Adjust $app OpenID Connect Single Sign-On Configuration
# - name: Stackspin # - name: Stackspin
# key: "\${client_id}" # key: "\${client_id}"
# secret: "\${client_secret}" # secret: "\${client_secret}"
# autoDiscoverUrl: 'https://sso.\${domain}/.well-known/openid-configuration' # autoDiscoverUrl: 'https://sso.\${domain}/.well-known/openid-configuration'
EOF EOF
cat <<EOF >$app-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: $app-data
namespace: $namespace
labels:
stackspin.net/backupSet: "$app"
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 2Gi
storageClassName: local-path
EOF