Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CLI: Faster boot, add --help global option, standardize command lifecycle #4006

Merged
merged 21 commits into from
Feb 6, 2017
2 changes: 2 additions & 0 deletions dockerfiles/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ RUN mkdir -p /version \
&& docker -v

COPY scripts/base /scripts/base/
COPY scripts/entrypoint.sh /scripts/entrypoint.sh

RUN chmod u+x /scripts/entrypoint.sh
1 change: 0 additions & 1 deletion dockerfiles/base/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ base_dir=$(cd "$(dirname "$0")"; pwd)

init "$@"
build

25 changes: 23 additions & 2 deletions dockerfiles/base/scripts/base/commands/cmd_action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,31 @@
# Tyler Jewell - Initial Implementation
#

cmd_action() {
debug $FUNCNAME
help_cmd_action() {
text "\n"
text "USAGE: ${CHE_IMAGE_FULLNAME} action <ACTION_NAME> [ACTION_PARAMETERS]\n"
text "\n"
text "Executes a REST action against ${CHE_MINI_PRODUCT_NAME} server or workspace.\n"
text "\n"
text "ACTIONS:\n"
text " create-start-workspace\n"
text " add-user\n"
text " remove-user\n"
text " execute-command\n"
text " list-workspaces\n"
text " workspace-ssh\n"
text " get-ssh-data\n"
text " graceful-stop\n"
text "\n"
text "Run '${CHE_IMAGE_FULLNAME} action' for action parameters"
text "\n"
}

pre_cmd_action() {
# Not loaded as part of the init process to save on download time
load_utilities_images_if_not_done
}

cmd_action() {
docker_run -it ${UTILITY_IMAGE_CHEACTION} "$@"
}
19 changes: 16 additions & 3 deletions dockerfiles/base/scripts/base/commands/cmd_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,22 @@
# Tyler Jewell - Initial Implementation
#

cmd_backup() {
debug $FUNCNAME
help_cmd_backup() {
text "\n"
text "USAGE: ${CHE_IMAGE_FULLNAME} backup [PARAMETERS]\n"
text "\n"
text "Backup ${CHE_MINI_PRODUCT_NAME} configuration and user data\n"
text "\n"
text "PARAMETERS:\n"
text " --no-skip-data Excludes user data in /instance/data\n"
text "\n"
}

pre_cmd_backup() {
true
}

cmd_backup() {
# possibility to skip ${CHE_FORMAL_PRODUCT_NAME} projects backup
SKIP_BACKUP_CHE_DATA=${1:-"--no-skip-data"}
if [[ "${SKIP_BACKUP_CHE_DATA}" == "--skip-data" ]]; then
Expand Down Expand Up @@ -46,7 +59,7 @@ cmd_backup() {
$(cmd_backup_extra_args) \
${BOOTSTRAP_IMAGE_ALPINE} sh -c "tar czf /root/backup/${CHE_BACKUP_FILE_NAME} -C /root${CHE_CONTAINER_ROOT} . --exclude='backup' --exclude='instance/dev' --exclude='instance/logs' ${TAR_EXTRA_EXCLUDE}"
info ""
info "backup" "Codenvy data saved in ${CHE_HOST_BACKUP}/${CHE_BACKUP_FILE_NAME}"
info "backup" "${CHE_MINI_PRODUCT_NAME} data saved in ${CHE_HOST_BACKUP}/${CHE_BACKUP_FILE_NAME}"
}

cmd_backup_extra_args() {
Expand Down
41 changes: 33 additions & 8 deletions dockerfiles/base/scripts/base/commands/cmd_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,27 @@
# Tyler Jewell - Initial Implementation
#

cmd_config_post_action() {
true
help_cmd_config() {
text "\n"
text "USAGE: ${CHE_IMAGE_FULLNAME} config [PARAMETERS]\n"
text "\n"
text "Generate a ${CHE_MINI_PRODUCT_NAME} runtime configuration into /instance. The configurator uses
values from your host, ${CHE_MINI_PRODUCT_NAME}.env, and optionally your local repository to generate
a runtime configuration used to start and stop ${CHE_MINI_PRODUCT_NAME}. A configuration is generated
before every execution of ${CHE_MINI_PRODUCT_NAME}. The configuration phase will download all Docker
images required to start or stop ${CHE_MINI_PRODUCT_NAME} to guarantee that the right images are cached
before execution. If you have mounted a local repository or assembly, the ${CHE_MINI_PRODUCT_NAME} Docker
images will use those binaries instead of their embedded ones.\n"
text "\n"
text "PARAMETERS:\n"
text " --no-force Updates images if matching tag not found in local cache\n"
text " --pull Uses 'docker pull' to check for new remote versions of images\n"
text " --force Uses 'docker rmi' and 'docker pull' to forcibly retrieve latest images\n"
text "\n"
}

pre_cmd_config() {
true
}

cmd_config() {
Expand All @@ -19,12 +38,12 @@ cmd_config() {
# If the system is already initialized, but a user wants to update images, then re-download.
FORCE_UPDATE=${1:-"--no-force"}
if ! is_initialized; then
cmd_init $FORCE_UPDATE
cmd_lifecycle init $FORCE_UPDATE
elif [[ "${FORCE_UPDATE}" == "--pull" ]] || \
[[ "${FORCE_UPDATE}" == "--force" ]]; then
cmd_download $FORCE_UPDATE
cmd_lifecycle download $FORCE_UPDATE
elif is_nightly && ! is_fast && ! skip_pull; then
cmd_download --pull
cmd_lifecycle download --pull
fi

# If using a local repository, then we need to always perform an updated init with those files
Expand All @@ -44,7 +63,6 @@ cmd_config() {

# Replace certain environment file lines with their container counterparts
info "config" "Customizing docker-compose for running in a container"


if local_repo || local_assembly; then
# in development mode to avoid permissions issues we copy tomcat assembly to ${CHE_INSTANCE}
Expand Down Expand Up @@ -74,8 +92,6 @@ cmd_config() {
cp -r "$(echo ${CHE_CONTAINER_ASSEMBLY_FULL_PATH})/." \
"${CHE_CONTAINER_INSTANCE}/dev/${CHE_MINI_PRODUCT_NAME}-tomcat/"
fi

cmd_config_post_action
}


Expand Down Expand Up @@ -151,3 +167,12 @@ config_directory_is_empty() {
return 0
fi
}

post_cmd_config() {
cmd_config_post_action
}

cmd_config_post_action() {
true
}

20 changes: 18 additions & 2 deletions dockerfiles/base/scripts/base/commands/cmd_destroy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
# Tyler Jewell - Initial Implementation
#

help_cmd_destroy() {
text "\n"
text "USAGE: ${CHE_IMAGE_FULLNAME} destroy [PARAMETERS]\n"
text "\n"
text "Deletes a ${CHE_MINI_PRODUCT_NAME} installation\n"
text "\n"
text "PARAMETERS:\n"
text " --quiet Do not ask user for confirmation\n"
text " --cli Removes the 'cli.log'\n"
text "\n"
}


pre_cmd_destroy() {
true
}

cmd_destroy_post_action() {
true
Expand All @@ -32,12 +48,12 @@ cmd_destroy() {
esac
done

WARNING="${RED}!!!${NC} Stopping services and ${RED}!!!${NC} deleting data ${RED}!!!${NC} this is unrecoverable ${RED}!!!${NC}"
WARNING="${YELLOW}!!!${RED} Stopping services and ${YELLOW}!!!${RED} deleting data ${YELLOW}!!!${RED} this is unrecoverable ${YELLOW}!!!${NC}"
if ! confirm_operation "${WARNING}" "${QUIET}"; then
return;
fi

cmd_stop --force
cmd_lifecycle stop --skip:graceful

info "destroy" "Deleting instance and config..."

Expand Down
27 changes: 22 additions & 5 deletions dockerfiles/base/scripts/base/commands/cmd_dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,27 @@
# http://www.eclipse.org/legal/epl-v10.html
#

cmd_dir() {
debug $FUNCNAME
help_cmd_dir() {
text "\n"
text "USAGE: ${CHE_IMAGE_FULLNAME} dir COMMAND [PARAMETERS]\n"
text "\n"
text "Create a workspace using a local directory mounted to ':\chedir'\n"
text "\n"
text "COMMANDS:\n"
text " init Initializes an empty local directory with a new Chefile\n"
text " down Stops the workspace and ${CHE_MINI_PRODUCT_NAME} representing this directory\n"
text " ssh SSH into the workspace that represents the local directory\n"
text " status Reports on the runtime status of ${CHE_MINI_PRODUCT_NAME} and the workspace runtime\n"
text " up Starts ${CHE_MINI_PRODUCT_NAME} and creates a new workspace with a project from your local dir\n"
text "\n"
}

pre_cmd_dir() {
# Not loaded as part of the init process to save on download time
load_utilities_images_if_not_done
}

cmd_dir() {
CHE_LOCAL_REPO=false
if [[ "${CHEDIR_MOUNT}" != "not set" ]]; then
local HOST_FOLDER_TO_USE="${CHEDIR_MOUNT}"
Expand All @@ -18,7 +36,6 @@ cmd_dir() {
warning "':/chedir' not mounted - using ${DATA_MOUNT} as source location"
fi

# Not loaded as part of the init process to save on download time
load_utilities_images_if_not_done
docker_run -it -v ${HOST_FOLDER_TO_USE}:${HOST_FOLDER_TO_USE} ${UTILITY_IMAGE_CHEDIR} ${HOST_FOLDER_TO_USE} "$@"
docker_run -it -v ${HOST_FOLDER_TO_USE}:${HOST_FOLDER_TO_USE} \
${UTILITY_IMAGE_CHEDIR} ${HOST_FOLDER_TO_USE} "$@"
}
18 changes: 18 additions & 0 deletions dockerfiles/base/scripts/base/commands/cmd_download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
# Tyler Jewell - Initial Implementation
#

help_cmd_download() {
text "\n"
text "USAGE: ${CHE_IMAGE_FULLNAME} download [PARAMETERS]\n"
text "\n"
text "Downloads Docker images required to execute ${CHE_MINI_PRODUCT_NAME}\n"
text "\n"
text "PARAMETERS:\n"
text " --force Uses 'docker rmi' and 'docker pull' to forcibly retrieve latest images\n"
text " --no-force Updates images if matching tag not found in local cache\n"
text " --pull Uses 'docker pull' to check for new remote versions of images\n"
text "\n"
}

pre_cmd_download() {
true
}

cmd_download() {
FORCE_UPDATE=${1:-"--no-force"}

Expand All @@ -23,3 +40,4 @@ cmd_download() {
fi
done
}

11 changes: 10 additions & 1 deletion dockerfiles/base/scripts/base/commands/cmd_help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@
# Tyler Jewell - Initial Implementation
#

help_cmd_help() {
text "\n"
text "Usage: ${CHE_IMAGE_FULLNAME} help"
text "\n"
}

cmd_help() {
usage
usage
}

pre_cmd_help() {
true
}
43 changes: 37 additions & 6 deletions dockerfiles/base/scripts/base/commands/cmd_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
# Tyler Jewell - Initial Implementation
#

help_cmd_info() {
text "\n"
text "USAGE: ${CHE_IMAGE_FULLNAME} info [PARAMETERS]\n"
text "\n"
text "Status, information, and support diagnostic bundles for ${CHE_MINI_PRODUCT_NAME}\n"
text "\n"
text "PARAMETERS:\n"
text " --all Prints info, runs networking tests, ad prepares diagnostic bundle\n"
text " --bundle Prepares diagnostic bundle for ${CHE_MINI_PRODUCT_NAME} and Docker\n"
text " --network Runs simulated network diagnostic to confirm network routing\n"
text " --print Default - displays status and configuration of ${CHE_MINI_PRODUCT_NAME}\n"
text "\n"
}


pre_cmd_info() {
true
}

cmd_info() {
debug $FUNCNAME
if [ $# -eq 0 ]; then
Expand Down Expand Up @@ -132,12 +151,6 @@ print_info() {
text " $SINGLE_IMAGE\n"
done

# This seems like overkill for the output
#readarray STACK_IMAGE_LIST < /version/$CHE_VERSION/images-stacks
#for SINGLE_IMAGE in "${STACK_IMAGE_LIST[@]}"; do
#text " $SINGLE_IMAGE"
#done

if ! is_initialized; then
text "${CHE_ENVIRONMENT_FILE}: not initialized\n"
else
Expand All @@ -149,3 +162,21 @@ print_info() {
done
fi
}

cmd_network() {
info ""
info "---------------------------------------"
info "-------- CONNECTIVITY TEST --------"
info "---------------------------------------"

info "network" "${BOOTSTRAP_IMAGE_CHEIP}: ${CHE_HOST}"

start_test_server

info "network" "Browser => Workspace Agent (localhost): Connection $(test1 && echo "succeeded" || echo "failed")"
info "network" "Browser => Workspace Agent ($AGENT_EXTERNAL_IP): Connection $(test2 && echo "succeeded" || echo "failed")"
info "network" "Server => Workspace Agent (External IP): Connection $(test3 && echo "succeeded" || echo "failed")"
info "network" "Server => Workspace Agent (Internal IP): Connection $(test4 && echo "succeeded" || echo "failed")"

stop_test_server
}
21 changes: 20 additions & 1 deletion dockerfiles/base/scripts/base/commands/cmd_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
# Tyler Jewell - Initial Implementation
#

help_cmd_init() {
text "\n"
text "USAGE: ${CHE_IMAGE_FULLNAME} init [PARAMETERS]\n"
text "\n"
text "Initializes a directory with a new ${CHE_MINI_PRODUCT_NAME} installation\n"
text "\n"
text "PARAMETERS:\n"
text " --accept-license If license acceptance required, auto accepts during installation\n"
text " --force Uses 'docker rmi' and 'docker pull' to forcibly retrieve latest images\n"
text " --no-force Updates images if matching tag not found in local cache\n"
text " --pull Uses 'docker pull' to check for new remote versions of images\n"
text " --reinit Reinitialize an existing installation overwriting defaults\n"
text "\n"
}

pre_cmd_init() {
true
}

cmd_init() {

# set an initial value for the flag
Expand Down Expand Up @@ -50,7 +69,7 @@ cmd_init() {
warning "($CHE_MINI_PRODUCT_NAME init): 'nightly' installations cannot be upgraded to non-nightly versions"
fi

cmd_download $FORCE_UPDATE
cmd_lifecycle download $FORCE_UPDATE

if require_license; then
if [[ "${AUTO_ACCEPT_LICENSE}" = "false" ]]; then
Expand Down
Loading