Skip to content

Instantly share code, notes, and snippets.

@l0rd
Created June 15, 2017 16:45
Show Gist options
  • Save l0rd/def46212843dd8adc14b9f46cdbff227 to your computer and use it in GitHub Desktop.
Save l0rd/def46212843dd8adc14b9f46cdbff227 to your computer and use it in GitHub Desktop.
Che deployment script
#!/bin/bash
set -e
DEFAULT_CHE_IMAGE_REPO="docker.io/rhchestage/che-server"
DEFAULT_CHE_IMAGE_TAG="nightly-fabric8"
CHE_IMAGE_REPO=${CHE_IMAGE_REPO:-${DEFAULT_CHE_IMAGE_REPO}}
CHE_IMAGE_TAG=${CHE_IMAGE_TAG:-${DEFAULT_CHE_IMAGE_TAG}}
# minishift is running
echo "# Checking if minishift is running..."
minishift status | grep -q "Running" ||(echo "Minishift is not running. Aborting"; exit 1)
OPENSHIFT_ENDPOINT=${OPENSHIFT_ENDPOINT:-https://$(minishift ip):8443}
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 "${CHE_OPENSHIFT_PROJECT+x}" ]; then echo "Env var CHE_OPENSHIFT_PROJECT is unset. 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}"
export CHE_IMAGE="${CHE_IMAGE_REPO}:${CHE_IMAGE_TAG}"
# Escape slashes in CHE_IMAGE to use it with sed later
# e.g. docker.io/rhchestage => docker.io\/rhchestage
export CHE_IMAGE_SANITIZED=$(echo "${CHE_IMAGE}" | sed 's/\//\\\//g')
# minishift config
export OSO_TOKEN=$(oc login $OPENSHIFT_ENDPOINT -u developer -p developer > /dev/null && oc whoami -t)
export OSIO_VERSION=$(curl -sSL http://central.maven.org/maven2/io/fabric8/online/apps/che/maven-metadata.xml | grep latest | sed -e 's,.*<latest>\([^<]*\)</latest>.*,\1,g')
# oc apply
oc login ${OPENSHIFT_ENDPOINT} --token=${OSO_TOKEN}
oc project ${CHE_OPENSHIFT_PROJECT}
curl -sSL http://central.maven.org/maven2/io/fabric8/online/apps/che/${OSIO_VERSION}/che-${OSIO_VERSION}-openshift.yml | \
sed "s/ hostname-http:.*/ hostname-http: ${OPENSHIFT_NAMESPACE_URL}/" | \
sed "s/ image:.*/ image: \"${CHE_IMAGE_SANITIZED}\"/" | \
sed "s/ workspaces-memory-limit: 2300Mi/ workspaces-memory-limit: 1300Mi/" | \
sed "s/ workspaces-memory-request: 1500Mi/ workspaces-memory-request: 500Mi/" | \
sed "s/ che-openshift-secure-routes: \"true\"/ che-openshift-secure-routes: \"false\"/" | \
sed "s/ che-secure-external-urls: \"true\"/ che-secure-external-urls: \"false\"/" | \
sed "s/ che-openshift-precreate-subpaths: \"false\"/ che-openshift-precreate-subpaths: \"true\"/" | \
grep -v -e "tls:" -e "insecureEdgeTerminationPolicy: Redirect" -e "termination: edge" | \
oc apply --force=true -f -
# Check if an old che-debug service exists.
if ! oc get svc che-debug &> /dev/null; then
echo "# Dleting old che-debug service"
oc delete svc che-debug
fi
if [ "${CHE_DEBUGGING_ENABLED}" == "true" ]; then
echo "# Create debug route..."
oc expose dc che --name=che-debug --target-port=http-debug --port=8000 --type=NodePort
NodePort=$(oc get service che-debug -o jsonpath='{.spec.ports[0].nodePort}')
echo "And remote debugging is possible attaching to URL $(minishift ip):${NodePort}"
fi
export OPENSHIFT_ENDPOINT="https://$(minishift ip):8443/"
export OPENSHIFT_USERNAME="developer"
export OPENSHIFT_PASSWORD="developer"
export CHE_OPENSHIFT_PROJECT="mario-loriedo-che"
export OPENSHIFT_NAMESPACE_URL="${CHE_OPENSHIFT_PROJECT}.$(minishift ip).nip.io"
export CHE_LOG_LEVEL="DEBUG"
export CHE_DEBUGGING_ENABLED="true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment