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 PATH="$PATH:$HOME/.local/bin/server"
|
||||||
export PROJECTS="$HOME/projects"
|
export PROJECTS="$HOME/projects"
|
||||||
|
@ -17,11 +17,14 @@ _stackspin_cluster_cache=/var/tmp/stackspin-cluster
|
||||||
# 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]\+\)'
|
local pod_suffix='-\(0\|[0-f]\+\)'
|
||||||
test $# -lt 1 &&
|
if test $# -lt 1; then
|
||||||
builtin cd "$STACKSPIN" &&
|
builtin cd "$STACKSPIN"
|
||||||
echo "Usage: $0 <COMMAND> [args...]" &&
|
echo "Usage: $0 <COMMAND> [args...]"
|
||||||
echo "Inbuilt commands: select, sso, user, exec, pod, occ, push" &&
|
echo "Stackspin commands: select, sso, user, push"
|
||||||
|
echo "Kubepod commands: pod, exec, app, shell, ls, logs, upload"
|
||||||
|
echo "App commands: occ, vikunja"
|
||||||
return 1
|
return 1
|
||||||
|
fi
|
||||||
local command="$1"
|
local command="$1"
|
||||||
shift
|
shift
|
||||||
case "$command" in
|
case "$command" in
|
||||||
|
@ -35,7 +38,7 @@ stack() {
|
||||||
#export GITLAB_CI="true"
|
#export GITLAB_CI="true"
|
||||||
echo Selected "$_cluster_name" with IP "$_cluster_ip"
|
echo Selected "$_cluster_name" with IP "$_cluster_ip"
|
||||||
echo "$_cluster_name" >"$_stackspin_cluster_cache"
|
echo "$_cluster_name" >"$_stackspin_cluster_cache"
|
||||||
test "$PWD" = "$HOME" && builtin cd "$STACKSPIN"
|
#test "$PWD" = "$HOME" && builtin cd "$STACKSPIN"
|
||||||
;;
|
;;
|
||||||
(sso) builtin cd "$STACKSPIN"
|
(sso) builtin cd "$STACKSPIN"
|
||||||
"$0" exec dashboard --container backend -- flask "$@";;
|
"$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 $*";;
|
(occ) "$0" exec nc-nextcloud -c nextcloud -it -- su www-data -s /bin/bash -c "php $command $*";;
|
||||||
(vikunja) local pod=${2:-vikunja}
|
(vikunja) local pod=${2:-vikunja}
|
||||||
case "$1" in
|
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"
|
"$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
|
(restore) "$0" upload "$pod" "$3" -c api
|
||||||
"$0" exec "$pod" -c api -it -- ./vikunja restore "$3"
|
"$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
|
esac
|
||||||
;;
|
;;
|
||||||
# high-level
|
# 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)
|
(ls)
|
||||||
if test $# -gt 1 && ! [[ "$2" =~ ".*/.*" ]]
|
if test $# -gt 1 && ! [[ "$2" =~ ".*/.*" ]]
|
||||||
then "$0" exec "$1" "$2" "$3" -it -- ls -lAhF --group-directories-first "${@:4}"
|
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}")
|
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}"
|
"$0" ls "$1" -c "$container" "${@:2}"
|
||||||
done
|
done
|
||||||
fi;;
|
fi;;
|
||||||
|
@ -88,26 +96,25 @@ stack() {
|
||||||
kubectl cp "$2" -n $("$0" pod "$1$pod_suffix"):$2 "${@:3}"
|
kubectl cp "$2" -n $("$0" pod "$1$pod_suffix"):$2 "${@:3}"
|
||||||
"$0" ls "$1" "${@:3}";;
|
"$0" ls "$1" "${@:3}";;
|
||||||
(exec) "$0" kube exec "$@";;
|
(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
|
# low-level
|
||||||
(kube)
|
(kube)
|
||||||
if ! namespacedpod=$("$0" pod "$2$pod_suffix")
|
test $# -gt 1 || { echo "Please provide a command and pod name" >&2 && return 1; }
|
||||||
then echo "No pod found for $2" >&2
|
local pods=$("$0" pod "$2$pod_suffix") || { echo "No pod found for $2" >&2 && return 1; }
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
local subcommand=$1
|
local subcommand=$1
|
||||||
shift 2
|
shift 2
|
||||||
local commands=()
|
local commands=()
|
||||||
for arg;
|
for arg
|
||||||
do case "$arg" in (-*) break;; (*) commands+="$arg"; shift;; esac
|
do case "$arg" in (-*) break;; (*) commands+="$arg"; shift;; esac
|
||||||
done
|
done
|
||||||
test "$subcommand" = get ||
|
for namespacedpod in $pods; do
|
||||||
highlight "Running $subcommand on $namespacedpod" >&2
|
test "$subcommand" = get ||
|
||||||
kubectl "$subcommand" "$commands[@]" -n $(echo $namespacedpod) "$@";;
|
highlight "Running $subcommand on $namespacedpod" >&2
|
||||||
|
kubectl "$subcommand" "$commands[@]" -n $(echo $namespacedpod) "$@"
|
||||||
|
done;;
|
||||||
(pod)
|
(pod)
|
||||||
local podname=$1
|
test $# -gt 0 && local podname=$1 && shift
|
||||||
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";;
|
||||||
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" "$@"
|
||||||
|
@ -115,10 +122,15 @@ stack() {
|
||||||
fi
|
fi
|
||||||
builtin cd "$STACKSPIN"
|
builtin cd "$STACKSPIN"
|
||||||
# Since the install command can also be given bare to install stackspin itself
|
# Since the install command can also be given bare to install stackspin itself
|
||||||
if test $# -gt 0 -a "$command" = install
|
if test "$command" = "install"; then
|
||||||
then "./install/install-$1.sh" || ./install/install-app.sh "$@"
|
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" "$@"
|
else python3 -m stackspin "$_cluster_name" "$command" "$@"
|
||||||
# pip3 install -r requirements.txt
|
|
||||||
fi;;
|
fi;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
test $# -lt 1 &&
|
if test $# -lt 1; then
|
||||||
echo "Usage: $0 <app> [subdomain] [repo] [namespace]" &&
|
echo "You should be in the root apps folder."
|
||||||
|
echo "Usage: $0 <app> [subdomain] [repo] [namespace]"
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
app=$1
|
app=$1
|
||||||
subdomain=${2:-$app}
|
subdomain=${2:-$app}
|
||||||
repo=${3:-$app}
|
repo=${3:-$app}
|
||||||
namespace=${4:-stackspout}
|
namespace=${4:-stackspout}
|
||||||
|
|
||||||
|
if test "$(basename "$PWD")" != "$subdomain"
|
||||||
|
then mkdir -p "$subdomain" && cd "$subdomain"
|
||||||
|
fi
|
||||||
|
|
||||||
cat <<EOF >$app-oauth-client.yaml
|
cat <<EOF >$app-oauth-client.yaml
|
||||||
apiVersion: hydra.ory.sh/v1alpha1
|
apiVersion: hydra.ory.sh/v1alpha1
|
||||||
kind: OAuth2Client
|
kind: OAuth2Client
|
||||||
|
@ -120,3 +128,7 @@ spec:
|
||||||
storage: 2Gi
|
storage: 2Gi
|
||||||
storageClassName: local-path
|
storageClassName: local-path
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
ls -l
|
||||||
|
echo "To do: Obtain chart version, check configmap, create oauth secrets if needed" >&2
|
||||||
|
exec $SHELL
|
||||||
|
|
Loading…
Reference in New Issue