From 660a2b5a8cc12f4b2f24a9526d4e680c2d0a15ab Mon Sep 17 00:00:00 2001 From: Mart van Santen Date: Wed, 8 Dec 2021 07:56:58 +0100 Subject: [PATCH] - Add check for kratos port - Add new version of port forward script --- run_app.sh | 21 +++++++++++++++++++++ set-ssh-tunnel.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100755 set-ssh-tunnel.sh diff --git a/run_app.sh b/run_app.sh index bcd8613..b8f5f49 100755 --- a/run_app.sh +++ b/run_app.sh @@ -1,5 +1,26 @@ + +GREEN='\033[0;32m' +RED='\033[1;31m' +NC='\033[0m' # No Color + +# Check if kratos port is open +if nc -z localhost 8000; +then + echo -e "${GREEN}Great! It looks like the Kratos Admin port is available${NC}" +else + echo -e "${RED}**********************************************************${NC}" + echo -e "${RED}WARNING! It looks like the Kratos Admin port NOT available${NC}" + echo -e "${RED}please run in a seperate terminal: ${NC}" + echo -e "${RED}./set-ssh-tunnel.sh init.stackspin.net ${NC}" + echo -e "${RED} ${NC}" + echo -e "${RED}We will continue to start the app after 5 seconds. ${NC}" + echo -e "${RED}**********************************************************${NC}" + sleep 5 +fi + export FLASK_APP=app.py export FLASK_ENV=development export SECRET_KEY="e38hq!@0n64g@qe6)5csk41t=ljo2vllog(%k7njnm4b@kh42c" export KRATOS_URL="http://127.0.0.1:8000" + flask run diff --git a/set-ssh-tunnel.sh b/set-ssh-tunnel.sh new file mode 100755 index 0000000..6a1c72a --- /dev/null +++ b/set-ssh-tunnel.sh @@ -0,0 +1,45 @@ +#!/bin/bash + + +host=$1 +namespace=$2 + +if [ "x$host" == "x" ] +then + echo "Please give host of kubernetes master as argument. Optionally a + namespace can be provided. This defaults to 'stackspin'" + echo " " + echo $0 hostname [namespace] + exit 1 +fi + + +if [ "x$namespace" == "x" ] +then + namespace="stackspin" +fi + +admin=`ssh $host -lroot kubectl get service -n $namespace |grep single-sign-on-kratos-admin | awk '{print $3'}` +public=`ssh $host -lroot kubectl get service -n $namespace |grep single-sign-on-kratos-public | awk '{print $3}'` +hydra=`ssh $host -lroot kubectl get service -n $namespace |grep single-sign-on-hydra-admin | awk '{print $3}'` +psql=`ssh $host -lroot kubectl get service -n $namespace |grep single-sign-on-postgres|grep -v headless | awk '{print $3}'` + + +if [ "x$admin" == 'x' ] || [ "x$public" == 'x' ] || [ "x$hydra" == 'x' ] || [ "x$psql" == 'x' ] +then + echo "It seems we where not able find at least one of the remote services" + echo " please make sure that kubectl use the right namespace by default." + echo " normally this is 'stackspin'. If you use a different namespace" + echo " please provide this as second argument" + exit 1 +fi + + +echo " +kratos admin port will be at localhost: 8000 +kratos public port will be at localhost: 8080 +hydra admin port will be at localhost: 4445 +psql port will be at localhost: 5432 +" + +ssh -L 8000:$admin:80 -L 8080:$public:80 -L 4445:$hydra:4445 -L 5432:$psql:5432 root@$host