diff --git a/docs/10-easy-docker/01-overview.md b/docs/10-easy-docker/01-overview.md index 7f9b08cd..bab00fab 100644 --- a/docs/10-easy-docker/01-overview.md +++ b/docs/10-easy-docker/01-overview.md @@ -25,6 +25,10 @@ Current limitations: - site management currently assumes one configured site per stack - backup and app management are focused on the configured stack image and site +Current setup-type behavior: + +- `development` stacks enable `developer_mode` automatically for newly created sites + The current entrypoint is: ```bash diff --git a/scripts/easy-docker/lib/app/wizard/common/core.sh b/scripts/easy-docker/lib/app/wizard/common/core.sh index 64ba7972..c8de1606 100755 --- a/scripts/easy-docker/lib/app/wizard/common/core.sh +++ b/scripts/easy-docker/lib/app/wizard/common/core.sh @@ -331,6 +331,25 @@ get_stack_topology() { return 0 } +get_stack_setup_type() { + local stack_dir="${1}" + local metadata_path="" + local setup_type="" + + metadata_path="${stack_dir}/metadata.json" + if [ ! -f "${metadata_path}" ]; then + return 1 + fi + + setup_type="$(get_metadata_string_field "${metadata_path}" "setup_type" || true)" + if [ -z "${setup_type}" ]; then + return 1 + fi + + printf '%s\n' "${setup_type}" + return 0 +} + get_metadata_compose_files_lines() { local metadata_path="${1}" diff --git a/scripts/easy-docker/lib/app/wizard/common/site/bootstrap/lifecycle.sh b/scripts/easy-docker/lib/app/wizard/common/site/bootstrap/lifecycle.sh index 9e0ca813..0fedd62b 100755 --- a/scripts/easy-docker/lib/app/wizard/common/site/bootstrap/lifecycle.sh +++ b/scripts/easy-docker/lib/app/wizard/common/site/bootstrap/lifecycle.sh @@ -305,6 +305,42 @@ install_stack_apps_on_site() { return 0 } +stack_site_should_enable_developer_mode() { + local stack_dir="${1}" + local setup_type="" + + setup_type="$(get_stack_setup_type "${stack_dir}" || true)" + case "${setup_type}" in + development) + return 0 + ;; + *) + return 1 + ;; + esac +} + +enable_stack_site_developer_mode() { + local stack_dir="${1}" + local site_name="${2}" + local developer_mode_command="" + local developer_mode_output="" + + developer_mode_command="$( + printf "bench --site %s set-config developer_mode 1 && bench --site %s clear-cache" \ + "$(shell_quote_site_command_arg "${site_name}")" \ + "$(shell_quote_site_command_arg "${site_name}")" + )" + + if run_stack_backend_bash_command_capture developer_mode_output "${stack_dir}" "${developer_mode_command}"; then + return 0 + fi + + EASY_DOCKER_SITE_ERROR_DETAIL="$(printf "Could not enable developer mode for '%s'." "${site_name}")" + capture_stack_site_error_log "${stack_dir}" "site-developer-mode-error" "${developer_mode_output}" >/dev/null 2>&1 || true + return 66 +} + run_stack_site_migrate() { local stack_dir="${1}" local site_name="${2}" @@ -333,6 +369,7 @@ bootstrap_first_stack_site() { local updated_at="" local installed_app_lines="" local site_create_status=0 + local developer_mode_status=0 local app_install_status=0 local site_migrate_status=0 local cleanup_status=0 @@ -416,6 +453,29 @@ bootstrap_first_stack_site() { esac fi + if stack_site_should_enable_developer_mode "${stack_dir}"; then + if enable_stack_site_developer_mode "${stack_dir}" "${site_name}"; then + : + else + developer_mode_status=$? + if cleanup_partial_stack_site "${stack_dir}" "${site_name}"; then + mark_stack_site_failed "${stack_dir}" "${site_name}" "" "enable-developer-mode" "${EASY_DOCKER_SITE_ERROR_DETAIL:-Developer mode activation failed. Partial site data was cleaned up automatically.}" "${EASY_DOCKER_SITE_ERROR_LOG_PATH}" "${created_at}" >/dev/null 2>&1 || true + return "${developer_mode_status}" + fi + + cleanup_status=$? + mark_stack_site_failed "${stack_dir}" "${site_name}" "" "enable-developer-mode" "${EASY_DOCKER_SITE_ERROR_DETAIL:-Developer mode activation failed and partial site data could not be cleaned up automatically. Manual cleanup is required.}" "${EASY_DOCKER_SITE_ERROR_LOG_PATH}" "${created_at}" >/dev/null 2>&1 || true + case "${cleanup_status}" in + 54 | 52) + return "${cleanup_status}" + ;; + *) + return 60 + ;; + esac + fi + fi + updated_at="$(get_current_utc_timestamp)" if ! persist_stack_site_metadata "${stack_dir}" "single-site" "${site_name}" "" "create-site" "" "" "${created_at}" "${updated_at}"; then return 58 diff --git a/scripts/easy-docker/lib/app/wizard/flows/manage/site.sh b/scripts/easy-docker/lib/app/wizard/flows/manage/site.sh index b0b9cb4c..a01ee508 100755 --- a/scripts/easy-docker/lib/app/wizard/flows/manage/site.sh +++ b/scripts/easy-docker/lib/app/wizard/flows/manage/site.sh @@ -123,7 +123,7 @@ handle_manage_stack_site_flow() { show_warning_and_wait "The site was created, but app installation failed. ${EASY_DOCKER_SITE_ERROR_DETAIL:-Check the output above.} ${EASY_DOCKER_SITE_ERROR_LOG_PATH:+See ${stack_dir}/${EASY_DOCKER_SITE_ERROR_LOG_PATH}}" 6 ;; 57) - show_warning_and_wait "Site bootstrap currently supports only MariaDB-backed single-host stacks." 4 + show_warning_and_wait "Site bootstrap currently supports only supported single-host database stacks." 4 ;; 58) show_warning_and_wait "The site metadata could not be written to metadata.json." 4 @@ -146,6 +146,9 @@ handle_manage_stack_site_flow() { 64) show_warning_and_wait "The site was created and apps were installed, but bench migrate failed. ${EASY_DOCKER_SITE_ERROR_DETAIL:-Check the output above.} ${EASY_DOCKER_SITE_ERROR_LOG_PATH:+See ${stack_dir}/${EASY_DOCKER_SITE_ERROR_LOG_PATH}}" 7 ;; + 66) + show_warning_and_wait "Site bootstrap failed while enabling developer mode for this development stack. ${EASY_DOCKER_SITE_ERROR_DETAIL:-Check the output above.} ${EASY_DOCKER_SITE_ERROR_LOG_PATH:+See ${stack_dir}/${EASY_DOCKER_SITE_ERROR_LOG_PATH}}" 7 + ;; *) show_warning_and_wait "Site bootstrap failed (${site_flow_status})." 4 ;; diff --git a/scripts/easy-docker/lib/ui/screens/production/setup.sh b/scripts/easy-docker/lib/ui/screens/production/setup.sh index a03a51c5..91a0c417 100755 --- a/scripts/easy-docker/lib/ui/screens/production/setup.sh +++ b/scripts/easy-docker/lib/ui/screens/production/setup.sh @@ -21,7 +21,14 @@ show_setup_menu() { render_main_screen 1 >&2 setup_label="$(get_setup_display_label "${setup_type}")" - status_text="$(printf "%s stack\n\nChoose whether to create a new stack or manage an existing one." "${setup_label}")" + case "${setup_type}" in + development) + status_text="$(printf "%s stack\n\nChoose whether to create a new stack or manage an existing one.\nNew sites created in this stack enable developer mode automatically." "${setup_label}")" + ;; + *) + status_text="$(printf "%s stack\n\nChoose whether to create a new stack or manage an existing one." "${setup_label}")" + ;; + esac render_box_message "${status_text}" "0 2" >&2