Skip to content

Commit

Permalink
Improvements to launcher.sh after code reviews
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Loriedo <mloriedo@redhat.com>
  • Loading branch information
l0rd committed Jul 19, 2016
1 parent 489ec50 commit 01ee7bc
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 54 deletions.
21 changes: 10 additions & 11 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ Vagrant.configure(2) do |config|
local progress=$1
local command=$2
shift 2
local pid=""
case "$progress" in
extended)
# simulate tty environment to get full output of progress bars and percentages
Expand All @@ -125,7 +125,7 @@ Vagrant.configure(2) do |config|
;;
esac
}
echo "------------------------------------"
echo "ECLIPSE CHE: UPGRADING DOCKER ENGINE"
echo "------------------------------------"
Expand All @@ -136,7 +136,7 @@ Vagrant.configure(2) do |config|
perform $PROVISION_PROGRESS sudo yum -y update docker-engine
echo $(docker --version)
# Add the 'vagrant' user to the 'docker' group
usermod -aG docker vagrant &>/dev/null
Expand Down Expand Up @@ -178,7 +178,7 @@ Vagrant.configure(2) do |config|
`codenvy/che:${CHE_VERSION} --remote:${IP} --port:${PORT} run &>/dev/null
SHELL

config.vm.provision "shell" do |s|
config.vm.provision "shell" do |s|
s.inline = $script
s.args = [$http_proxy, $https_proxy, $no_proxy, $che_version, $ip, $containerPort, $provisionProgress]
end
Expand All @@ -198,20 +198,19 @@ Vagrant.configure(2) do |config|
CHE_URL="http://${IP}:${PORT}"
# Test the default dashboard page to see when it returns a non-error value.
# Che is active once it returns success
# Che is active once it returns success
while [ true ]; do
printf "#"
curl -v ${CHE_URL}/dashboard &>/dev/null
exitcode=$?
if [ $exitcode == "0" ]; then
http_status_code=$(curl -I ${CHE_URL}/api/ -s -o /dev/null --write-out "%{http_code}")
if [ "$http_status_code" == "200" ]; then
echo "${CHE_URL}" > /home/user/che/.che_url
echo "${MAPPED_PORT}" > /home/user/che/.che_host_port
echo "---------------------------------------"
echo "ECLIPSE CHE: BOOTED AND REACHABLE"
echo "ECLIPSE CHE: ${CHE_URL} "
echo "---------------------------------------"
exit 0
fi
exit 0
fi
sleep 10
done
SHELL
Expand Down
16 changes: 8 additions & 8 deletions dockerfiles/che-cli/files-to-install/che.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ init_global_variables() {
# User configurable variables
DEFAULT_CHE_VERSION="latest"
DEFAULT_CHE_CLI_ACTION="help"

CHE_VERSION=${CHE_VERSION:-${DEFAULT_CHE_VERSION}}
CHE_CLI_ACTION=${CHE_CLI_ACTION:-${DEFAULT_CHE_CLI_ACTION}}

USAGE="
Usage:
che [COMMAND]
Expand Down Expand Up @@ -98,13 +98,13 @@ execute_command_with_progress() {
local progress=$1
local command=$2
shift 2

local pid=""
printf "\n"
printf "\n"

case "$progress" in
extended)
$command "$@"
$command "$@"
;;
basic|*)
$command "$@" &>/dev/null &
Expand All @@ -117,7 +117,7 @@ execute_command_with_progress() {
printf "\n"
;;
esac
printf "\n"
printf "\n"
}

update_che_launcher() {
Expand All @@ -127,9 +127,9 @@ update_che_launcher() {

CURRENT_IMAGE=$(docker images -q ${CHE_LAUNCHER_IMAGE_NAME}:${CHE_VERSION})

if [ "${CURRENT_IMAGE}" != "" ]; then
if [ "${CURRENT_IMAGE}" != "" ]; then
info "ECLIPSE CHE: ALREADY HAVE IMAGE ${CHE_LAUNCHER_IMAGE_NAME}:${CHE_VERSION}"
else
else
info "ECLIPSE CHE: PULLING IMAGE ${CHE_LAUNCHER_IMAGE_NAME}:${CHE_VERSION}"
execute_command_with_progress extended docker pull ${CHE_LAUNCHER_IMAGE_NAME}:${CHE_VERSION}
info "ECLIPSE CHE: IMAGE ${CHE_LAUNCHER_IMAGE_NAME}:${CHE_VERSION} INSTALLED"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Copyright (c) 2012-2016 Codenvy, S.A., Red Hat, Inc
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Mario Loriedo - Initial implementation
#
# To build, in this directory:
# `docker build -t codenvy/che .`
# `docker build -t codenvy/che-launcher .`
#
# To use it:
# `docker run --rm -v /var/run/docker.sock:/var/run/docker.sock codenvy/che start`
Expand Down
125 changes: 91 additions & 34 deletions dockerfiles/che/launcher.sh → dockerfiles/che-launcher/launcher.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#!/bin/sh
# Copyright (c) 2012-2016 Codenvy, S.A., Red Hat, Inc
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Mario Loriedo - Initial implementation
#

init_logging() {
BLUE='\033[1;34m'
Expand All @@ -10,8 +19,8 @@ init_logging() {
init_global_variables() {

CHE_SERVER_CONTAINER_NAME="che-server"
CHE_SERVER_IMAGE_NAME="codenvy/che"
CHE_LAUNCER_IMAGE_NAME="codenvy/che-launcher"
CHE_SERVER_IMAGE_NAME="codenvy/che-server"
CHE_LAUNCHER_IMAGE_NAME="codenvy/che-launcher"

# Possible Docker install types are:
# native, boot2docker or moby
Expand All @@ -22,7 +31,7 @@ init_global_variables() {
DEFAULT_CHE_HOSTNAME=$(get_che_hostname)
DEFAULT_CHE_PORT="8080"
DEFAULT_CHE_VERSION="latest"
DEFAULT_CHE_RESTART_POLICY="always"
DEFAULT_CHE_RESTART_POLICY="no"
DEFAULT_CHE_USER="root"
DEFAULT_CHE_LOG_LEVEL="info"
DEFAULT_CHE_DATA_FOLDER="/home/user/che"
Expand All @@ -42,9 +51,24 @@ init_global_variables() {
CHE_CONF_ARGS=${CHE_CONF_FOLDER:+-v ${CHE_CONF_FOLDER}:/conf -e \"CHE_LOCAL_CONF_DIR=/conf\"}
CHE_LOCAL_BINARY_ARGS=${CHE_LOCAL_BINARY:+-v ${CHE_LOCAL_BINARY}:/home/user/che}

if is_docker_for_mac || is_docker_for_windows; then
CHE_STORAGE_ARGS=${CHE_DATA_FOLDER:+-v ${CHE_DATA_FOLDER}/storage:/home/user/che/storage \
-e \"CHE_WORKSPACE_STORAGE=${CHE_DATA_FOLDER}/workspaces\" \
-e \"CHE_WORKSPACE_STORAGE_CREATE_FOLDERS=false\"}
else
CHE_STORAGE_ARGS=${CHE_DATA_FOLDER:+-v ${CHE_DATA_FOLDER}/storage:/home/user/che/storage \
-v ${CHE_DATA_FOLDER}/workspaces:/home/user/che/workspaces}
fi

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

USAGE="
Usage:
docker run -v /var/run/docker.sock:/var/run/docker.sock ${CHE_LAUNCER_IMAGE_NAME} [COMMAND]
docker run -v /var/run/docker.sock:/var/run/docker.sock ${CHE_LAUNCHER_IMAGE_NAME} [COMMAND]
start Starts Che server
stop Stops Che server
restart Restart Che server
Expand Down Expand Up @@ -115,20 +139,54 @@ print_debug_info() {
debug "---------------------------------------"
}

get_docker_install_type() {
is_boot2docker() {
if uname -r | grep -q 'boot2docker'; then
return 0
else
return 1
fi
}

has_docker_for_windows_ip() {
DOCKER_HOST_IP=$(get_docker_host_ip)
if [ "${DOCKER_HOST_IP}" = "10.0.75.2" ]; then
return 0
else
return 1
fi
}

is_docker_for_mac() {
if uname -r | grep -q 'moby' && ! has_docker_for_windows_ip; then
return 0
else
return 1
fi
}

is_docker_for_windows() {
if uname -r | grep -q 'moby' && has_docker_for_windows_ip; then
return 0
else
return 1
fi
}

get_docker_install_type() {
if is_boot2docker; then
echo "boot2docker"
elif uname -r | grep -q 'moby'; then
echo "moby"
elif is_docker_for_windows; then
echo "docker4windows"
elif is_docker_for_mac; then
echo "docker4mac"
else
echo "native"
fi
}

get_docker_host_ip() {
NETWORK_IF="eth0"
INSTALL_TYPE=$(get_docker_install_type)
if [ "${INSTALL_TYPE}" = "boot2docker" ]; then
if is_boot2docker; then
NETWORK_IF="eth1"
fi

Expand All @@ -142,12 +200,9 @@ get_docker_host_ip() {

get_che_hostname() {
INSTALL_TYPE=$(get_docker_install_type)
CHE_IP=$(get_docker_host_ip)

if [ "${INSTALL_TYPE}" = "boot2docker" ]; then
echo "${CHE_IP}"
elif [[ "${INSTALL_TYPE}" = "moby" && "${CHE_IP}" = "10.0.75.2" ]]; then
echo "${CHE_IP}"
if [ "${INSTALL_TYPE}" = "boot2docker" ] ||
[ "${INSTALL_TYPE}" = "docker4windows" ]; then
get_docker_host_ip
else
echo "localhost"
fi
Expand Down Expand Up @@ -200,10 +255,12 @@ wait_until_container_is_running() {
}

server_is_booted() {
if ! curl -v http://"${CHE_HOST_IP}":"${CHE_PORT}"/dashboard > /dev/null 2>&1 ; then
return 1
else
HTTP_STATUS_CODE=$(curl -I http://"${CHE_HOST_IP}":"${CHE_PORT}"/api/ \
-s -o /dev/null --write-out "%{http_code}")
if [ "${HTTP_STATUS_CODE}" = "200" ]; then
return 0
else
return 1
fi
}

Expand Down Expand Up @@ -245,59 +302,59 @@ start_che_server() {
error_exit "A container named \"${CHE_SERVER_CONTAINER_NAME}\" already exists. Please remove it manually (docker rm -f ${CHE_SERVER_CONTAINER_NAME}) and try again."
fi

CURRENT_IMAGE=$(docker images -q ${CHE_SERVER_IMAGE_NAME}:${CHE_VERSION})
CURRENT_IMAGE=$(docker images -q "${CHE_SERVER_IMAGE_NAME}":"${CHE_VERSION}")

if [ "${CURRENT_IMAGE}" != "" ]; then
if [ "${CURRENT_IMAGE}" != "" ]; then
info "ECLIPSE CHE: ALREADY HAVE IMAGE ${CHE_SERVER_IMAGE_NAME}:${CHE_VERSION}"
else
else
update_che_server
fi

info "ECLIPSE CHE: CONTAINER STARTING"
docker run -d --name "${CHE_SERVER_CONTAINER_NAME}" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "${CHE_DATA_FOLDER}"/lib:/home/user/che/lib-copy \
-v "${CHE_DATA_FOLDER}"/workspaces:/home/user/che/workspaces \
-v "${CHE_DATA_FOLDER}"/storage:/home/user/che/storage \
-v /home/user/che/lib:/home/user/che/lib-copy \
${CHE_LOCAL_BINARY_ARGS} \
-p "${CHE_PORT}":8080 \
--restart="${CHE_RESTART_POLICY}" \
--user="${CHE_USER}" \
${CHE_CONF_ARGS} \
${CHE_STORAGE_ARGS} \
"${CHE_SERVER_IMAGE_NAME}":"${CHE_VERSION}" \
--remote:"${CHE_HOST_IP}" \
-s:uid \
-s:client \
run > /dev/null # 2>&1
${CHE_DEBUG_OPTION} \
run > /dev/null

wait_until_container_is_running 10
if ! che_container_is_running; then
error_exit "ECLIPSE CHE: Timeout waiting Che container to start."
fi

info "ECLIPSE CHE: SERVER LOGS AT \"docker logs -f che\""
info "ECLIPSE CHE: SERVER LOGS AT \"docker logs -f ${CHE_SERVER_CONTAINER_NAME}\""
info "ECLIPSE CHE: SERVER BOOTING..."
wait_until_server_is_booted 20

if server_is_booted; then
info "ECLIPSE CHE: BOOTED AND REACHABLE"
info "ECLIPSE CHE: http://${CHE_HOSTNAME}:${CHE_PORT}"
else
error_exit "ECLIPSE CHE: Timeout waiting Che server to boot. Run \"docker logs che\" to see the logs."
error_exit "ECLIPSE CHE: Timeout waiting Che server to boot. Run \"docker logs ${CHE_SERVER_CONTAINER_NAME}\" to see the logs."
fi
}

execute_command_with_progress() {
local progress=$1
local command=$2
progress=$1
command=$2
shift 2
local pid=""
printf "\n"

pid=""
printf "\n"

case "$progress" in
extended)
$command "$@"
$command "$@"
;;
basic|*)
$command "$@" &>/dev/null &
Expand All @@ -310,7 +367,7 @@ execute_command_with_progress() {
printf "\n"
;;
esac
printf "\n"
printf "\n"
}

stop_che_server() {
Expand Down
8 changes: 8 additions & 0 deletions dockerfiles/che-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Copyright (c) 2012-2016 Codenvy, S.A., Red Hat, Inc
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Mario Loriedo
#
# To build it, run in the repository root:
# `docker build -t codenvy/che-server -f $(pwd)/dockerfiles/che-server/Dockerfile .`
Expand Down

0 comments on commit 01ee7bc

Please sign in to comment.