<commit_before>#!/bin/bash -e

#
# Discover the APP_BASE from the location of this script.
#
if [ -z "$APP_BASE" ] ; then
  DIRNAME=`dirname "$0"`
  APP_BASE=`cd "$DIRNAME"; pwd`
  export APP_BASE
fi

while getopts "fu" opt; do
  case $opt in
    f)
      echo "Cleaning up all existing k8s containers"
      docker rm -f openshift cadvisor || true
      RUNNING_CONTAINERS=`docker ps -a | grep k8s | cut -c 1-12`
      test -x "$RUNNING_CONTAINERS" || docker rm -f $RUNNING_CONTAINERS
      ;;
    u)
      echo "Updating all necessary images"
      for image in google/cadvisor:latest openshift/origin:latest registry:latest tutum/influxdb:latest fabric8/hawtio:latest; do
        docker pull $image
      done
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      ;;
  esac
done

export DOCKER_IP=${DOCKER_IP:-127.0.0.1}
export DOCKER_REGISTRY=$DOCKER_IP:5000
export KUBERNETES_MASTER=http://$DOCKER_IP:8080
export FABRIC8_CONSOLE=http://$DOCKER_IP:8484/hawtio

docker run -d --name=openshift -v /var/run/docker.sock:/var/run/docker.sock --privileged --net=host openshift/origin:latest start

docker run -d --name=cadvisor -p 4194:8080 \
  --volume=/:/rootfs:ro \
  --volume=/var/run:/var/run:rw \
  --volume=/sys:/sys:ro \
  --volume=/var/lib/docker/:/var/lib/docker:ro \
  google/cadvisor:latest

# using an env var but ideally we'd use an alias ;)
KUBE="docker run --rm -i --net=host -e KUBERNETES_MASTER=http://$DOCKER_IP:8080 openshift/origin:latest kube"

if [ -f "$APP_BASE/registry.json" ]; then
  cat $APP_BASE/registry.json | $KUBE apply -c -
  cat $APP_BASE/influxdb.json | $KUBE apply -c -
  cat $APP_BASE/fabric8.json | $KUBE apply -c -
  cat $APP_BASE/elasticsearch.json | $KUBE apply -c -
else
  $KUBE apply -c https://raw.githubusercontent.com/fabric8io/fabric8/master/bin/registry.json
  $KUBE apply -c https://raw.githubusercontent.com/fabric8io/fabric8/master/bin/influxdb.json
  $KUBE apply -c https://raw.githubusercontent.com/fabric8io/fabric8/master/bin/fabric8.json
  $KUBE apply -c https://raw.githubusercontent.com/fabric8io/fabric8/master/bin/elasticsearch.json
fi<commit_msg>Dodgy test before delete containers, display running services<commit_after>#!/bin/bash -e

#
# Discover the APP_BASE from the location of this script.
#
if [ -z "$APP_BASE" ] ; then
  DIRNAME=`dirname "$0"`
  APP_BASE=`cd "$DIRNAME"; pwd`
  export APP_BASE
fi

while getopts "fud:" opt; do
  case $opt in
    f)
      echo "Cleaning up all existing k8s containers"
      docker rm -f openshift cadvisor 2>/dev/null || true
      RUNNING_CONTAINERS=`docker ps -a | grep k8s | cut -c 1-12`
      test -z "$RUNNING_CONTAINERS" || docker rm -f $RUNNING_CONTAINERS
      ;;
    u)
      echo "Updating all necessary images"
      for image in google/cadvisor:latest openshift/origin:latest registry:latest tutum/influxdb:latest fabric8/hawtio:latest; do
        docker pull $image
      done
      ;;
    d)
      DOCKER_IP=$OPTARG
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      ;;
  esac
done

export DOCKER_IP=${DOCKER_IP:-127.0.0.1}
export DOCKER_REGISTRY=$DOCKER_IP:5000
export KUBERNETES_MASTER=http://$DOCKER_IP:8080
export FABRIC8_CONSOLE=http://$DOCKER_IP:8484/hawtio

docker run -d --name=openshift -v /var/run/docker.sock:/var/run/docker.sock --privileged --net=host openshift/origin:latest start

docker run -d --name=cadvisor -p 4194:8080 \
  --volume=/:/rootfs:ro \
  --volume=/var/run:/var/run:rw \
  --volume=/sys:/sys:ro \
  --volume=/var/lib/docker/:/var/lib/docker:ro \
  google/cadvisor:latest

# using an env var but ideally we'd use an alias ;)
KUBE="docker run --rm -i --net=host openshift/origin:latest kube"

if [ -f "$APP_BASE/registry.json" ]; then
  cat $APP_BASE/registry.json | $KUBE apply -c -
  cat $APP_BASE/influxdb.json | $KUBE apply -c -
  cat $APP_BASE/fabric8.json | $KUBE apply -c -
  cat $APP_BASE/elasticsearch.json | $KUBE apply -c -
else
  $KUBE apply -c https://raw.githubusercontent.com/fabric8io/fabric8/master/bin/registry.json
  $KUBE apply -c https://raw.githubusercontent.com/fabric8io/fabric8/master/bin/influxdb.json
  $KUBE apply -c https://raw.githubusercontent.com/fabric8io/fabric8/master/bin/fabric8.json
  $KUBE apply -c https://raw.githubusercontent.com/fabric8io/fabric8/master/bin/elasticsearch.json
fi

getServiceIpAndPort()
{
  echo `$KUBE get services/$1|grep $1| sed 's/\s\+/ /g' | awk '{ print $3 ":" $4 }'`
}
echo
echo "You now have the following services running:"
echo
echo "Fabric8: http://$(getServiceIpAndPort hawtio-service)"
echo "Docker Registry: http://$(getServiceIpAndPort registry-service)"
echo "Influxdb: http://$(getServiceIpAndPort influx-master)"
echo "Elasticsearch: http://$(getServiceIpAndPort elasticsearch)"
{'fraction_non_alphanumeric': 0.1398941798941799, 'fraction_numerical': 0.021164021164021163, 'mean_word_length': 3.4711447492904446, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6861037', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1737, 'n_words': 399}