From 01ee7bccd253930d63241025abf2ccf75df6b5af Mon Sep 17 00:00:00 2001 From: Mario Loriedo Date: Mon, 18 Jul 2016 11:37:58 +0200 Subject: [PATCH] Improvements to launcher.sh after code reviews Signed-off-by: Mario Loriedo --- Vagrantfile | 21 ++- dockerfiles/che-cli/files-to-install/che.sh | 16 +-- dockerfiles/{che => che-launcher}/Dockerfile | 10 +- dockerfiles/{che => che-launcher}/launcher.sh | 125 +++++++++++++----- dockerfiles/che-server/Dockerfile | 8 ++ 5 files changed, 126 insertions(+), 54 deletions(-) rename dockerfiles/{che => che-launcher}/Dockerfile (65%) rename dockerfiles/{che => che-launcher}/launcher.sh (77%) diff --git a/Vagrantfile b/Vagrantfile index 48ce0e5f5dae..8caa9e844ad7 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -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 @@ -125,7 +125,7 @@ Vagrant.configure(2) do |config| ;; esac } - + echo "------------------------------------" echo "ECLIPSE CHE: UPGRADING DOCKER ENGINE" echo "------------------------------------" @@ -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 @@ -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 @@ -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 diff --git a/dockerfiles/che-cli/files-to-install/che.sh b/dockerfiles/che-cli/files-to-install/che.sh index 0df8bd26dbfb..8cd20d7e8032 100644 --- a/dockerfiles/che-cli/files-to-install/che.sh +++ b/dockerfiles/che-cli/files-to-install/che.sh @@ -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] @@ -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 & @@ -117,7 +117,7 @@ execute_command_with_progress() { printf "\n" ;; esac - printf "\n" + printf "\n" } update_che_launcher() { @@ -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" diff --git a/dockerfiles/che/Dockerfile b/dockerfiles/che-launcher/Dockerfile similarity index 65% rename from dockerfiles/che/Dockerfile rename to dockerfiles/che-launcher/Dockerfile index 8dcc2d5995ac..2d25f8c1643c 100644 --- a/dockerfiles/che/Dockerfile +++ b/dockerfiles/che-launcher/Dockerfile @@ -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` diff --git a/dockerfiles/che/launcher.sh b/dockerfiles/che-launcher/launcher.sh similarity index 77% rename from dockerfiles/che/launcher.sh rename to dockerfiles/che-launcher/launcher.sh index 3fda4010434b..12926184a53b 100755 --- a/dockerfiles/che/launcher.sh +++ b/dockerfiles/che-launcher/launcher.sh @@ -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' @@ -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 @@ -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" @@ -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 @@ -115,11 +139,46 @@ 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 @@ -127,8 +186,7 @@ get_docker_install_type() { 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 @@ -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 @@ -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 } @@ -245,37 +302,37 @@ 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 @@ -283,21 +340,21 @@ start_che_server() { 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 & @@ -310,7 +367,7 @@ execute_command_with_progress() { printf "\n" ;; esac - printf "\n" + printf "\n" } stop_che_server() { diff --git a/dockerfiles/che-server/Dockerfile b/dockerfiles/che-server/Dockerfile index 171e8b0dfe76..5129ec3a2d8d 100644 --- a/dockerfiles/che-server/Dockerfile +++ b/dockerfiles/che-server/Dockerfile @@ -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 .`