Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Updates to support improvements to che-server Docker container #29

Merged
merged 1 commit into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions che-launcher/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,25 @@ init_global_variables() {
DEFAULT_CHE_RESTART_POLICY="no"
DEFAULT_CHE_USER="root"
DEFAULT_CHE_LOG_LEVEL="info"
DEFAULT_CHE_DATA_FOLDER="/home/user/che"
DEFAULT_CHE_DEBUG_SERVER="false"
DEFAULT_CHE_DEBUG_SERVER_PORT="8000"
DEFAULT_CHE_DEBUG_SERVER_SUSPEND="false"
DEFAULT_CHE_DOCKER_MACHINE_HOST_EXTERNAL=$(get_docker_external_hostname)

# Clean eventual user provided paths
CHE_CONF_FOLDER=${CHE_CONF_FOLDER:+$(get_converted_and_clean_path "${CHE_CONF_FOLDER}")}
CHE_DATA_FOLDER=${CHE_DATA_FOLDER:+$(get_converted_and_clean_path "${CHE_DATA_FOLDER}")}
CHE_LOCAL_BINARY=${CHE_LOCAL_BINARY:+$(get_converted_and_clean_path "${CHE_LOCAL_BINARY}")}
CHE_CONF=${CHE_CONF:+$(get_converted_and_clean_path "${CHE_CONF}")}
CHE_CONF_LOCATION="${CHE_CONF}":"${CHE_CONF}:Z"
# "<-- Added comment with quote to fix broken syntax highlighting

DEFAULT_CHE_DATA_FOLDER="/home/user/che"
CHE_DATA=${CHE_DATA:+$(get_converted_and_clean_path "${CHE_DATA}")}
CHE_DATA=${CHE_DATA:-${DEFAULT_CHE_DATA_FOLDER}}
CHE_DATA_LOCATION="${CHE_DATA}":"/data:Z"
# "<-- Added comment with quote to fix broken syntax highlighting

CHE_ASSEMBLY=${CHE_ASSEMBLY:+$(get_converted_and_clean_path "${CHE_ASSEMBLY}")}
CHE_ASSEMBLY_LOCATION="${CHE_ASSEMBLY}":"${CHE_ASSEMBLY}:Z"
# "<-- Added comment with quote to fix broken syntax highlighting

CHE_PRODUCT_NAME=${CHE_PRODUCT_NAME:-${DEFAULT_CHE_PRODUCT_NAME}}
CHE_MINI_PRODUCT_NAME=${CHE_MINI_PRODUCT_NAME:-${DEFAULT_CHE_MINI_PRODUCT_NAME}}
Expand All @@ -81,27 +90,11 @@ init_global_variables() {
CHE_USER=${CHE_USER:-${DEFAULT_CHE_USER}}
CHE_HOST_IP=${CHE_HOST_IP:-${DEFAULT_DOCKER_HOST_IP}}
CHE_LOG_LEVEL=${CHE_LOG_LEVEL:-${DEFAULT_CHE_LOG_LEVEL}}
CHE_DATA_FOLDER=${CHE_DATA_FOLDER:-${DEFAULT_CHE_DATA_FOLDER}}
CHE_DEBUG_SERVER=${CHE_DEBUG_SERVER:-${DEFAULT_CHE_DEBUG_SERVER}}
CHE_DEBUG_SERVER_PORT=${CHE_DEBUG_SERVER_PORT:-${DEFAULT_CHE_DEBUG_SERVER_PORT}}
CHE_DEBUG_SERVER_SUSPEND=${CHE_DEBUG_SERVER_SUSPEND:-${DEFAULT_CHE_DEBUG_SERVER_SUSPEND}}
CHE_DOCKER_MACHINE_HOST_EXTERNAL=${CHE_DOCKER_MACHINE_HOST_EXTERNAL:-${DEFAULT_CHE_DOCKER_MACHINE_HOST_EXTERNAL}}

CHE_CONF_LOCATION="${CHE_CONF_FOLDER}":"/conf:Z"
CHE_STORAGE_LOCATION="${CHE_DATA_FOLDER}/storage":"/home/user/che/storage:Z"
CHE_WORKSPACE_LOCATION="${CHE_DATA_FOLDER}/workspaces":"/home/user/che/workspaces:Z"
CHE_LOCAL_BINARY_LOCATION="${CHE_LOCAL_BINARY}":"/home/user/che:Z"

if [ "${CHE_LOG_LEVEL}" = "debug" ]; then
CHE_DEBUG_OPTION="--log_level:debug"
else
CHE_DEBUG_OPTION=""
fi

if [ "${CHE_DEBUG_SERVER}" = "true" ]; then
CHE_DEBUG_OPTION="${CHE_DEBUG_OPTION} --debug"
fi

USAGE="
Usage:
docker run --rm -t -v /var/run/docker.sock:/var/run/docker.sock ${LAUNCHER_IMAGE_NAME} [COMMAND]
Expand Down
22 changes: 8 additions & 14 deletions che-launcher/launcher_cmds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ start_che_server() {
fi

info "${CHE_PRODUCT_NAME}: Starting container..."
docker_run_with_debug "${CHE_SERVER_IMAGE_NAME}":"${CHE_VERSION}" \
--remote:"${CHE_HOST_IP}" \
-s:uid \
-s:client \
${CHE_DEBUG_OPTION} \
run > /dev/null
docker_run_with_debug "${CHE_SERVER_IMAGE_NAME}":"${CHE_VERSION}" > /dev/null

CURRENT_CHE_SERVER_CONTAINER_ID=$(get_che_server_container_id ${CHE_SERVER_CONTAINER_NAME})
wait_until_container_is_running 10 ${CURRENT_CHE_SERVER_CONTAINER_ID}
Expand Down Expand Up @@ -70,7 +65,7 @@ stop_che_server() {
info "${CHE_PRODUCT_NAME}: Container $CURRENT_CHE_SERVER_CONTAINER_ID is not running. Nothing to do."
else
info "${CHE_PRODUCT_NAME}: Stopping server..."
docker exec ${CURRENT_CHE_SERVER_CONTAINER_ID} /home/user/che/bin/che.sh -c -s:uid stop > /dev/null
docker stop ${CURRENT_CHE_SERVER_CONTAINER_ID} > /dev/null
wait_until_container_is_stopped 60 ${CURRENT_CHE_SERVER_CONTAINER_ID}
if che_container_is_running ${CURRENT_CHE_SERVER_CONTAINER_ID}; then
error_exit "${CHE_PRODUCT_NAME}: Timeout waiting for the ${CHE_PRODUCT_NAME} container to stop."
Expand Down Expand Up @@ -123,8 +118,7 @@ print_debug_info() {
IFS=$'\n'
for CHE_SERVER_CONTAINER_ID in $CURRENT_CHE_INSTANCES; do
info ""
info "--------- CHE INSTANCE INFO ----------"
info "CHE SERVER CONTAINER ID = $CHE_SERVER_CONTAINER_ID"
info "--------- CHE INSTANCE: $CHE_SERVER_CONTAINER_ID"
CURRENT_CHE_SERVER_CONTAINER_NAME=$(docker inspect --format='{{.Name}}' ${CHE_SERVER_CONTAINER_ID} | cut -f2 -d"/")
info "CHE SERVER CONTAINER NANE = $CURRENT_CHE_SERVER_CONTAINER_NAME"
info "CHE CONTAINER EXISTS = $(che_container_exist $CHE_SERVER_CONTAINER_ID && echo "YES" || echo "NO")"
Expand All @@ -149,18 +143,18 @@ print_debug_info() {
info ""
info ""
info "---- CURRENT COMMAND LINE OPTIONS ---"
info "CHE_PORT = ${CHE_PORT}"
info "CHE_VERSION = ${CHE_VERSION}"
info "CHE_DATA = ${CHE_DATA}"
info "CHE_CONF = ${CHE_CONF:-not set}"
info "CHE_ASSEMBLY = ${CHE_ASSEMBLY:-not set}"
info "CHE_PORT = ${CHE_PORT}"
info "CHE_HOST_IP = ${CHE_HOST_IP}"
info "CHE_RESTART_POLICY = ${CHE_RESTART_POLICY}"
info "CHE_USER = ${CHE_USER}"
info "CHE_HOST_IP = ${CHE_HOST_IP}"
info "CHE_LOG_LEVEL = ${CHE_LOG_LEVEL}"
info "CHE_DEBUG_SERVER = ${CHE_DEBUG_SERVER}"
info "CHE_DEBUG_SERVER_PORT = ${CHE_DEBUG_SERVER_PORT}"
info "CHE_HOSTNAME = ${CHE_HOSTNAME}"
info "CHE_DATA_FOLDER = ${CHE_DATA_FOLDER}"
info "CHE_CONF_FOLDER = ${CHE_CONF_FOLDER:-not set}"
info "CHE_LOCAL_BINARY = ${CHE_LOCAL_BINARY:-not set}"
info "CHE_SERVER_CONTAINER_NAME = ${CHE_SERVER_CONTAINER_NAME}"
info "CHE_SERVER_IMAGE_NAME = ${CHE_SERVER_IMAGE_NAME}"
}
49 changes: 26 additions & 23 deletions che-launcher/launcher_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,40 +107,40 @@ docker_run() {
ENV_FILE=$(get_list_of_che_system_environment_variables)
docker run -d --name "${CHE_SERVER_CONTAINER_NAME}" \
-v /var/run/docker.sock:/var/run/docker.sock:Z \
-v /home/user/che/lib:/home/user/che/lib-copy:Z \
-v "$CHE_DATA_LOCATION" \
-p "${CHE_PORT}":8080 \
--restart="${CHE_RESTART_POLICY}" \
--user="${CHE_USER}" \
--env-file=$ENV_FILE \
-v "$CHE_STORAGE_LOCATION" "$@"
-e "CHE_LOG_LEVEL=${CHE_LOG_LEVEL}" \
-e "CHE_IP=$CHE_HOST_IP" \
--env-file=$ENV_FILE "$@"

rm -rf $ENV_FILE > /dev/null
}

docker_run_with_storage() {
docker_run_if_in_vm() {
# If the container will run inside of a VM, additional parameters must be set.
# Setting CHE_IN_VM=true will have the che-server container set the values.
if is_docker_for_mac || is_docker_for_windows || is_boot2docker; then
# If on docker for mac or windows, then we have to use these special parameters
docker_run -e "CHE_WORKSPACE_STORAGE=$CHE_DATA_FOLDER/workspaces" \
-e "CHE_WORKSPACE_STORAGE_CREATE_FOLDERS=false" "$@"
docker_run -e "CHE_IN_VM=true" "$@"
else
# Otherwise, mount the full directory
docker_run -v "$CHE_WORKSPACE_LOCATION" "$@"
docker_run "$@"
fi
}

docker_run_with_local_binary() {
if has_local_binary_path; then
docker_run_with_storage -v "$CHE_LOCAL_BINARY_LOCATION" "$@"
docker_run_with_assembly() {
if has_assembly; then
docker_run_if_in_vm -v "$CHE_ASSEMBLY_LOCATION" -e "CHE_ASSEMBLY=${CHE_ASSEMBLY}" "$@"
else
docker_run_with_storage "$@"
docker_run_if_in_vm "$@"
fi
}

docker_run_with_conf() {
if has_che_conf_path; then
docker_run_with_local_binary -v "$CHE_CONF_LOCATION" -e "CHE_LOCAL_CONF_DIR=/conf" "$@"
docker_run_with_assembly -v "$CHE_CONF_LOCATION" -e "CHE_LOCAL_CONF_DIR=${CHE_CONF}" "$@"
else
docker_run_with_local_binary "$@"
docker_run_with_assembly "$@"
fi
}

Expand All @@ -154,9 +154,12 @@ docker_run_with_external_hostname() {

docker_run_with_debug() {
if has_debug && has_debug_suspend; then
docker_run_with_external_hostname -p "${CHE_DEBUG_SERVER_PORT}":8000 -e "JPDA_SUSPEND=y" "$@"
docker_run_with_external_hostname -p "${CHE_DEBUG_SERVER_PORT}":8000 \
-e "CHE_DEBUG_SERVER=true" \
-e "JPDA_SUSPEND=y" "$@"
elif has_debug; then
docker_run_with_external_hostname -p "${CHE_DEBUG_SERVER_PORT}":8000 "$@"
docker_run_with_external_hostname -p "${CHE_DEBUG_SERVER_PORT}":8000 \
-e "CHE_DEBUG_SERVER=true" "$@"
else
docker_run_with_external_hostname "$@"
fi
Expand All @@ -179,15 +182,15 @@ has_debug() {
}

has_che_conf_path() {
if [ "${CHE_CONF_FOLDER}" = "" ]; then
if [ "${CHE_CONF}" = "" ]; then
return 1
else
return 0
fi
}

has_local_binary_path() {
if [ "${CHE_LOCAL_BINARY}" = "" ]; then
has_assembly() {
if [ "${CHE_ASSEMBLY}" = "" ]; then
return 1
else
return 0
Expand Down Expand Up @@ -354,13 +357,13 @@ get_container_debug() {
}

get_che_container_host_ip_from_container() {
BINDS=$(docker inspect --format="{{.Config.Cmd}}" "${1}" | cut -d '[' -f 2 | cut -d ']' -f 1)
BINDS=$(docker inspect --format="{{.Config.Env}}" "${1}" | cut -d '[' -f 2 | cut -d ']' -f 1)

IFS=$' '
for SINGLE_BIND in $BINDS; do
case $SINGLE_BIND in
*--remote*)
echo $SINGLE_BIND | cut -f2 -d":"
*CHE_IP*)
echo $SINGLE_BIND | cut -f2 -d=
;;
*)
;;
Expand Down