<commit_before>#!/bin/bash
set -e

DEFAULT_CHE_IMAGE_REPO=rhche/che-server
DEFAULT_CHE_IMAGE_TAG=nightly

CHE_IMAGE_REPO=${CHE_IMAGE_REPO:-${DEFAULT_CHE_IMAGE_REPO}}
CHE_IMAGE_TAG=${CHE_IMAGE_TAG:-${DEFAULT_CHE_IMAGE_TAG}}

CHE_IMAGE_REPO=$(echo $CHE_IMAGE_REPO | sed 's/\//\\\//g')

# minishift is running
echo "# Checking if minishift is running..."
minishift status | grep -q "Running" ||(echo "Minishift is not running. Aborting"; exit 1)

if [ -z ${OPENSHIFT_USERNAME+x} ]; then echo "Env var OPENSHIFT_USERNAME is unset. Aborting"; exit 1; fi
if [ -z ${OPENSHIFT_PASSWORD+x} ]; then echo "Env var OPENSHIFT_PASSWORD is unset. Aborting"; exit 1; fi
if [ -z ${OPENSHIFT_NAMESPACE_URL+x} ]; then echo "Env var OPENSHIFT_NAMESPACE_URL is unset. Aborting"; exit 1; fi
if [ -z ${CHE_LOG_LEVEL+x} ]; then echo "Env var CHE_LOG_LEVEL is unset. Aborting"; exit 1; fi
if [ -z ${CHE_DEBUGGING_ENABLED+x} ]; then echo "Env var CHE_DEBUGGING_ENABLED is unset. Aborting"; exit 1; fi
if [ -z ${FABRIC8_ONLINE_PATH+x} ]; then echo "Env var FABRIC8_ONLINE_PATH is unset. Aborting"; exit 1; fi
if [ -z ${CHE_OPENSHIFT_PROJECT+x} ]; then echo "Env var CHE_OPENSHIFT_PROJECT is unset. Aborting"; exit 1; fi

# if [ ! -d "${FABRIC8_ONLINE_PATH}"apps/che/src/main/fabric8 ]; then echo "Folder ${FABRIC8_ONLINE_PATH}apps/che/src/main/fabric8 does not exists. Aborting"; exit 1; fi 

echo "# oc login ${OPENSHIFT_ENDPOINT}..."
oc login ${OPENSHIFT_ENDPOINT} -u ${OPENSHIFT_USERNAME} -p ${OPENSHIFT_PASSWORD} > /dev/null

# Check if the project exists othewise create it
if ! oc get project ${CHE_OPENSHIFT_PROJECT} &> /dev/null; then
  echo "# Creating project"
  oc new-project ${CHE_OPENSHIFT_PROJECT}
fi

oc project ${CHE_OPENSHIFT_PROJECT}

# Deploy configmaps
echo "# Create configmaps..."
if oc get configmap che &> /dev/null ; then oc delete configmap che &> /dev/null; fi
oc create configmap che \
      --from-literal=hostname-http=${OPENSHIFT_NAMESPACE_URL} \
      --from-literal=workspace-storage="/home/user/che/workspaces" \
      --from-literal=workspace-storage-create-folders="false" \
      --from-literal=local-conf-dir="/etc/conf" \
      --from-literal=openshift-serviceaccountname="che" \
      --from-literal=che-server-evaluation-strategy="single-port" \
      --from-literal=log-level=${CHE_LOG_LEVEL} \
      --from-literal=docker-connector="openshift" \
      --from-literal=port="8080" \
      --from-literal=remote-debugging-enabled=${CHE_DEBUGGING_ENABLED} \
      --from-literal=che-oauth-github-forceactivation="true" \
      --from-literal=workspaces-memory-limit="1300Mi" \
      --from-literal=workspaces-memory-request="500Mi" \
      --from-literal=enable-workspaces-autostart="false" \
      --from-literal=che-server-java-opts="-XX:+UseG1GC -XX:+UseStringDeduplication -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:MaxRAM=700m -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" \
      --from-literal=che-workspaces-java-opts="-XX:+UseG1GC -XX:+UseStringDeduplication -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:MaxRAM=1300m -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" \
      --from-literal=che-openshift-secure-routes="false" \
      --from-literal=che-secure-external-urls="false" \
      --from-literal=che-server-timeout-ms="0"

# Deploy PVs (gofabric8 way)
#   gofabric8 should be installed:
#   https://github.com/fabric8io/gofabric8#getting-started
echo "# Create pvc..."
# TODO check if the pvc exist
oc apply -f ${FABRIC8_ONLINE_PATH}apps/che/src/main/fabric8/data-pvc.yml
oc apply -f ${FABRIC8_ONLINE_PATH}apps/che/src/main/fabric8/workspace-pvc.yml
oc login ${OPENSHIFT_ENDPOINT} -u system:admin -n ${CHE_OPENSHIFT_PROJECT}  > /dev/null
# TODO check if pv exists (or if pvc has been bounded)
gofabric8 volumes
oc login ${OPENSHIFT_ENDPOINT} -u ${OPENSHIFT_USERNAME} -p ${OPENSHIFT_PASSWORD} -n ${CHE_OPENSHIFT_PROJECT}  > /dev/null

# Wait a few seconds for the PVCs to be bound to a PV before the starting the pods
sleep 5

# Create and configure service account
# TODO check if service account already exists
echo "# Create service account..."
echo "apiVersion: \"v1\"<commit_msg>Add param for subpath creation to create-all.sh<commit_after>#!/bin/bash
set -e

DEFAULT_CHE_IMAGE_REPO=rhche/che-server
DEFAULT_CHE_IMAGE_TAG=nightly

