2022-04-28 16:15:51 +00:00
|
|
|
export STACKSPIN="$HOME/stackspin"
|
|
|
|
_stackspin_cluster_cache=/var/tmp/stackspin-cluster
|
|
|
|
|
|
|
|
# Stackspin CLI Wrapper
|
|
|
|
# Initialize once with "stack select example.org",
|
|
|
|
# then it loads the last selected one on startup.
|
|
|
|
# Presumes a mapping like the following in your ssh config:
|
|
|
|
# Host example.org
|
|
|
|
# Hostname [IP]
|
|
|
|
stack() {
|
|
|
|
case "$1" in
|
2022-05-03 16:50:05 +00:00
|
|
|
# stackspin administration
|
2022-04-28 16:15:51 +00:00
|
|
|
(select) shift
|
|
|
|
export _cluster_name="$1"
|
|
|
|
export _cluster_ip="$(ssh -G "$_cluster_name" | grep --max-count 1 "^hostname " | cut -d " " -f2-)"
|
|
|
|
export CLUSTER_DIR="$STACKSPIN/clusters/$_cluster_name"
|
|
|
|
export KUBECONFIG="$CLUSTER_DIR/kube_config_cluster.yml"
|
2022-05-03 16:50:05 +00:00
|
|
|
export GITLAB_CI="true"
|
2022-04-28 16:15:51 +00:00
|
|
|
echo Selected "$_cluster_name" with IP "$_cluster_ip"
|
|
|
|
echo "$_cluster_name" >"$_stackspin_cluster_cache"
|
|
|
|
;;
|
|
|
|
(sso) shift
|
|
|
|
builtin cd "$STACKSPIN"
|
2022-05-03 16:50:05 +00:00
|
|
|
"$0" exec single-sign-on-login -- flask "$@";;
|
2022-04-28 16:15:51 +00:00
|
|
|
(user)
|
|
|
|
if test "$2" = "init"
|
|
|
|
then mail="$3"
|
|
|
|
shift 3
|
|
|
|
stack user create "$mail"
|
|
|
|
stack user update "$mail" name "$*"
|
|
|
|
echo "Initialized user '$*' with email '$mail'"
|
2022-05-03 16:50:05 +00:00
|
|
|
else "$0" exec single-sign-on-login -- flask "$@"
|
2022-04-28 16:15:51 +00:00
|
|
|
fi;;
|
2022-05-03 16:50:05 +00:00
|
|
|
# app clis via kubectl
|
|
|
|
(occ) "$0" exec nc-nextcloud -it -- su www-data -s /bin/bash -c "php $*";;
|
|
|
|
(exec) shift
|
|
|
|
kubectl exec -n $("$0" pod "$1") "${@:2}";;
|
2022-05-03 16:26:15 +00:00
|
|
|
(pod) shift
|
2022-05-03 16:50:05 +00:00
|
|
|
kubectl get pods --all-namespaces -o=custom-columns=S:.metadata.namespace,N:.metadata.name --no-headers "${@:2}" | grep --color=never "$1";;
|
|
|
|
# stackspin bare
|
2022-04-28 16:15:51 +00:00
|
|
|
(*) builtin cd "$STACKSPIN"
|
|
|
|
if test $# -gt 1 -a "$1" = install
|
|
|
|
then shift && "./install/install-$1.sh" || ./install/install-app.sh "$@"
|
|
|
|
else python3 -m stackspin "$_cluster_name" "$@"
|
|
|
|
fi;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
cat "$_stackspin_cluster_cache" 2>/dev/null |
|
|
|
|
while read cluster; do stack select "$cluster"; done
|
2022-05-03 16:50:05 +00:00
|
|
|
|
2022-04-28 16:15:51 +00:00
|
|
|
cd "$HOME/stackspout"
|