<commit_before>#!/bin/bash

#
# 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

OPENSHIFT_VERSION=v0.4.2

FABRIC8_VERSION=172.16.31.10
OPENSHIFT_IMAGE=openshift/origin:${OPENSHIFT_VERSION}
OPENSHIFT_ROUTER_IMAGE=openshift/origin-haproxy-router:${OPENSHIFT_VERSION}
REGISTRY_IMAGE=openshift/origin-docker-registry:${OPENSHIFT_VERSION}
INFLUXDB_IMAGE=tutum/influxdb:latest
FABRIC8_CONSOLE_IMAGE=fabric8/hawtio-kubernetes:latest
KIBANA_IMAGE=jimmidyson/kibana4:latest
ELASTICSEARCH_IMAGE=fabric8/elasticsearch-k8s:1.5.0
FLUENTD_IMAGE=fabric8/fluentd-kubernetes:latest
#GRAFANA_IMAGE=jimmidyson/grafana:latest
APP_LIBRARY_IMAGE=fabric8/app-library:${FABRIC8_VERSION}
FORGE_IMAGE=fabric8/fabric8-forge:${FABRIC8_VERSION}
KIWIIRC_IMAGE=fabric8/fabric8-kiwiirc:latest
REDIS_IMAGE=redis:latest
GOIRC_SERVER_IMAGE=lonli078/go-irc-server:latest
HUBOT_IMAGE=fabric8/hubot:latest
HUBOT_NOTIFIER=fabric8/hubot-notifier:${FABRIC8_VERSION}

MINIMUM_IMAGES="${OPENSHIFT_IMAGE} ${FABRIC8_CONSOLE_IMAGE} ${APP_LIBRARY_IMAGE} ${REGISTRY_IMAGE} ${OPENSHIFT_ROUTER_IMAGE}"
ALL_IMAGES="${MINIMUM_IMAGES} ${INFLUXDB_IMAGE} ${KIBANA_IMAGE} ${ELASTICSEARCH_IMAGE} ${FLUENTD_IMAGE} ${GRAFANA_IMAGE} ${FORGE_IMAGE} ${KIWIIRC_IMAGE} ${REDIS_IMAGE} ${GOIRC_SERVER_IMAGE} ${HUBOT_IMAGE} ${HUBOT_NOTIFIER}"
DEPLOY_IMAGES="${MINIMUM_IMAGES}"
UPDATE_IMAGES=0
DEPLOY_ALL=0
CLEANUP=0
DONT_RUN=0
FABRIC8_VAGRANT_IP=172.28.128.4
OPENSHIFT_ADMIN_PASSWORD=<PASSWORD>
OPENSHIFT_MASTER_URL=localhost

while getopts "fud:kpm:P:" opt; do
  case $opt in
    k)
      DEPLOY_IMAGES="${ALL_IMAGES}"
      DEPLOY_ALL=1
      ;;
    f)
      echo "Cleaning up all existing k8s containers"
      docker rm -fv openshift || true
      RUNNING_CONTAINERS=`docker ps -a | grep k8s | cut -c 1-12`
      test -z "$RUNNING_CONTAINERS" || docker rm -fv $RUNNING_CONTAINERS
      CLEANUP=1
      echo
      ;;
    u)
      UPDATE_IMAGES=1
      ;;
    p)
      UPDATE_IMAGES=1
      DONT_RUN=1
      ;;
    d)
      DOCKER_IP=$OPTARG
      ;;
    m)
      OPENSHIFT_MASTER_URL=${OPTARG##http*://}
      ;;
    P)
      OPENSHIFT_ADMIN_PASSWORD=$OPTARG
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      echo
      ;;
  esac
done

echo "Validating your environment..."
echo

if [ ${UPDATE_IMAGES} -eq 1 ]; then
  echo "Updating all necessary images"
  for image in ${DEPLOY_IMAGES}; do
    docker pull $image
  done
  echo
fi

for image in ${DEPLOY_IMAGES}; do
  (
    IFS=':' read -a splitimage <<< "$image"
    docker images | grep -qEo "${splitimage[0]}\W+${splitimage[1]}" || (echo "Missing necessary Docker image: $image" && docker pull $image && echo)
  )
done

if [ ${CLEANUP} -eq 1 ]; then
  docker run --rm --privileged -v /var/lib:/var/lib --entrypoint=rm ${OPENSHIFT_IMAGE} -rf /var/lib/openshift/
fi

if [ ${DONT_RUN} -eq 1 ]; then
  echo "Terminating before running any containers"
  exit 0
fi

