|
@@ -0,0 +1,91 @@
|
|
|
+#!/usr/bin/env sh
|
|
|
+
|
|
|
+if [ $# -lt 1 ] || [ "$1" == "help" ] || [ "$1" == "h" ]
|
|
|
+then
|
|
|
+ echo "usage: $0 (help|status|clean|run|logs) [container-name]"
|
|
|
+ echo " help - print this message"
|
|
|
+ echo " status - report whether a container named container-name can be found, and whether or not it is running"
|
|
|
+ echo " clean - kill and remove any existing containers matching container-name"
|
|
|
+ echo " run - kill and remove any existing containers matching container-name, build the current directory into a new image, and deploy a new container container-name"
|
|
|
+ echo " logs - tail the logs of the container named container-name, equivalent to docker logs -f container-name"
|
|
|
+ echo " container-name defaults to ggsh-instance"
|
|
|
+ echo " Run as root to ensure docker can be used, or set FORCE_NOROOT=* to force the script to run anyway."
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
+if [ "$EUID" -ne 0 ] && [ -z "$FORCE_NOROOT" ]
|
|
|
+then
|
|
|
+ echo "$0 must be run as root to use docker. Set FORCE_NOROOT=* to force the script to run anyway."
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
+if [ $# -gt 1 ]
|
|
|
+then
|
|
|
+ CONTAINER_NAME=$2
|
|
|
+else
|
|
|
+ CONTAINER_NAME="ggsh-instance"
|
|
|
+fi
|
|
|
+
|
|
|
+status_check() {
|
|
|
+ docker inspect -f '{{.State.Running}}' $CONTAINER_NAME 2> /dev/null
|
|
|
+}
|
|
|
+
|
|
|
+clean_container() {
|
|
|
+ STATUS=$(status_check)
|
|
|
+ if [ "$STATUS" = "true" ]
|
|
|
+ then
|
|
|
+ echo "Container $CONTAINER_NAME is running and will be stopped and removed."
|
|
|
+ docker kill $CONTAINER_NAME
|
|
|
+ docker rm $CONTAINER_NAME
|
|
|
+ elif [ "$STATUS" = "false" ]
|
|
|
+ then
|
|
|
+ echo "Container $CONTAINER_NAME is stopped and will be removed."
|
|
|
+ docker rm $CONTAINER_NAME
|
|
|
+ else
|
|
|
+ echo "No existing container $CONTAINER_NAME could be found, no cleanup will be performed."
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+case $1 in
|
|
|
+ "l"|"logs")
|
|
|
+ STATUS=$(status_check)
|
|
|
+ if [ "$STATUS" = "true" ] || [ "$STATUS" = "false" ]
|
|
|
+ then
|
|
|
+ docker logs -f $CONTAINER_NAME
|
|
|
+ else
|
|
|
+ echo "No existing container $CONTAINER_NAME could be found."
|
|
|
+ fi
|
|
|
+ ;;
|
|
|
+ "r"|"run")
|
|
|
+ clean_container
|
|
|
+ echo "Building UI"
|
|
|
+ pushd ui
|
|
|
+ yarn build
|
|
|
+ popd
|
|
|
+ echo "Building GeoGuessr Self Host image as ggsh:latest"
|
|
|
+ docker build -t ggsh:latest .
|
|
|
+ echo "Executing new container $CONTAINER_NAME using ggsh:latest"
|
|
|
+ docker run -p6070:80 --name $CONTAINER_NAME -d ggsh
|
|
|
+ echo "Geoguessr Self Host UI accessible at http://localhost:6070/"
|
|
|
+ echo "Geoguessr Self Host API accessible at http://localhost:6070/api/"
|
|
|
+ ;;
|
|
|
+ "c"|"clean")
|
|
|
+ clean_container
|
|
|
+ ;;
|
|
|
+ "s"|"status")
|
|
|
+ STATUS=$(status_check)
|
|
|
+ if [ "$STATUS" = "true" ]
|
|
|
+ then
|
|
|
+ echo "Existing container $CONTAINER_NAME is running."
|
|
|
+ elif [ "$STATUS" = "false" ]
|
|
|
+ then
|
|
|
+ echo "Existing container $CONTAINER_NAME is stopped."
|
|
|
+ else
|
|
|
+ echo "No existing container $CONTAINER_NAME could be found."
|
|
|
+ fi
|
|
|
+ ;;
|
|
|
+ *)
|
|
|
+ echo "Unknown option $1, must be one of help, status, clean, run, logs."
|
|
|
+ exit 1
|
|
|
+ ;;
|
|
|
+esac
|