Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tunnel ssh option #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion plugins/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ optBuild=false
optSilent=false
optOpen=false
optXdebug=false
optTunnel=true
optHelp=false


Expand All @@ -20,20 +21,22 @@ Up::Execute()

# Analyse des arguments de la ligne de commande grâce à l'utilitaire getopts
local OPTIND opt
while getopts ":dbsoxh-:" opt ; do
while getopts ":dbsoxth-:" opt ; do
case $opt in
d ) optDelete=true;;
b ) optBuild=true;;
s ) optSilent=true;;
o ) optOpen=true;;
x ) optXdebug=true;;
t ) optTunnel=true;;
h ) optHelp=true;;
- ) case $OPTARG in
delete-data ) optDelete=true;;
xdebug ) optXdebug=true;;
build ) optBuild=true;;
silent ) optSilent=true;;
open ) optOpen=true;;
tunnel ) optTunnel=true;;
help ) Up::Usage
exit 0;;
* ) echo "illegal option --$OPTARG"
Expand All @@ -51,6 +54,7 @@ Up::Execute()
Log "optBuild = ${optBuild}"
Log "optSilent = ${optSilent}"
Log "optOpen = ${optOpen}"
Log "optTunnel = ${optTunnel}"
Log "optXdebug = ${optXdebug}"
Log "optHelp = ${optHelp}"

Expand Down Expand Up @@ -118,6 +122,8 @@ Up::Execute()
fi
fi

Up::Tunnel

Up::Message

if [ "$optSilent" = false ]; then
Expand All @@ -144,6 +150,7 @@ Up::Usage()
echo " -x, --xdebug Enable xdebug in PHP container"
echo " -s, --silent Don't run docker-compose log --follow after start"
echo " -o, --open Open browser after start on the $SERVER_NAME url"
echo " -t, --tunnel Start an ssh tunnel, to expose localhost on the internet"
echo " -h, --help Print help information and quit"
echo ""
echo "Start docker-compose after initializing context (databases, ports, proxy, etc... )"
Expand Down Expand Up @@ -328,4 +335,25 @@ Up::Stop()
Up::Message()
{
Log "Up::Message : override function in env.sh to display custom message to the developper"
}

Up::Tunnel()
{
Log "Up::Tunnel : open ssh tunnel : $optTunnel"

if [ "$optTunnel" = true ]; then
Log "run ngrok in background"
Log "ngrok http -region eu --host-header ${SERVER_NAME} ${DOCKER_PORT_HTTP} &"
ngrok http -region eu --host-header ${SERVER_NAME} ${DOCKER_PORT_HTTP} &
echo ""
echo "$(UI.Color.Green)Tunnel SSH lancé $(UI.Color.Default)"
echo ""
NGROK_URL="http://127.0.0.1:4040/"
if [ "$OSTYPE" != 'linux-gnu' ]; then
open "$NGROK_URL"
else
xdg-open "$NGROK_URL"
fi
fi

}