echo "Validating firewall rules"
RULE="INPUT -d 172.17.42.1 -s 172.17.0.0/16 -j ACCEPT"
RULE_OUTPUT=$( { docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -C $RULE; } 2>&1 )
test -n "$RULE_OUTPUT" && docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -I $RULE
RULE="INPUT -d 172.17.0.0/16 -s 172.16.31.10/16 -j ACCEPT"
RULE_OUTPUT=$( { docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -C $RULE; } 2>&1 )
test -n "$RULE_OUTPUT" && docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -I $RULE
RULE="INPUT -d 172.16.31.10/16 -s 172.17.0.0/16 -j ACCEPT"
RULE_OUTPUT=$( { docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -C $RULE; } 2>&1 )
test -n "$RULE_OUTPUT" && docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -I $RULE
RULE="INPUT -d 172.30.17.0/24 -s 172.17.0.0/16 -j ACCEPT"
RULE_OUTPUT=$( { docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -C $RULE; } 2>&1 )
test -n "$RULE_OUTPUT" && docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -I $RULE
RULE="INPUT -d 172.17.0.0/16 -s 172.30.17.0/24 -j ACCEPT"
RULE_OUTPUT=$( { docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -C $RULE; } 2>&1 )
test -n "$RULE_OUTPUT" && docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -I $RULE
echo

# TODO it would be nice if we could tell easily if these routes have already been applied so we don't have to do this each time
if [[ $OSTYPE == darwin* ]]; then
    if [ -z "$DOCKER_IP" ] ; then
      export DOCKER_IP=`boot2docker ip 2> /dev/null`
    fi

    echo "Adding network routes to 172.17.0.0/24, 172.30.17.0/24 & 172.16.58.3/24 via $DOCKER_IP so that the host operating system can see pods and services inside OpenShift"
    sudo route delete 172.17.0.0
    sudo route -n add 172.17.0.0/24 $DOCKER_IP
    sudo route delete 172.30.17.0
    sudo route -n add 172.30.17.0/24 $DOCKER_IP
    sudo route delete 172.16.58.3
    sudo route -n add 172.16.58.3/24 $DOCKER_IP
fi

export DOCKER_IP=${DOCKER_IP:-127.0.0.1}
export KUBERNETES=https://$DOCKER_IP:8443

# using an env var but ideally we'd use an alias ;)
KUBE="docker exec -i openshift openshift cli"

if [ -n "${OPENSHIFT_MASTER_URL}" ]; then
  PUBLIC_MASTER_ARG="--public-master=${OPENSHIFT_MASTER_URL}"
fi

if [ -n "${OPENSHIFT_ADMIN_PASSWORD}" ]; then
  echo "Configuring OpenShift authentication"
  docker run -v /openshift gliderlabs/alpine:3.1 sh -c "apk-install apache2-utils && htpasswd -bc /openshift/htpasswd admin ${OPENSHIFT_ADMIN_PASSWORD}" &> /dev/null
  OPENSHIFT_VOLUME_MOUNT="--volumes-from=$(docker ps -ql)"
  OPENSHIFT_OAUTH_ARGS="-e OPENSHIFT_OAUTH_PASSWORD_AUTH=htpasswd -e OPENSHIFT_OAUTH_HTPASSWD_FILE=/openshift/htpasswd"
fi

OPENSHIFT_CONTAINER=$(docker run -d --name=openshift ${OPENSHIFT_VOLUME_MOUNT} -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/openshift:/var/lib/openshift --privileged --net=host ${OPENSHIFT_OAUTH_ARGS} ${OPENSHIFT_IMAGE} start --portal-net='172.30.17.0/24' --cors-allowed-origins='.*' ${PUBLIC_MASTER_ARG})

validateService()
{
  echo "Waiting for $1"
  while true; do
    curl -k -s -o /dev/null --connect-timeout 1 $2 && break || sleep 1
  done
}

validateService "Kubernetes master" $KUBERNETES
docker exec -i openshift sh -c "openshift ex --credentials=\$KUBECONFIG router --create"
docker exec -i openshift sh -c "openshift ex --credentials=\$KUBECONFIG registry --create"
docker exec -i openshift sh -c "openshift ex policy add-role-to-user cluster-admin admin -n master"
docker exec -i openshift sh -c "openshift admin policy add-role-to-group cluster-admin system:authenticated system:unauthenticated"
<commit_msg>OpenShift 0.4.3 upgrade - disabling auth for now<commit_after>#!/bin/bash

#
# 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

OPENSHIFT_VERSION=v0.4.3

