Skip to content

Commit

Permalink
Fix TEST_MODE on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
roypaulin committed Apr 12, 2024
1 parent cacfa5f commit c27a346
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ vsql: ## Run a basic sanity test (optional -DQUERY="select 'whatever')
.PHONY: verticapylab-start
verticapylab-start: etc/VerticaPyLab.conf ## Start a jupyterlab
@source etc/VerticaPyLab.conf; \
if [[ $${TEST_MODE^^} == "YES" ]] ; then \
VERTICAPYLAB_IMG_VERSION=$(VERSION); \
if [[ $$(tr '[:lower:]' '[:upper:]'<<< ${TEST_MODE}) == "YES" ]] ; then \
VERTICAPYLAB_IMG_VERSION=$(VERSION); \
fi; \
if (($$(docker ps --no-trunc -q -f NAME="$$VERTICAPYLAB_CONTAINER_NAME" | wc -l)==0)); then \
if [[ -z $$(docker image ls -q "opentext/$$VERTICAPYLAB_IMG:$$VERTICAPYLAB_IMG_VERSION" 2>&1) ]]; then \
if [[ $${TEST_MODE^^} == "YES" ]] ; then \
if [[ $$(tr '[:lower:]' '[:upper:]'<<< ${TEST_MODE}) == "YES" ]] ; then \
echo "Building image opentext/$$VERTICAPYLAB_IMG:$$VERTICAPYLAB_IMG_VERSION"; \
TEST_MODE=yes $(MAKE) verticapylab-build; \
else \
Expand Down Expand Up @@ -165,7 +165,7 @@ verticapylab-stop: ## Shut down the jupyterlab server and remove the container
.PHONY: verticapylab-uninstall
verticapylab-uninstall: ## Remove the verticapylab container and associated images.
@source etc/VerticaPyLab.conf; \
if [[ $${TEST_MODE^^} == "YES" ]] ; then \
if [[ $$(tr '[:lower:]' '[:upper:]'<<< ${TEST_MODE}) == "YES" ]] ; then \
VERTICAPYLAB_IMG_VERSION=$(VERSION); \
fi; \
docker stop "$$VERTICAPYLAB_CONTAINER_NAME" >/dev/null 2>&1; \
Expand Down
61 changes: 33 additions & 28 deletions bin/verticapylab
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,42 @@ else
url_host="$VERTICAPYLAB_BIND_ADDRESS"
fi

function openURL() {
container=$1
host=$2
URL=$(docker logs "$container" 2>&1 | grep -Eo 'http[s]?://[0-9.]+:8888/.*' | head -n 1 | sed "s/[0-9.]*:8888/$host:$VERTICAPYLAB_PORT/")
# This checks the kernel name to set the correct command to open the link in browser,
# because Linux systems will use xdg-open while MacOs will use open
if [[ $OSTYPE == darwin* ]]; then # OSX uses different args for stat
OPEN_CMD=open
elif [[ $(uname -r) =~ WSL ]]; then
OPEN_CMD="$BIN/open"
else
OPEN_CMD=xdg-open
fi
# Open the correct url in browser. We know that the correct url is the second one.
# So even if in some cases a 3rd one is created this will not be affected
echo
echo "Waiting for url to open in browser..."
$OPEN_CMD "$URL" 2> /dev/null
if [[ $? -eq 0 ]]; then
echo
echo "If the link does not open or does not work, copy and paste this URL in browser:"
else
echo
echo "Copy and paste this URL in browser:"
fi
echo " $URL"
}

# If the container already exists, open the url in the browser
if docker exec -i "$VERTICAPYLAB_CONTAINER_NAME" true 2>/dev/null; then
echo "$VERTICAPYLAB_CONTAINER_NAME is already running"
URL=$(docker logs "$VERTICAPYLAB_CONTAINER_NAME" 2>&1 | grep -Eo 'http[s]?://[0-9.]+:8888/.*' | head -n 1 | sed "s/[0-9.]*:8888/$url_host:$VERTICAPYLAB_PORT/")
echo "Copy and paste this URL in browser:"
echo " $URL"
openURL $VERTICAPYLAB_CONTAINER_NAME $url_host
exit 0
fi

if [[ ${TEST_MODE^^} == "YES" ]]; then
if [[ $(tr '[:lower:]' '[:upper:]'<<< ${TEST_MODE}) == "YES" ]] ; then
VERTICAPYLAB_IMG_VERSION=$VERSION
fi

Expand Down Expand Up @@ -137,7 +164,7 @@ Host $VERTICA_HOST_NAME $SSH_CONFIG_EXTRA_HOSTNAME
User dbadmin
" | docker exec -i "$VERTICAPYLAB_CONTAINER_NAME" bash -c 'umask 077; mkdir -p $HOME/.ssh; cat >> $HOME/.ssh/config'

if [[ ${TEST_MODE^^} == "YES" ]]; then
if [[ $(tr '[:lower:]' '[:upper:]'<<< ${TEST_MODE}) == "YESo" ]] ; then
trap ' tput setaf 1; echo "VerticaPy installation failed"; tput sgr0; ' EXIT

echo "Uninstalling old VerticaPy"
Expand All @@ -164,26 +191,4 @@ while ! docker logs -n 5 "$VERTICAPYLAB_CONTAINER_NAME" 2>&1 | grep 'Or copy and
sleep 1
done

URL=$(docker logs "$VERTICAPYLAB_CONTAINER_NAME" 2>&1 | grep -Eo 'http[s]?://[0-9.]+:8888/.*' | head -n 1 | sed "s/[0-9.]*:8888/$url_host:$VERTICAPYLAB_PORT/")
# This checks the kernel name to set the correct command to open the link in browser,
# because Linux systems will use xdg-open while MacOs will use open
if [[ $OSTYPE == darwin* ]]; then # OSX uses different args for stat
OPEN_CMD=open
elif [[ $(uname -r) =~ WSL ]]; then
OPEN_CMD="$BIN/open"
else
OPEN_CMD=xdg-open
fi
# Open the correct url in browser. We know that the correct url is the second one.
# So even if in some cases a 3rd one is created this will not be affected
echo
echo "Waiting for url to open in browser..."
$OPEN_CMD "$URL" 2> /dev/null
if [[ $? -eq 0 ]]; then
echo
echo "If the link does not open or does not work, copy and paste this URL in browser:"
else
echo
echo "Copy and paste this URL in browser:"
fi
echo " $URL"
openURL $VERTICAPYLAB_CONTAINER_NAME $url_host
2 changes: 1 addition & 1 deletion bin/verticapylab-build
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fi
# Load the configuration
source $CONFIG_FILE || abort $? "Cannot load config file $CONFIG_FILE"

if [[ ${TEST_MODE^^} == "YES" ]]; then
if [[ $(tr '[:lower:]' '[:upper:]'<<< ${TEST_MODE}) == "YES" ]] ; then
VERTICAPYLAB_IMG_VERSION=$VERSION
fi

Expand Down

0 comments on commit c27a346

Please sign in to comment.