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

CLI - Separate debugging apart from local repo #3581

Merged
merged 7 commits into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions dockerfiles/base/scripts/base/cli/cli-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,11 @@ get_display_url() {
fi
}

check_if_booted() {
CURRENT_CHE_SERVER_CONTAINER_ID=$(get_server_container_id $CHE_SERVER_CONTAINER_NAME)
wait_until_container_is_running 20 ${CURRENT_CHE_SERVER_CONTAINER_ID}
if ! container_is_running ${CURRENT_CHE_SERVER_CONTAINER_ID}; then
error "(${CHE_MINI_PRODUCT_NAME} start): Timeout waiting for ${CHE_MINI_PRODUCT_NAME} container to start."
return 2
fi

info "start" "Services booting..."
info "start" "Server logs at \"docker logs -f ${CHE_SERVER_CONTAINER_NAME}\""
wait_until_server_is_booted 60 ${CURRENT_CHE_SERVER_CONTAINER_ID}

DISPLAY_URL=$(get_display_url)

if server_is_booted ${CURRENT_CHE_SERVER_CONTAINER_ID}; then
info "start" "Booted and reachable"
info "start" "Ver: $(get_installed_version)"
info "start" "Use: ${DISPLAY_URL}"
info "start" "API: ${DISPLAY_URL}/swagger"
get_debug_display_url() {
if ! is_docker_for_mac; then
echo "http://${CHE_HOST}:${CHE_DEBUG_PORT}"
else
error "(${CHE_MINI_PRODUCT_NAME} start): Timeout waiting for server. Run \"docker logs ${CHE_SERVER_CONTAINER_NAME}\" to inspect the issue."
return 2
echo "http://localhost:${CHE_DEBUG_PORT}"
fi
}

Expand Down
100 changes: 60 additions & 40 deletions dockerfiles/base/scripts/base/commands/cmd_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,54 @@ cmd_config() {
get_image_manifest $CHE_VERSION
fi

# Development mode
if [ "${CHE_DEVELOPMENT_MODE}" = "on" ]; then
# if dev mode is on, pick configuration sources from repo.
# If using a local repository, then we need to always perform an updated init with those files
if local_repo; then
# if user has mounted local repo, use configuration files from the repo.
# please note that in production mode update of configuration sources must be only on update.
docker_run -v "${CHE_HOST_CONFIG}":/copy \
-v "${CHE_HOST_DEVELOPMENT_REPO}"/dockerfiles/init:/files \
$IMAGE_INIT

fi

info "config" "Generating $CHE_MINI_PRODUCT_NAME configuration..."

# Run the docker configurator
generate_configuration_with_puppet

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


if local_repo; then
# in development mode to avoid permissions issues we copy tomcat assembly to ${CHE_INSTANCE}
# if ${CHE_FORMAL_PRODUCT_NAME} development tomcat exist we remove it
if [[ -d "${CHE_CONTAINER_INSTANCE}/dev" ]]; then
log "docker_run -v \"${CHE_HOST_INSTANCE}/dev\":/root/dev alpine:3.4 sh -c \"rm -rf /root/dev/*\""
docker_run -v "${CHE_HOST_INSTANCE}/dev":/root/dev alpine:3.4 sh -c "rm -rf /root/dev/*"

# Super weird bug - sometimes, the RM command doesn't wipe everything, so we have to repeat it a couple times
until config_directory_is_empty; do
docker_run -v "${CHE_HOST_INSTANCE}/dev":/root/dev alpine:3.4 sh -c "rm -rf /root/dev/${CHE_MINI_PRODUCT_NAME}-tomcat" > /dev/null 2>&1 || true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you change path from /root/dev/* to /root/dev/${CHE_MINI_PRODUCT_NAME}-tomcat" ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't make this path change. I believe that @riuvshin had made this path change in another issue that was already reviewed and merged. I believe it has to do with being clearer in the in the instance folder on what parts are Tomcat vs. which parts are not.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then can you rebase your branch or merge master into it

done

log "rm -rf \"${CHE_HOST_INSTANCE}/dev\" >> \"${LOGS}\""
rm -rf "${CHE_CONTAINER_INSTANCE}/dev"
fi

if [[ ! -d $(echo ${CHE_CONTAINER_DEVELOPMENT_REPO}/${CHE_ASSEMBLY_IN_REPO}) ]]; then
warning "You volume mounted a valid $CHE_FORMAL_PRODUCT_NAME repo to ':/repo', but we could not find a ${CHE_FORMAL_PRODUCT_NAME} assembly."
warning "Have you built ${CHE_ASSEMBLY_IN_REPO_MODULE_NAME} with 'mvn clean install'?"
return 2
fi

# copy ${CHE_FORMAL_PRODUCT_NAME} development tomcat to ${CHE_INSTANCE} folder
info "config" "Copying local binaries to ${CHE_HOST_INSTANCE}/dev..."
mkdir -p "${CHE_CONTAINER_INSTANCE}/dev/${CHE_MINI_PRODUCT_NAME}-tomcat"
cp -r "$(echo $CHE_CONTAINER_DEVELOPMENT_REPO/$CHE_ASSEMBLY_IN_REPO)/." \
"${CHE_CONTAINER_INSTANCE}/dev/${CHE_MINI_PRODUCT_NAME}-tomcat/"
fi

info "config" "Generating $CHE_MINI_PRODUCT_NAME configuration..."
# Run the docker configurator
generate_configuration_with_puppet

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

# Write the installed version to the *.ver file into the instance folder
echo "$CHE_VERSION" > "${CHE_CONTAINER_INSTANCE}/${CHE_VERSION_FILE}"

cmd_config_post_action

}


Expand All @@ -76,43 +90,49 @@ generate_configuration_with_puppet() {
CHE_ENV_FILE="${CHE_HOST_INSTANCE}/config/$CHE_MINI_PRODUCT_NAME.env"
fi

if [ "${CHE_DEVELOPMENT_MODE}" = "on" ]; then
# Note - bug in docker requires relative path for env, not absolute
GENERATE_CONFIG_COMMAND="docker_run \
--env-file=\"${REFERENCE_CONTAINER_ENVIRONMENT_FILE}\" \
--env-file=/version/$CHE_VERSION/images \
-v \"${CHE_HOST_INSTANCE}\":/opt/${CHE_MINI_PRODUCT_NAME}:rw \
-v \"${CHE_HOST_DEVELOPMENT_REPO}/dockerfiles/init/manifests\":/etc/puppet/manifests:ro \
-v \"${CHE_HOST_DEVELOPMENT_REPO}/dockerfiles/init/modules\":/etc/puppet/modules:ro \
-e \"CHE_ENV_FILE=${CHE_ENV_FILE}\" \
-e \"CHE_CONTAINER_ROOT=${CHE_CONTAINER_ROOT}\" \
-e \"CHE_ENVIRONMENT=development\" \
-e \"CHE_CONFIG=${CHE_HOST_INSTANCE}\" \
-e \"CHE_INSTANCE=${CHE_HOST_INSTANCE}\" \
-e \"CHE_DEVELOPMENT_REPO=${CHE_HOST_DEVELOPMENT_REPO}\" \
-e \"CHE_ASSEMBLY=${CHE_ASSEMBLY}\" \
--entrypoint=/usr/bin/puppet \
$IMAGE_INIT \
apply --modulepath \
/etc/puppet/modules/ \
/etc/puppet/manifests/${CHE_MINI_PRODUCT_NAME}.pp --show_diff"
if debug_server; then
CHE_ENVIRONMENT="development"
WRITE_LOGS=""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that mean that puppet logs will be shown only in debug mode? debug mode should only activate debug and do not change any other behaviour

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it means that puppet logs will be streamed if you have --debug only. If you mount a repository, but do not provide --debug then they would not be streamed.

else
CHE_ENVIRONMENT="production"
WRITE_LOGS=">> \"${LOGS}\""
fi

if local_repo; then
CHE_REPO="on"
WRITE_PARAMETERS="-v \"${CHE_HOST_DEVELOPMENT_REPO}/dockerfiles/init/manifests\":/etc/puppet/manifests:ro \
-v \"${CHE_HOST_DEVELOPMENT_REPO}/dockerfiles/init/modules\":/etc/puppet/modules:ro \
-e \"CHE_ASSEMBLY=${CHE_ASSEMBLY}\""
else
GENERATE_CONFIG_COMMAND="docker_run \
--env-file=\"${REFERENCE_CONTAINER_ENVIRONMENT_FILE}\" \
CHE_REPO="off"
WRITE_PARAMETERS=""
fi

GENERATE_CONFIG_COMMAND="docker_run \
--env-file=\"${REFERENCE_CONTAINER_ENVIRONMENT_FILE}\" \
--env-file=/version/$CHE_VERSION/images \
-v \"${CHE_HOST_INSTANCE}\":/opt/${CHE_MINI_PRODUCT_NAME}:rw \
${WRITE_PARAMETERS} \
-e \"CHE_ENV_FILE=${CHE_ENV_FILE}\" \
-e \"CHE_CONTAINER_ROOT=${CHE_CONTAINER_ROOT}\" \
-e \"CHE_ENVIRONMENT=production\" \
-e \"CHE_ENVIRONMENT=${CHE_ENVIRONMENT}\" \
-e \"CHE_CONFIG=${CHE_HOST_INSTANCE}\" \
-e \"CHE_INSTANCE=${CHE_HOST_INSTANCE}\" \
-e \"CHE_REPO=${CHE_REPO}\" \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on why did you change CHE_HOST_DEVELOPMENT_REPO. As I can see it is still used in other places.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just come cleanup to keep things simpler. The puppet templates had logic where both the repo and debugging logic was using the same variable. And this was needed to separate the logic across two variables.

--entrypoint=/usr/bin/puppet \
$IMAGE_INIT \
apply --modulepath \
/etc/puppet/modules/ \
/etc/puppet/manifests/${CHE_MINI_PRODUCT_NAME}.pp --show_diff >> \"${LOGS}\""
fi
/etc/puppet/manifests/${CHE_MINI_PRODUCT_NAME}.pp --show_diff ${WRITE_LOGS}"

log ${GENERATE_CONFIG_COMMAND}
eval ${GENERATE_CONFIG_COMMAND}
}

config_directory_is_empty() {
if [[ -d "${CHE_CONTAINER_INSTANCE}/dev/${CHE_MINI_PRODUCT_NAME}-tomcat" ]]; then
return 1
else
return 0
fi
}
10 changes: 5 additions & 5 deletions dockerfiles/base/scripts/base/commands/cmd_debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ cmd_debug() {
info ""
info "----------- ${CHE_PRODUCT_NAME} INFO ------------"
info "${CHE_PRODUCT_NAME}_VERSION = ${CHE_VERSION}"
info "${CHE_PRODUCT_NAME}_INSTANCE = ${CHE_HOST_INSTANCE}"
info "${CHE_PRODUCT_NAME}_CONFIG = ${CHE_HOST_CONFIG}"
info "${CHE_PRODUCT_NAME}_INSTANCE = ${CHE_HOST_INSTANCE}"
info "${CHE_PRODUCT_NAME}_CONFIG = ${CHE_HOST_CONFIG}"
info "${CHE_PRODUCT_NAME}_HOST = ${CHE_HOST}"
info "${CHE_PRODUCT_NAME}_REGISTRY = ${CHE_MANIFEST_DIR}"
info "${CHE_PRODUCT_NAME}_DEVELOPMENT_MODE = ${CHE_DEVELOPMENT_MODE}"
if [ "${CHE_DEVELOPMENT_MODE}" = "on" ]; then
info "${CHE_PRODUCT_NAME}_DEBUG = ${CHE_DEBUG}"
info "${CHE_PRODUCT_NAME}_BACKUP = ${CHE_HOST_BACKUP}"
if local_repo; then
info "${CHE_PRODUCT_NAME}_DEVELOPMENT_REPO = ${CHE_HOST_DEVELOPMENT_REPO}"
fi
info "${CHE_PRODUCT_NAME}_BACKUP = ${CHE_HOST_BACKUP}"
info ""
info "----------- PLATFORM INFO -----------"
info "DOCKER_INSTALL_TYPE = $(get_docker_install_type)"
Expand Down
34 changes: 15 additions & 19 deletions dockerfiles/base/scripts/base/commands/cmd_destroy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,14 @@ cmd_destroy() {
alpine:3.4 sh -c \"rm -rf /root${CHE_CONTAINER_ROOT}/docs \
&& rm -rf /root${CHE_CONTAINER_ROOT}/instance \
&& rm -rf /root${CHE_CONTAINER_ROOT}/${CHE_MINI_PRODUCT_NAME}.env\""

docker_run -v "${CHE_HOST_CONFIG}":/root${CHE_CONTAINER_ROOT} \
alpine:3.4 sh -c "rm -rf /root${CHE_CONTAINER_ROOT}/docs \
&& rm -rf /root${CHE_CONTAINER_ROOT}/instance \
&& rm -rf /root${CHE_CONTAINER_ROOT}/${CHE_MINI_PRODUCT_NAME}.env" > /dev/null 2>&1 || true

# Super weird bug. For some reason on windows, this command has to be run 3x for everything

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does docker have an issue for that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I haven't created an issue. I wasn't sure it was a docker issue for it. We discovered this a couple months ago when we first implemented the cmd_destroy function. We were seeing that we had to 3x remove stuff in that function and now it's coming up again. I can create that issue for them.

# to be destroyed properly if you are in dev mode.
if has_docker_for_windows_client; then
if [[ "${CHE_DEVELOPMENT_MODE}" = "on" ]]; then
docker_run -v "${CHE_HOST_CONFIG}":/root${CHE_CONTAINER_ROOT} \
alpine:3.4 sh -c "rm -rf /root${CHE_CONTAINER_ROOT}/docs \
&& rm -rf /root${CHE_CONTAINER_ROOT}/instance \
&& rm -rf /root${CHE_CONTAINER_ROOT}/${CHE_MINI_PRODUCT_NAME}.env" > /dev/null 2>&1 || true
docker_run -v "${CHE_HOST_CONFIG}":/root${CHE_CONTAINER_ROOT} \
alpine:3.4 sh -c "rm -rf /root${CHE_CONTAINER_ROOT}/docs \
&& rm -rf /root${CHE_CONTAINER_ROOT}/instance \
&& rm -rf /root${CHE_CONTAINER_ROOT}/${CHE_MINI_PRODUCT_NAME}.env" > /dev/null 2>&1 || true
fi
fi

until directory_is_empty; do
docker_run -v "${CHE_HOST_CONFIG}":/root${CHE_CONTAINER_ROOT} \
alpine:3.4 sh -c "rm -rf /root${CHE_CONTAINER_ROOT}/docs \
; rm -rf /root${CHE_CONTAINER_ROOT}/instance \
; rm -rf /root${CHE_CONTAINER_ROOT}/${CHE_MINI_PRODUCT_NAME}.env" > /dev/null 2>&1 || true
done
rm -rf "${CHE_CONTAINER_INSTANCE}"

cmd_destroy_post_action
Expand All @@ -78,3 +65,12 @@ cmd_destroy() {
fi
}

directory_is_empty() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bit confusing to have both directory_is_empty and directory_is_clean functions. Is it on purpose?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They had different syntax of what to check. So I keep both as directory_is_empty and then add a qualifier for the one in config now.

if [[ -d "${CHE_CONTAINER_CONFIG}/docs" ]] ||
[[ -d "${CHE_CONTAINER_CONFIG}/instance" ]] ||
[[ -f "${CHE_CONTAINER_CONFIG}/${CHE_MINI_PRODUCT_NAME}.env" ]]; then
return 1
else
return 0
fi
}
7 changes: 2 additions & 5 deletions dockerfiles/base/scripts/base/commands/cmd_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ cmd_init() {
fi

# in development mode we use init files from repo otherwise we use it from docker image
if [ "${CHE_DEVELOPMENT_MODE}" = "on" ]; then
if local_repo; then
docker_run -v "${CHE_HOST_CONFIG}":/copy \
-v "${CHE_HOST_DEVELOPMENT_REPO}"/dockerfiles/init:/files \
-v "${CHE_HOST_DEVELOPMENT_REPO}"/dockerfiles/init/manifests/${CHE_MINI_PRODUCT_NAME}.env:/etc/puppet/manifests/${CHE_MINI_PRODUCT_NAME}.env \
Expand All @@ -101,12 +101,9 @@ cmd_init() {
info "init" " ${CHE_PRODUCT_NAME}_VERSION=${CHE_VERSION}"
info "init" " ${CHE_PRODUCT_NAME}_CONFIG=${CHE_HOST_CONFIG}"
info "init" " ${CHE_PRODUCT_NAME}_INSTANCE=${CHE_HOST_INSTANCE}"
if [ "${CHE_DEVELOPMENT_MODE}" == "on" ]; then
info "init" " ${CHE_PRODUCT_NAME}_ENVIRONMENT=development"
if local_repo; then
info "init" " ${CHE_PRODUCT_NAME}_DEVELOPMENT_REPO=${CHE_HOST_DEVELOPMENT_REPO}"
info "init" " ${CHE_PRODUCT_NAME}_ASSEMBLY=${CHE_ASSEMBLY}"
else
info "init" " ${CHE_PRODUCT_NAME}_ENVIRONMENT=production"
fi
fi

Expand Down
59 changes: 51 additions & 8 deletions dockerfiles/base/scripts/base/commands/cmd_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cmd_start() {
info "start" "Starting containers..."
COMPOSE_UP_COMMAND="docker_compose --file=\"${REFERENCE_CONTAINER_COMPOSE_FILE}\" -p=\"${CHE_MINI_PRODUCT_NAME}\" up -d"

if [ "${CHE_DEVELOPMENT_MODE}" != "on" ]; then
if ! debug_server; then
COMPOSE_UP_COMMAND+=" >> \"${LOGS}\" 2>&1"
fi

Expand All @@ -58,7 +58,7 @@ cmd_start() {
cmd_start_check_ports() {

# If dev mode is on, then we also need to check the debug port set by the user for availability
if [ "${CHE_DEVELOPMENT_MODE}" = "on" ]; then
if debug_server; then
USER_DEBUG_PORT=$(docker_run --env-file="${REFERENCE_CONTAINER_ENVIRONMENT_FILE}" alpine sh -c 'echo $CHE_DEBUG_PORT')

if [[ "$USER_DEBUG_PORT" = "" ]]; then
Expand All @@ -71,15 +71,15 @@ cmd_start_check_ports() {
fi

text " port ${CHE_PORT} (http): $(port_open ${CHE_PORT} && echo "${GREEN}[AVAILABLE]${NC}" || echo "${RED}[ALREADY IN USE]${NC}") \n"
if [ "${CHE_DEVELOPMENT_MODE}" = "on" ]; then
text " port ${CHE_DEBUG_PORT} (debug): $(port_open ${CHE_DEBUG_PORT} && echo "${GREEN}[AVAILABLE]${NC}" || echo "${RED}[ALREADY IN USE]${NC}") \n"
if debug_server; then
text " port ${CHE_DEBUG_PORT} (debug): $(port_open ${CHE_DEBUG_PORT} && echo "${GREEN}[AVAILABLE]${NC}" || echo "${RED}[ALREADY IN USE]${NC}") \n"
fi
if ! $(port_open ${CHE_PORT}); then
echo ""
error "Ports required to run $CHE_MINI_PRODUCT_NAME are used by another program."
return 1;
fi
if [ "${CHE_DEVELOPMENT_MODE}" = "on" ]; then
if debug_server; then
if ! $(port_open ${CHE_DEBUG_PORT}); then
echo ""
error "Ports required to run $CHE_MINI_PRODUCT_NAME are used by another program."
Expand Down Expand Up @@ -112,7 +112,50 @@ cmd_restart() {
debug $FUNCNAME

FORCE_UPDATE=${1:-"--no-force"}
info "restart" "Restarting..."
cmd_stop
cmd_start ${FORCE_UPDATE}
info "restart" "Restarting..."
cmd_stop
cmd_start ${FORCE_UPDATE}
}

check_if_booted() {
CURRENT_CHE_SERVER_CONTAINER_ID=$(get_server_container_id $CHE_SERVER_CONTAINER_NAME)
wait_until_container_is_running 20 ${CURRENT_CHE_SERVER_CONTAINER_ID}
if ! container_is_running ${CURRENT_CHE_SERVER_CONTAINER_ID}; then
error "(${CHE_MINI_PRODUCT_NAME} start): Timeout waiting for ${CHE_MINI_PRODUCT_NAME} container to start."
return 2
fi

info "start" "Services booting..."

# CHE-3546 - if in development mode, then display the che server logs to STDOUT
# automatically kill the streaming of the log output when the server is booted
if debug_server; then
docker logs -f ${CHE_SERVER_CONTAINER_NAME} &
LOG_PID=$!
else
info "start" "Server logs at \"docker logs -f ${CHE_SERVER_CONTAINER_NAME}\""
fi

wait_until_server_is_booted 60 ${CURRENT_CHE_SERVER_CONTAINER_ID}

if debug_server; then
kill $LOG_PID > /dev/null 2>&1
info ""
fi

if server_is_booted ${CURRENT_CHE_SERVER_CONTAINER_ID}; then
DISPLAY_URL=$(get_display_url)
info "start" "Booted and reachable"
info "start" "Ver: $(get_installed_version)"
info "start" "Use: ${DISPLAY_URL}"
info "start" "API: ${DISPLAY_URL}/swagger"
if debug_server; then
DISPLAY_DEBUG_URL=$(get_debug_display_url)
info "start" "Debug: ${DISPLAY_DEBUG_URL}"
fi
else
error "(${CHE_MINI_PRODUCT_NAME} start): Timeout waiting for server. Run \"docker logs ${CHE_SERVER_CONTAINER_NAME}\" to inspect the issue."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like kill $LOG_PID > /dev/null 2>&1 is needed here also

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the kill operation to be outside of hte initial loop so that it's killed first, displayed second.

return 2
fi
}

Loading