Dgraph

From BITPlan Wiki
Revision as of 09:01, 5 August 2020 by Wf (talk | contribs)
Jump to navigation Jump to search

Ratel

2020-08-05

docker pull dgraph/dgraph:v20.03.0
mkdir -p ~/dgraph

Dgraph start script

see https://stackoverflow.com/questions/63260073/starting-zero-alpha-and-ratel-in-a-single-command-e-g-in-macosx-and-other-envir

#!/bin/bash
# WF 2020-08-05
# see https://dgraph.io/tour/intro/2/

version=v20.03.0

#ansi colors
#http://www.csc.uvic.ca/~sae/seng265/fall04/tips/s265s047-tips/bash-using-colors.html
blue='\033[0;34m'
red='\033[0;31m'
green='\033[0;32m' # '\e[1;32m' is too bright for white bg.
endColor='\033[0m'

#
# a colored message
#   params:
#     1: l_color - the color of the message
#     2: l_msg - the message to display
#
color_msg() {
  local l_color="$1"
  local l_msg="$2"
  echo -e "${l_color}$l_msg${endColor}"
}

#
# error
#
# show the given error message on stderr and exit
#
#   params:
#     1: l_msg - the error message to display
#
error() {
  local l_msg="$1"
  # use ansi red for error
  color_msg $red "Error:" 1>&2
  color_msg $red "\t$l_msg" 1>&2
  exit 1
}


# show usage
#
usage() {
  echo "$0 [-h|--help|-k|--kill"
  echo ""
  echo "-b | --bash: start a bash terminal shell within the currently running container"
  echo "-h | --help: show this usage"
  echo "-k | --kill: stop the docker image"
  exit 1
}

#
# stop the docker image
#
stopImage() {
  color_msg $blue "stopping and removing dgraph image ..."
  docker stop dgraph
  docker rm dgraph
  color_msg $green "...done"
}

#
# start a bash shell within the currently running container
#
bashInto() {
  sudo docker exec -it dgraph bash
}

#
# dgraph zero
#
zero() {
  docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 \
  -p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph --name dgraph \
  dgraph/dgraph:$version dgraph zero
}

#
# dgraph alpha
#
alpha() {
  docker exec -it dgraph dgraph alpha --lru_mb 2048 --zero localhost:5080 --whitelist 0.0.0.0/0
}

#
# dgraph ratel
#
ratel() {
  docker exec -it dgraph dgraph-ratel
}

me=$0
dir=$(dirname $0)
base=$(basename $0)
if [ $# -lt 1 ]
then
case $base in
  dgraph)
    # Run Dgraph zero
    # And in another, run ratel (Dgraph UI)
    # In another terminal, now run Dgraph alpha
    for option in zero ratel alpha
    do
      #echo $dir $option
      open -a terminal.app $dir/$option
      # wait a bit
      sleep 2
    done
    ;;
    alpha) alpha;;
    ratel) ratel;;
    zero) zero;;
  esac
fi
# commandline option
while [  "$1" != ""  ]
do
  option="$1"
  case $option in
    alpha) alpha;;
    ratel) ratel;;
    zero) zero;;
    -b|--bash) bashInto;;
    -k|--kill) stopImage;;
    -h|--help) usage;;
  esac
  shift
done