-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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 | ||
|
||
} | ||
|
||
|
||
|
@@ -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="" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it means that puppet logs will be streamed if you have |
||
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}\" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does docker have an issue for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
# 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 | ||
|
@@ -78,3 +65,12 @@ cmd_destroy() { | |
fi | ||
} | ||
|
||
directory_is_empty() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
@@ -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." | ||
|
@@ -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." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
There was a problem hiding this comment.
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" ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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