config/shell/server: drastically improve stack command
This commit is contained in:
parent
e1a9ec48ca
commit
b329a94d42
|
@ -1,4 +1,4 @@
|
|||
test -z "$DISPLAY" && test "$XDG_VTNR" -eq 1 || return 0
|
||||
test -z "$DISPLAY" && test "$XDG_VTNR" -lt 1 || return 0
|
||||
|
||||
export PATH="$PATH:$HOME/.local/bin/server"
|
||||
export PROJECTS="$HOME/projects"
|
||||
|
@ -17,11 +17,14 @@ _stackspin_cluster_cache=/var/tmp/stackspin-cluster
|
|||
# This is a function so it can change directory.
|
||||
stack() {
|
||||
local pod_suffix='-\(0\|[0-f]\+\)'
|
||||
test $# -lt 1 &&
|
||||
builtin cd "$STACKSPIN" &&
|
||||
echo "Usage: $0 <COMMAND> [args...]" &&
|
||||
echo "Inbuilt commands: select, sso, user, exec, pod, occ, push" &&
|
||||
if test $# -lt 1; then
|
||||
builtin cd "$STACKSPIN"
|
||||
echo "Usage: $0 <COMMAND> [args...]"
|
||||
echo "Stackspin commands: select, sso, user, push"
|
||||
echo "Kubepod commands: pod, exec, app, shell, ls, logs, upload"
|
||||
echo "App commands: occ, vikunja"
|
||||
return 1
|
||||
fi
|
||||
local command="$1"
|
||||
shift
|
||||
case "$command" in
|
||||
|
@ -35,7 +38,7 @@ stack() {
|
|||
#export GITLAB_CI="true"
|
||||
echo Selected "$_cluster_name" with IP "$_cluster_ip"
|
||||
echo "$_cluster_name" >"$_stackspin_cluster_cache"
|
||||
test "$PWD" = "$HOME" && builtin cd "$STACKSPIN"
|
||||
#test "$PWD" = "$HOME" && builtin cd "$STACKSPIN"
|
||||
;;
|
||||
(sso) builtin cd "$STACKSPIN"
|
||||
"$0" exec dashboard --container backend -- flask "$@";;
|
||||
|
@ -65,22 +68,27 @@ stack() {
|
|||
(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
|
||||
(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"
|
||||
(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";;
|
||||
(*) echo "Unknown Subcommand";;
|
||||
esac
|
||||
;;
|
||||
# high-level
|
||||
(shell) "$0" exec "$1" -it -- /bin/sh "${@:2}";;
|
||||
(shell)
|
||||
container=$1
|
||||
shift
|
||||
test "$1" = "-c" && pod=$2 && shift 2
|
||||
"$0" exec "$container" -c "$pod" -it -- /bin/sh "$@";;
|
||||
(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" &&
|
||||
do highlight "Listing content of $container" &&
|
||||
"$0" ls "$1" -c "$container" "${@:2}"
|
||||
done
|
||||
fi;;
|
||||
|
@ -88,26 +96,25 @@ stack() {
|
|||
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;;
|
||||
(logs) "$0" kube logs "$@" | $(command which lnav || { which bat >/dev/null && echo "bat --number -l toml" } || echo 'less -RF');;
|
||||
# low-level
|
||||
(kube)
|
||||
if ! namespacedpod=$("$0" pod "$2$pod_suffix")
|
||||
then echo "No pod found for $2" >&2
|
||||
return 1
|
||||
fi
|
||||
test $# -gt 1 || { echo "Please provide a command and pod name" >&2 && return 1; }
|
||||
local pods=$("$0" pod "$2$pod_suffix") || { echo "No pod found for $2" >&2 && return 1; }
|
||||
local subcommand=$1
|
||||
shift 2
|
||||
local commands=()
|
||||
for arg;
|
||||
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) "$@";;
|
||||
for namespacedpod in $pods; do
|
||||
test "$subcommand" = get ||
|
||||
highlight "Running $subcommand on $namespacedpod" >&2
|
||||
kubectl "$subcommand" "$commands[@]" -n $(echo $namespacedpod) "$@"
|
||||
done;;
|
||||
(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";;
|
||||
test $# -gt 0 && 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
|
||||
(*) if which "$0-$command" >/dev/null 2>&1
|
||||
then "$0-$command" "$@"
|
||||
|
@ -115,10 +122,15 @@ stack() {
|
|||
fi
|
||||
builtin cd "$STACKSPIN"
|
||||
# Since the install command can also be given bare to install stackspin itself
|
||||
if test $# -gt 0 -a "$command" = install
|
||||
then "./install/install-$1.sh" || ./install/install-app.sh "$@"
|
||||
if test "$command" = "install"; then
|
||||
if test $# -gt 0
|
||||
then "./install/install-$1.sh" || ./install/install-app.sh "$@"
|
||||
else
|
||||
/usr/bin/python3 -m pip install --upgrade pip
|
||||
/usr/bin/python3 -m pip install -r requirements.txt
|
||||
python3 -m stackspin "$_cluster_name" "$command"
|
||||
fi
|
||||
else python3 -m stackspin "$_cluster_name" "$command" "$@"
|
||||
# pip3 install -r requirements.txt
|
||||
fi;;
|
||||
esac
|
||||
}
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
#!/bin/sh -e
|
||||
test $# -lt 1 &&
|
||||
echo "Usage: $0 <app> [subdomain] [repo] [namespace]" &&
|
||||
if test $# -lt 1; then
|
||||
echo "You should be in the root apps folder."
|
||||
echo "Usage: $0 <app> [subdomain] [repo] [namespace]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
app=$1
|
||||
subdomain=${2:-$app}
|
||||
repo=${3:-$app}
|
||||
namespace=${4:-stackspout}
|
||||
|
||||
if test "$(basename "$PWD")" != "$subdomain"
|
||||
then mkdir -p "$subdomain" && cd "$subdomain"
|
||||
fi
|
||||
|
||||
cat <<EOF >$app-oauth-client.yaml
|
||||
apiVersion: hydra.ory.sh/v1alpha1
|
||||
kind: OAuth2Client
|
||||
|
@ -120,3 +128,7 @@ spec:
|
|||
storage: 2Gi
|
||||
storageClassName: local-path
|
||||
EOF
|
||||
|
||||
ls -l
|
||||
echo "To do: Obtain chart version, check configmap, create oauth secrets if needed" >&2
|
||||
exec $SHELL
|
||||
|
|
Loading…
Reference in New Issue