FABRIC8_VERSION=2.0.40.1
OPENSHIFT_IMAGE=openshift/origin:${OPENSHIFT_VERSION}
OPENSHIFT_ROUTER_IMAGE=openshift/origin-haproxy-router:${OPENSHIFT_VERSION}
REGISTRY_IMAGE=openshift/origin-docker-registry:${OPENSHIFT_VERSION}
INFLUXDB_IMAGE=tutum/influxdb:latest
FABRIC8_CONSOLE_IMAGE=fabric8/hawtio-kubernetes:latest
KIBANA_IMAGE=jimmidyson/kibana4:latest
ELASTICSEARCH_IMAGE=fabric8/elasticsearch-k8s:1.5.0
FLUENTD_IMAGE=fabric8/fluentd-kubernetes:latest
#GRAFANA_IMAGE=jimmidyson/grafana:latest
APP_LIBRARY_IMAGE=fabric8/app-library:${FABRIC8_VERSION}
FORGE_IMAGE=fabric8/fabric8-forge:${FABRIC8_VERSION}
KIWIIRC_IMAGE=fabric8/fabric8-kiwiirc:latest
REDIS_IMAGE=redis:latest
GOIRC_SERVER_IMAGE=lonli078/go-irc-server:latest
HUBOT_IMAGE=fabric8/hubot:latest
HUBOT_NOTIFIER=fabric8/hubot-notifier:${FABRIC8_VERSION}

MINIMUM_IMAGES="${OPENSHIFT_IMAGE} ${FABRIC8_CONSOLE_IMAGE} ${APP_LIBRARY_IMAGE} ${REGISTRY_IMAGE} ${OPENSHIFT_ROUTER_IMAGE}"
ALL_IMAGES="${MINIMUM_IMAGES} ${INFLUXDB_IMAGE} ${KIBANA_IMAGE} ${ELASTICSEARCH_IMAGE} ${FLUENTD_IMAGE} ${GRAFANA_IMAGE} ${FORGE_IMAGE} ${KIWIIRC_IMAGE} ${REDIS_IMAGE} ${GOIRC_SERVER_IMAGE} ${HUBOT_IMAGE} ${HUBOT_NOTIFIER}"
DEPLOY_IMAGES="${MINIMUM_IMAGES}"
UPDATE_IMAGES=0
DEPLOY_ALL=0
CLEANUP=0
DONT_RUN=0
FABRIC8_VAGRANT_IP=172.28.128.4
OPENSHIFT_ADMIN_PASSWORD=<PASSWORD>
OPENSHIFT_MASTER_URL=localhost

while getopts "fud:kpm:P:" opt; do
  case $opt in
    k)
      DEPLOY_IMAGES="${ALL_IMAGES}"
      DEPLOY_ALL=1
      ;;
    f)
      echo "Cleaning up all existing k8s containers"
      docker rm -fv openshift || true
      RUNNING_CONTAINERS=`docker ps -a | grep k8s | cut -c 1-12`
      test -z "$RUNNING_CONTAINERS" || docker rm -fv $RUNNING_CONTAINERS
      CLEANUP=1
      echo
      ;;
    u)
      UPDATE_IMAGES=1
      ;;
    p)
      UPDATE_IMAGES=1
      DONT_RUN=1
      ;;
    d)
      DOCKER_IP=$OPTARG
      ;;
    m)
      OPENSHIFT_MASTER_URL=${OPTARG##http*://}
      ;;
    P)
      OPENSHIFT_ADMIN_PASSWORD=$OPTARG
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      echo
      ;;
  esac
done

echo "Validating your environment..."
echo

if [ ${UPDATE_IMAGES} -eq 1 ]; then
  echo "Updating all necessary images"
  for image in ${DEPLOY_IMAGES}; do
    docker pull $image
  done
  echo
fi

for image in ${DEPLOY_IMAGES}; do
  (
    IFS=':' read -a splitimage <<< "$image"
    docker images | grep -qEo "${splitimage[0]}\W+${splitimage[1]}" || (echo "Missing necessary Docker image: $image" && docker pull $image && echo)
  )
done

if [ ${CLEANUP} -eq 1 ]; then
  docker run --rm --privileged -v /var/lib:/var/lib --entrypoint=rm ${OPENSHIFT_IMAGE} -rf /var/lib/openshift/
fi

if [ ${DONT_RUN} -eq 1 ]; then
  echo "Terminating before running any containers"
  exit 0
fi

