Skip to content

Commit

Permalink
Improve CLI Boot Speed (#3424)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Jewell authored Dec 19, 2016
1 parent 6dc998b commit a1526c2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
39 changes: 22 additions & 17 deletions dockerfiles/base/scripts/base/cli/cli-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ check_if_booted() {

server_is_booted() {
PING_URL=$(get_boot_url)
HTTP_STATUS_CODE=$(curl -I -k ${PING_URL} -s -o /dev/null --write-out "%{http_code}")
HTTP_STATUS_CODE=$(curl -I -k ${PING_URL} -s -o /dev/null --write-out '%{http_code}')
log "${HTTP_STATUS_CODE}"
if [[ "${HTTP_STATUS_CODE}" = "200" ]] || [[ "${HTTP_STATUS_CODE}" = "302" ]]; then
return 0
Expand Down Expand Up @@ -108,22 +108,27 @@ initiate_offline_or_network_mode(){
# 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
local HTTP_STATUS_CODE=$(curl -I -k dockerhub.com -s -o /dev/null --write-out "%{http_code}")
if [[ ! $HTTP_STATUS_CODE -eq "301" ]]; 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 dockerhub.com'"
return 2;
if [[ "${FAST_BOOT}" = "false" ]]; then
info "cli" "Checking network... (hint: '--fast' skips version and network checks)"
local HTTP_STATUS_CODE=$(curl -I -k dockerhub.com -s -o /dev/null --write-out '%{http_code}')
if [[ ! $HTTP_STATUS_CODE -eq "301" ]]; 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 dockerhub.com'"
return 2;
fi
else
warning "Skipping dockerhub network check..."
fi
fi
}
Expand Down
12 changes: 6 additions & 6 deletions dockerfiles/base/scripts/base/commands/cmd_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cmd_network() {
### TEST 1: Simulate browser ==> workspace agent HTTP connectivity
HTTP_CODE=$(curl -I localhost:${AGENT_EXTERNAL_PORT}/alpine-release \
-s -o "${LOGS}" --connect-timeout 5 \
--write-out "%{http_code}") || echo "28" >> "${LOGS}"
--write-out '%{http_code}') || echo "28" >> "${LOGS}"

if [ "${HTTP_CODE}" = "200" ]; then
info "Browser => Workspace Agent (localhost): Connection succeeded"
Expand All @@ -44,7 +44,7 @@ cmd_network() {
### TEST 1a: Simulate browser ==> workspace agent HTTP connectivity
HTTP_CODE=$(curl -I ${AGENT_EXTERNAL_IP}:${AGENT_EXTERNAL_PORT}/alpine-release \
-s -o "${LOGS}" --connect-timeout 5 \
--write-out "%{http_code}") || echo "28" >> "${LOGS}"
--write-out '%{http_code}') || echo "28" >> "${LOGS}"

if [ "${HTTP_CODE}" = "200" ]; then
info "Browser => Workspace Agent ($AGENT_EXTERNAL_IP): Connection succeeded"
Expand All @@ -55,10 +55,10 @@ cmd_network() {
### TEST 2: Simulate Che server ==> workspace agent (external IP) connectivity
export HTTP_CODE=$(docker_run --name fakeserver \
--entrypoint=curl \
${IMAGE_CODENVY} \
$(eval "echo \${IMAGE_${CHE_PRODUCT_NAME}}") \
-I ${AGENT_EXTERNAL_IP}:${AGENT_EXTERNAL_PORT}/alpine-release \
-s -o "${LOGS}" \
--write-out "%{http_code}")
--write-out '%{http_code}')

if [ "${HTTP_CODE}" = "200" ]; then
info "Server => Workspace Agent (External IP): Connection succeeded"
Expand All @@ -69,10 +69,10 @@ cmd_network() {
### TEST 3: Simulate Che server ==> workspace agent (internal IP) connectivity
export HTTP_CODE=$(docker_run --name fakeserver \
--entrypoint=curl \
${IMAGE_CODENVY} \
$(eval "echo \${IMAGE_${CHE_PRODUCT_NAME}}") \
-I ${AGENT_INTERNAL_IP}:${AGENT_INTERNAL_PORT}/alpine-release \
-s -o "${LOGS}" \
--write-out "%{http_code}")
--write-out '%{http_code}')

if [ "${HTTP_CODE}" = "200" ]; then
info "Server => Workspace Agent (Internal IP): Connection succeeded"
Expand Down
15 changes: 14 additions & 1 deletion dockerfiles/base/scripts/base/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ init_constants() {
UNDERLINE='\033[4m'
NC='\033[0m'
LOG_INITIALIZED=false
FAST_BOOT=false

DEFAULT_CHE_PRODUCT_NAME="CHE"
CHE_PRODUCT_NAME=${CHE_PRODUCT_NAME:-${DEFAULT_CHE_PRODUCT_NAME}}
Expand Down Expand Up @@ -236,6 +237,10 @@ init() {
usage;
fi

if [[ "$@" == *"--fast"* ]]; then
FAST_BOOT=true
fi

SCRIPTS_BASE_CONTAINER_SOURCE_DIR="/scripts/base"
# add helper scripts
for HELPER_FILE in "${SCRIPTS_BASE_CONTAINER_SOURCE_DIR}"/*.sh
Expand Down Expand Up @@ -338,7 +343,11 @@ cli_init() {
# Do not perform a version compatibility check if running upgrade command.
# The upgrade command has its own internal checks for version compatibility.
if [ $1 != "upgrade" ]; then
verify_version_compatibility
if [[ "${FAST_BOOT}" = "false" ]]; then
verify_version_compatibility
else
warning "Skipping version compatibility check..."
fi
else
verify_version_upgrade_compatibility
fi
Expand All @@ -360,9 +369,13 @@ start() {
# Bootstrap enough stuff to load /cli/cli.sh
init "$@"

# Removes "--fast" from the positional arguments if it is set.
set -- "${@/\-\-fast/}"

# Begin product-specific CLI calls
info "cli" "Loading cli..."


# The pre_init method is unique to each assembly. This method must be provided by
# a custom CLI assembly in their container and can set global variables which are
# specific to that implementation of the CLI. This method must be called after
Expand Down

0 comments on commit a1526c2

Please sign in to comment.