diff --git a/dockerfiles/base/scripts/base/library.sh b/dockerfiles/base/scripts/base/library.sh index 58f6723bf5..2af3c68268 100644 --- a/dockerfiles/base/scripts/base/library.sh +++ b/dockerfiles/base/scripts/base/library.sh @@ -30,7 +30,6 @@ get_boot_url() { } get_display_url() { - # If the user has modified che.env with a custom CHE_HOST, we need to detect that here # and not use the in-memory one which is always set with eclipse/che-ip. local CHE_HOST_LOCAL=$${CHE_PRODUCT_NAME}_HOST @@ -74,78 +73,6 @@ server_is_booted() { fi } -initiate_offline_or_network_mode(){ - # If you are using ${CHE_FORMAL_PRODUCT_NAME} in offline mode, images must be loaded here - # This is the point where we know that docker is working, but before we run any utilities - # that require docker. - if is_offline; then - info "init" "Importing ${CHE_MINI_PRODUCT_NAME} Docker images from tars..." - - if [ ! -d ${CHE_CONTAINER_OFFLINE_FOLDER} ]; then - warning "Skipping offline image loading - '${CHE_CONTAINER_OFFLINE_FOLDER}' not found" - else - IFS=$'\n' - for file in "${CHE_CONTAINER_OFFLINE_FOLDER}"/*.tar - do - if ! $(docker load < "${CHE_CONTAINER_OFFLINE_FOLDER}"/"${file##*/}" > /dev/null); then - error "Failed to restore ${CHE_MINI_PRODUCT_NAME} Docker images" - return 2; - fi - info "init" "Loading ${file##*/}..." - done - fi - else - # If we are here, then we want to run in networking mode. - # If we are in networking mode, we have had some issues where users have failed DNS networking. - # See: https://github.com/eclipse/che/issues/3266#issuecomment-265464165 - if ! is_fast && ! skip_network; then - # Removing this info line as it was appearing before initial CLI output -# info "cli" "Checking network... (hint: '--fast' skips nightly, version, network, and preflight checks)" - local HTTP_STATUS_CODE=$(curl -I -k hub.docker.com -s -o /dev/null --write-out '%{http_code}') - if [[ ! $HTTP_STATUS_CODE -eq "301" ]] && [[ ! $HTTP_STATUS_CODE -eq "200" ]]; then - info "Welcome to $CHE_FORMAL_PRODUCT_NAME!" - info "" - info "We could not resolve DockerHub using DNS." - info "Either we cannot reach the Internet or Docker's DNS resolver needs a modification." - info "" - info "You can:" - info " 1. Modify Docker's DNS settings." - info " a. Docker for Windows & Mac have GUIs for this." - info " b. Typically setting DNS to 8.8.8.8 fixes resolver issues." - info " 2. Does your network require Docker to use a proxy?" - info " a. Docker for Windows & Mac have GUIs to set proxies." - info " 3. Verify that you have access to DockerHub." - info " a. Try 'curl --head hub.docker.com'" - info " 4. Skip networking checks." - info " a. Add '--fast' to any command" - return 2; - fi - fi - fi -} - -grab_initial_images() { - # get list of images - get_image_manifest ${CHE_VERSION} - - # grab all bootstrap images - IFS=$'\n' - for BOOTSTRAP_IMAGE_LINE in ${BOOTSTRAP_IMAGE_LIST}; do - local BOOTSTRAP_IMAGE=$(echo ${BOOTSTRAP_IMAGE_LINE} | cut -d'=' -f2) - if [ "$(docker images -q ${BOOTSTRAP_IMAGE} 2> /dev/null)" = "" ]; then - info "cli" "Pulling image ${BOOTSTRAP_IMAGE}" - log "docker pull ${BOOTSTRAP_IMAGE} >> \"${LOGS}\" 2>&1" - TEST="" - docker pull ${BOOTSTRAP_IMAGE} >> "${LOGS}" > /dev/null 2>&1 || TEST=$? - if [ "$TEST" = "1" ]; then - error "Image ${BOOTSTRAP_IMAGE} unavailable. Not on dockerhub or built locally." - return 2; - fi - fi - done - -} - has_env_variables() { PROPERTIES=$(env | grep "${CHE_PRODUCT_NAME}_") @@ -178,34 +105,6 @@ update_image_if_not_found() { fi } -list_versions(){ - # List all subdirectories and then print only the file name - for version in /version/* ; do - text " ${version##*/}\n" - done -} - -### Returns the list of ${CHE_FORMAL_PRODUCT_NAME} images for a particular version of ${CHE_FORMAL_PRODUCT_NAME} -### Sets the images as environment variables after loading from file -get_image_manifest() { - log "Checking registry for version '$1' images" - if ! has_version_registry $1; then - version_error $1 - return 1; - fi - - # Load images from file - BOOTSTRAP_IMAGE_LIST=$(cat ${SCRIPTS_BASE_CONTAINER_SOURCE_DIR}/images/images-bootstrap) - IMAGE_LIST=$(cat /version/$1/images) - UTILITY_IMAGE_LIST=$(cat ${SCRIPTS_BASE_CONTAINER_SOURCE_DIR}/images/images-utilities) - - # set variables - set_variables_images_list "${BOOTSTRAP_IMAGE_LIST}" - set_variables_images_list "${IMAGE_LIST}" - set_variables_images_list "${UTILITY_IMAGE_LIST}" - -} - # Usage: # confirm_operation [--force|--no-force] confirm_operation() { @@ -258,54 +157,6 @@ less_than_numerically() { return $COMPARE } -# This will compare two same length strings, such as versions -less_than() { - for (( i=0; i<${#1}; i++ )); do - if [[ ${1:$i:1} != ${2:$i:1} ]]; then - if [ ${1:$i:1} -lt ${2:$i:1} ]; then - return 0 - else - return 1 - fi - fi - done - return 1 -} - -# Compares $1 version to the first 10 versions listed as tags on Docker Hub -# Returns "" if $1 is newest, otherwise returns the newest version available -# Does not work with nightly versions - do not use this to compare nightly to another version -compare_versions() { - - local VERSION_LIST_JSON=$(curl -s https://hub.docker.com/v2/repositories/${CHE_IMAGE_NAME}/tags/) - local NUMBER_OF_VERSIONS=$(echo $VERSION_LIST_JSON | jq '.count') - - DISPLAY_LIMIT=10 - if [ $DISPLAY_LIMIT -gt $NUMBER_OF_VERSIONS ]; then - DISPLAY_LIMIT=$NUMBER_OF_VERSIONS - fi - - # Strips off -M#, -latest version information - BASE_VERSION=$(echo $1 | cut -f1 -d"-") - - COUNTER=0 - RETURN_VERSION="" - while [ $COUNTER -lt $DISPLAY_LIMIT ]; do - TAG=$(echo $VERSION_LIST_JSON | jq ".results[$COUNTER].name") - TAG=${TAG//\"} - - if [ "$TAG" != "nightly" ] && [ "$TAG" != "latest" ]; then - if less_than $BASE_VERSION $TAG; then - RETURN_VERSION=$TAG - break; - fi - fi - let COUNTER=COUNTER+1 - done - - echo $RETURN_VERSION -} - # Input - an array of ports and port descriptions to check # Output - true if all ports are open, false if any of them are already bound check_all_ports(){ diff --git a/dockerfiles/base/scripts/base/startup_03_pre_networking.sh b/dockerfiles/base/scripts/base/startup_03_pre_networking.sh index f990b86d92..38495afe8c 100644 --- a/dockerfiles/base/scripts/base/startup_03_pre_networking.sh +++ b/dockerfiles/base/scripts/base/startup_03_pre_networking.sh @@ -110,6 +110,13 @@ version_error(){ text "\nSet CHE_VERSION= and rerun.\n\n" } +list_versions(){ + # List all subdirectories and then print only the file name + for version in /version/* ; do + text " ${version##*/}\n" + done +} + ### define variables for all image name in the given list set_variables_images_list() { IFS=$'\n' diff --git a/dockerfiles/base/scripts/base/startup_04_pre_cli_init.sh b/dockerfiles/base/scripts/base/startup_04_pre_cli_init.sh index 217e8e61a3..84407acae9 100644 --- a/dockerfiles/base/scripts/base/startup_04_pre_cli_init.sh +++ b/dockerfiles/base/scripts/base/startup_04_pre_cli_init.sh @@ -251,6 +251,40 @@ is_intermediate_version() { return 1 } +# Compares $1 version to the first 10 versions listed as tags on Docker Hub +# Returns "" if $1 is newest, otherwise returns the newest version available +# Does not work with nightly versions - do not use this to compare nightly to another version +compare_versions() { + + local VERSION_LIST_JSON=$(curl -s https://hub.docker.com/v2/repositories/${CHE_IMAGE_NAME}/tags/) + local NUMBER_OF_VERSIONS=$(echo $VERSION_LIST_JSON | jq '.count') + + DISPLAY_LIMIT=10 + if [ $DISPLAY_LIMIT -gt $NUMBER_OF_VERSIONS ]; then + DISPLAY_LIMIT=$NUMBER_OF_VERSIONS + fi + + # Strips off -M#, -latest version information + BASE_VERSION=$(echo $1 | cut -f1 -d"-") + + COUNTER=0 + RETURN_VERSION="" + while [ $COUNTER -lt $DISPLAY_LIMIT ]; do + TAG=$(echo $VERSION_LIST_JSON | jq ".results[$COUNTER].name") + TAG=${TAG//\"} + + if [ "$TAG" != "nightly" ] && [ "$TAG" != "latest" ]; then + if less_than $BASE_VERSION $TAG; then + RETURN_VERSION=$TAG + break; + fi + fi + let COUNTER=COUNTER+1 + done + + echo $RETURN_VERSION +} + compare_cli_version_to_installed_version() { IMAGE_VERSION=$(get_image_version) INSTALLED_VERSION=$(get_installed_version) @@ -342,3 +376,17 @@ get_value_of_var_from_env() { done echo "" } + +# This will compare two same length strings, such as versions +less_than() { + for (( i=0; i<${#1}; i++ )); do + if [[ ${1:$i:1} != ${2:$i:1} ]]; then + if [ ${1:$i:1} -lt ${2:$i:1} ]; then + return 0 + else + return 1 + fi + fi + done + return 1 +}