echo "Validating firewall rules"
RULE="INPUT -d 172.17.42.1 -s 172.17.0.0/16 -j ACCEPT"
RULE_OUTPUT=$( { docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -C $RULE; } 2>&1 )
test -n "$RULE_OUTPUT" && docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -I $RULE
RULE="INPUT -d 172.17.0.0/16 -s 172.16.31.10/16 -j ACCEPT"
RULE_OUTPUT=$( { docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -C $RULE; } 2>&1 )
test -n "$RULE_OUTPUT" && docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -I $RULE
RULE="INPUT -d 172.16.31.10/16 -s 172.17.0.0/16 -j ACCEPT"
RULE_OUTPUT=$( { docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -C $RULE; } 2>&1 )
test -n "$RULE_OUTPUT" && docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -I $RULE
RULE="INPUT -d 172.30.17.0/24 -s 172.17.0.0/16 -j ACCEPT"
RULE_OUTPUT=$( { docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -C $RULE; } 2>&1 )
test -n "$RULE_OUTPUT" && docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -I $RULE
RULE="INPUT -d 172.17.0.0/16 -s 172.30.17.0/24 -j ACCEPT"
RULE_OUTPUT=$( { docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -C $RULE; } 2>&1 )
test -n "$RULE_OUTPUT" && docker run --rm --privileged --net=host --entrypoint=iptables ${OPENSHIFT_IMAGE} -I $RULE
echo

# TODO it would be nice if we could tell easily if these routes have already been applied so we don't have to do this each time
if [[ $OSTYPE == darwin* ]]; then
    if [ -z "$DOCKER_IP" ] ; then
      export DOCKER_IP=`boot2docker ip 2> /dev/null`
    fi

    echo "Adding network routes to 172.17.0.0/24, 172.30.17.0/24 & 172.16.58.3/24 via $DOCKER_IP so that the host operating system can see pods and services inside OpenShift"
    sudo route delete 172.17.0.0
    sudo route -n add 172.17.0.0/24 $DOCKER_IP
    sudo route delete 172.30.17.0
    sudo route -n add 172.30.17.0/24 $DOCKER_IP
    sudo route delete 172.16.58.3
    sudo route -n add 172.16.58.3/24 $DOCKER_IP
fi

export DOCKER_IP=${DOCKER_IP:-127.0.0.1}
export KUBERNETES=https://$DOCKER_IP:8443

# using an env var but ideally we'd use an alias ;)
KUBE="docker exec -i openshift openshift cli"

if [ -n "${OPENSHIFT_MASTER_URL}" ]; then
  PUBLIC_MASTER_ARG="--public-master=${OPENSHIFT_MASTER_URL}"
fi

#if [ -n "${OPENSHIFT_ADMIN_PASSWORD}" ]; then
#  echo "Configuring OpenShift authentication"
#  docker run -v /openshift gliderlabs/alpine:3.1 sh -c "apk-install apache2-utils && htpasswd -bc /openshift/htpasswd admin ${OPENSHIFT_ADMIN_PASSWORD}" &> /dev/null
#  OPENSHIFT_VOLUME_MOUNT="--volumes-from=$(docker ps -ql)"
#  OPENSHIFT_OAUTH_ARGS="-e OPENSHIFT_OAUTH_PASSWORD_AUTH=htpasswd -e OPENSHIFT_OAUTH_HTPASSWD_FILE=/openshift/htpasswd"
#fi

OPENSHIFT_CONTAINER=$(docker run -d --name=openshift ${OPENSHIFT_VOLUME_MOUNT} -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/openshift:/var/lib/openshift --privileged --net=host ${OPENSHIFT_IMAGE} start --portal-net='172.30.17.0/24' --cors-allowed-origins='.*' ${PUBLIC_MASTER_ARG})

validateService()
{
  echo "Waiting for $1"
  while true; do
    curl -k -s -o /dev/null --connect-timeout 1 $2 && break || sleep 1
  done
}

validateService "Kubernetes master" $KUBERNETES
docker exec -i openshift sh -c "openshift ex --credentials=\$KUBECONFIG router --create"
docker exec -i openshift sh -c "openshift ex --credentials=\$KUBECONFIG registry --create"
docker exec -i openshift sh -c "openshift ex policy add-role-to-user cluster-admin admin -n master"
docker exec -i openshift sh -c "openshift admin policy add-role-to-group cluster-admin system:authenticated system:unauthenticated"

{'fraction_non_alphanumeric': 0.14223980077638615, 'fraction_numerical': 0.04138284626089504, 'mean_word_length': 4.075836431226766, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 46, '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': '3490347', 'n_tokens_mistral': 5758, 'n_tokens_neox': 5205, 'n_words': 1211}