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

Implement Ngrok command to use with Nginx #750

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
43 changes: 43 additions & 0 deletions commands/ngrok.cmd
anbis marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
[[ ! ${WARDEN_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1

NGROK_AUTHTOKEN_PARAM=${WARDEN_PARAMS[0]}

# ~/.warden/.env
eval "$(cat "${WARDEN_HOME_DIR}/.env" | sed 's/\r$//g' | grep "^WARDEN_")" || exit $?

#
WARDEN_ENV_PATH="$(locateEnvPath)" || exit $?
loadEnvConfig "${WARDEN_ENV_PATH}" || exit $?

if [ -n "$NGROK_AUTHTOKEN_PARAM" ]; then
NGROK_AUTHTOKEN=${NGROK_AUTHTOKEN_PARAM}
else
if [ -n "$WARDEN_NGROK_AUTHTOKEN" ]; then
NGROK_AUTHTOKEN=${WARDEN_NGROK_AUTHTOKEN}
fi
fi

assertDockerRunning

if [[ "${WARDEN_PARAMS[0]}" == "help" ]]; then
$WARDEN_BIN ngrok --help || exit $? && exit $?
fi

if [[ -z "$NGROK_AUTHTOKEN" ]]; then
fatal "Ngrok auth-token is not set (WARDEN_NGROK_AUTHTOKEN=) in '.env' file. Can be also pass as parameter: 'warden ngrok [auth-token]'"
fi

NGINX_CONTAINER_ID=$($WARDEN_BIN env ps -q nginx)
if [[ -z "$NGINX_CONTAINER_ID" ]]; then
fatal "No container found for nginx service."
else
NGINX_CONTAINER=$(docker inspect -f '{{ index (split .Name "/") 1 }}' "${NGINX_CONTAINER_ID}")
fi

NETWORK_NAME=$(docker container inspect ${NGINX_CONTAINER} --format '{{range $key, $value := .NetworkSettings.Networks}}{{printf "%s\n" $key}}{{end}}')
if [[ -z "$NETWORK_NAME" ]]; then
fatal "No networks found for nginx service."
fi

docker run --rm -it --link ${NGINX_CONTAINER} --net ${NETWORK_NAME} -e NGROK_AUTHTOKEN=${NGROK_AUTHTOKEN} ngrok/ngrok:latest http ${NGINX_CONTAINER}:80
12 changes: 12 additions & 0 deletions commands/ngrok.help
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
[[ ! ${WARDEN_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1

WARDEN_USAGE=$(cat <<EOF
\033[33mUsage:\033[0m
ngrok Securely expose local server to the Internet for testing and development (use AUTH-TOKEN from global '.env' or environmental '.env')
ngrok AUTH-TOKEN Run Ngrok with AUTH-TOKEN

\033[33mOptions:\033[0m
-h, --help Display this help menu
EOF
)
1 change: 1 addition & 0 deletions commands/usage.help
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ Warden version $(cat ${WARDEN_DIR}/version)
debug Launches debug enabled shell within current project environment
sign-certificate Signs a wildcard certificate including all passed hostnames on the SAN list
version Show version information
ngrok Securely expose local server to the Internet for testing and development
EOF
)