CHE_IMAGE_REPO=${CHE_IMAGE_REPO:-${DEFAULT_CHE_IMAGE_REPO}}
CHE_IMAGE_TAG=${CHE_IMAGE_TAG:-${DEFAULT_CHE_IMAGE_TAG}}

CHE_IMAGE_REPO=$(echo $CHE_IMAGE_REPO | sed 's/\//\\\//g')

# minishift is running
echo "# Checking if minishift is running..."
minishift status | grep -q "Running" ||(echo "Minishift is not running. Aborting"; exit 1)

if [ -z ${OPENSHIFT_USERNAME+x} ]; then echo "Env var OPENSHIFT_USERNAME is unset. Aborting"; exit 1; fi
if [ -z ${OPENSHIFT_PASSWORD+x} ]; then echo "Env var OPENSHIFT_PASSWORD is unset. Aborting"; exit 1; fi
if [ -z ${OPENSHIFT_NAMESPACE_URL+x} ]; then echo "Env var OPENSHIFT_NAMESPACE_URL is unset. Aborting"; exit 1; fi
if [ -z ${CHE_LOG_LEVEL+x} ]; then echo "Env var CHE_LOG_LEVEL is unset. Aborting"; exit 1; fi
if [ -z ${CHE_DEBUGGING_ENABLED+x} ]; then echo "Env var CHE_DEBUGGING_ENABLED is unset. Aborting"; exit 1; fi
if [ -z ${FABRIC8_ONLINE_PATH+x} ]; then echo "Env var FABRIC8_ONLINE_PATH is unset. Aborting"; exit 1; fi
if [ -z ${CHE_OPENSHIFT_PROJECT+x} ]; then echo "Env var CHE_OPENSHIFT_PROJECT is unset. Aborting"; exit 1; fi

# if [ ! -d "${FABRIC8_ONLINE_PATH}"apps/che/src/main/fabric8 ]; then echo "Folder ${FABRIC8_ONLINE_PATH}apps/che/src/main/fabric8 does not exists. Aborting"; exit 1; fi 

echo "# oc login ${OPENSHIFT_ENDPOINT}..."
oc login ${OPENSHIFT_ENDPOINT} -u ${OPENSHIFT_USERNAME} -p ${OPENSHIFT_PASSWORD} > /dev/null

# Check if the project exists othewise create it
if ! oc get project ${CHE_OPENSHIFT_PROJECT} &> /dev/null; then
  echo "# Creating project"
  oc new-project ${CHE_OPENSHIFT_PROJECT}
fi

oc project ${CHE_OPENSHIFT_PROJECT}

# Deploy configmaps
echo "# Create configmaps..."
if oc get configmap che &> /dev/null ; then oc delete configmap che &> /dev/null; fi
oc create configmap che \
      --from-literal=hostname-http=${OPENSHIFT_NAMESPACE_URL} \
      --from-literal=workspace-storage="/home/user/che/workspaces" \
      --from-literal=workspace-storage-create-folders="false" \
      --from-literal=local-conf-dir="/etc/conf" \
      --from-literal=openshift-serviceaccountname="che" \
      --from-literal=che-server-evaluation-strategy="single-port" \
      --from-literal=log-level=${CHE_LOG_LEVEL} \
      --from-literal=docker-connector="openshift" \
      --from-literal=port="8080" \
      --from-literal=remote-debugging-enabled=${CHE_DEBUGGING_ENABLED} \
      --from-literal=che-oauth-github-forceactivation="true" \
      --from-literal=workspaces-memory-limit="1300Mi" \
      --from-literal=workspaces-memory-request="500Mi" \
      --from-literal=enable-workspaces-autostart="false" \
      --from-literal=che-server-java-opts="-XX:+UseG1GC -XX:+UseStringDeduplication -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:MaxRAM=700m -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" \
      --from-literal=che-workspaces-java-opts="-XX:+UseG1GC -XX:+UseStringDeduplication -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:MaxRAM=1300m -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" \
      --from-literal=che-openshift-secure-routes="false" \
      --from-literal=che-secure-external-urls="false" \
      --from-literal=che-server-timeout-ms="0" \
      --from-literal=che-openshift-precreate-subpaths="true"

# Deploy PVs (gofabric8 way)
#   gofabric8 should be installed:
#   https://github.com/fabric8io/gofabric8#getting-started
echo "# Create pvc..."
# TODO check if the pvc exist
oc apply -f ${FABRIC8_ONLINE_PATH}apps/che/src/main/fabric8/data-pvc.yml
oc apply -f ${FABRIC8_ONLINE_PATH}apps/che/src/main/fabric8/workspace-pvc.yml
oc login ${OPENSHIFT_ENDPOINT} -u system:admin -n ${CHE_OPENSHIFT_PROJECT}  > /dev/null
# TODO check if pv exists (or if pvc has been bounded)
gofabric8 volumes
oc login ${OPENSHIFT_ENDPOINT} -u ${OPENSHIFT_USERNAME} -p ${OPENSHIFT_PASSWORD} -n ${CHE_OPENSHIFT_PROJECT}  > /dev/null

# Wait a few seconds for the PVCs to be bound to a PV before the starting the pods
sleep 5

# Create and configure service account
# TODO check if service account already exists
echo "# Create service account..."
echo "apiVersion: \"v1\"
{'fraction_non_alphanumeric': 0.13862207992410766, 'fraction_numerical': 0.01304399383374837, 'mean_word_length': 4.3994878361075545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '5357004', 'n_tokens_mistral': 3108, 'n_tokens_neox': 2978, 'n_words': 668}