From 39402f3c14fe8c4796930e748c341367a6d06cb0 Mon Sep 17 00:00:00 2001 From: Marucci Maximo Date: Thu, 11 Jan 2024 15:59:13 -0300 Subject: [PATCH] fix (GRAL): #15 add improvements and fix bugs - Symfony - add database variable setting - fix installation sequence - Efde - Code optimization - Docker - add checks and validation in commands - Common - Fix validation in command_line - Add confirmation to delete directory and file --- bin/efde.sh | 2 +- console/common/tasks/command_line | 6 ++-- console/common/tasks/directory | 2 +- console/docker/props/menu | 6 ++-- console/docker/tasks/main | 46 +++++++++++++++++----------- console/docker/tasks/menu | 11 +++++++ console/efde/props/menu | 16 +++++----- console/efde/tasks/config | 18 ++++++----- console/efde/tasks/main | 2 +- console/efde/tasks/menu | 39 +++++++++++++---------- console/symfony/tasks/install | 46 ++++++++++++++++++++++++++-- console/symfony/tasks/main | 50 +++++++++++++++++------------- console/symfony/tasks/menu | 51 ++++++++++++++++--------------- 13 files changed, 188 insertions(+), 107 deletions(-) diff --git a/bin/efde.sh b/bin/efde.sh index 89b823b..4d40f10 100755 --- a/bin/efde.sh +++ b/bin/efde.sh @@ -56,7 +56,7 @@ menu_implementation(){ main(){ efde.tasks.config.check_config if ! efde.tasks.implemention.has_folder_implementation ; then - menu_main + efde.tasks.menu.main fi menu_implementation } diff --git a/console/common/tasks/command_line b/console/common/tasks/command_line index 95df325..af6040d 100644 --- a/console/common/tasks/command_line +++ b/console/common/tasks/command_line @@ -30,9 +30,9 @@ _mod_.run() { common.tasks.message.info "# RUN CLI > ${COMMAND_LINE}" fi - if [ "${FORCE_SHOW_OUTPUT}" = "false" ]; then - eval ${COMMAND_LINE} > /dev/null 2>&1 + if [ "${FORCE_SHOW_OUTPUT}" = "true" ]; then + eval ${COMMAND_LINE} else - eval ${COMMAND_LINE} + eval ${COMMAND_LINE} > /dev/null 2>&1 fi } \ No newline at end of file diff --git a/console/common/tasks/directory b/console/common/tasks/directory index 7fbcf1f..83fd83c 100644 --- a/console/common/tasks/directory +++ b/console/common/tasks/directory @@ -15,7 +15,7 @@ _mod_.create_recursive() { _mod_.remove() { local FORCE PATH FORCE=false - [[ "$1" == "force" ]] && { force=true; shift; path="$1"; } + [[ "$1" == "force" ]] && { FORCE=true; shift; PATH="$1"; } local PATH="$1" if [[ -z "$PATH" ]]; then diff --git a/console/docker/props/menu b/console/docker/props/menu index 65c7e56..ff29161 100644 --- a/console/docker/props/menu +++ b/console/docker/props/menu @@ -4,7 +4,8 @@ local PATH_MENU="docker.tasks.menu" _mod_MAIN=( - "$PATH_MENU.build,Build docker, Rebuild the project containers" + "$PATH_MENU.build,Build, Build or Re-Build the project containers" + "$PATH_MENU.show,Show, Show (start) containers of project" "$PATH_MENU.start,Start, Start containers of project" "$PATH_MENU.stop,Stop, Stop containers of project" "$PATH_MENU.logs,Logs, Inspect environment logs" @@ -12,6 +13,7 @@ "$PATH_MENU.command,Run command, Run command in container. Example: bash, cp, rm" "$PATH_MENU.stop_all,All Stop, Stops all containers running on the computer" "$PATH_MENU.apache_stop,Apache Stop, Apache2 stop service" - "$PATH_MENU.down,Down, Destroy all project containers, networks" + "$PATH_MENU.down,Down, Destroy all project containers and networks" + "$PATH_MENU.recipe_see,See recipe,See recipe docker-compose.yml" ) } diff --git a/console/docker/tasks/main b/console/docker/tasks/main index f45f151..a51f593 100644 --- a/console/docker/tasks/main +++ b/console/docker/tasks/main @@ -30,7 +30,7 @@ _mod_.dp_stop(){ _mod_.dp_all_stop(){ local CONTAINERS=$(docker ps -q) if [ -n "$CONTAINERS" ]; then - common.tasks.command_line.run false false "docker stop $CONTAINERS" + common.tasks.command_line.run true false "docker stop $CONTAINERS" else common.tasks.message.info "> There are no containers running at this time." fi @@ -47,27 +47,37 @@ _mod_.apache_stop(){ } _mod_.dp_down(){ - _mod_.dp_command_run "down" + local QUESTION=$(common.tasks.message.msg_color danger "Do you want to remove services from the project?") + _mod_.dp_show_container simple + if common.tasks.prompt.confirm_default_no "$QUESTION" ; then + _mod_.dp_command_run "down" + fi } _mod_.dp_logs(){ - local COMMAND_RUN VALUES MSG SEARCH + local -A MSG + local COMMAND_RUN VALUES SEARCH COMMAND_RUN="${GLOBAL_DOCKER_COMPOSE_COMMAND} logs -f" VALUES="" - MSG=$(common.tasks.message.msg_color warning 'Enter value to search or press Enter for all:') + MSG=( + [MAIN]=$(common.tasks.message.msg_color warning 'Enter value to search or press ENTER for all:') + [NEXT]=$(common.tasks.message.msg_color warning 'Find another value or ENTER:') + ) + common.tasks.message.info "Log monitor" while true; do - SEARCH=$(common.tasks.prompt.request_input "$MSG") + SEARCH=$(common.tasks.prompt.request_input "${MSG['MAIN']}") - if [[ -z "$SEARCH" ]]; then - break + if [[ -z "$SEARCH" ]]; then + break + else + if [[ -n "$VALUES" ]]; then + VALUES="$VALUES|$SEARCH" else - if [[ -n "$VALUES" ]]; then - VALUES="$VALUES|$SEARCH" - else - VALUES="$SEARCH" - fi + VALUES="$SEARCH" + MSG[MAIN]="${MSG['NEXT']}" fi + fi done if [[ -n "$VALUES" ]]; then @@ -76,12 +86,14 @@ _mod_.dp_logs(){ common.tasks.command_line.run true true "${COMMAND_RUN}" } + + _mod_.dp_show_container(){ - local COMMAND="ps" + local COMMAND="ps -a" if [[ $# -gt 0 && "$1" == "simple" ]]; then - COMMAND="ps --format \"table {{.Name}}\t{{.Image}}\t{{.Service}}\"" + COMMAND="ps -a --format \"table {{.Name}}\t{{.Image}}\t{{.Service}}\t{{.Status}}\"" fi - _mod_.dp_command_run "$COMMAND" + common.tasks.command_line.run true true "${GLOBAL_DOCKER_COMPOSE_COMMAND} $COMMAND" } @@ -116,7 +128,7 @@ _mod_.container_entry(){ else COMMAND_RUN="exec" fi - _mod_.dp_command_run "$COMMAND_RUN $SERVICE bash" + common.tasks.command_line.run true true "${GLOBAL_DOCKER_COMPOSE_COMMAND} $COMMAND_RUN $SERVICE bash" } _mod_.container_run_command() { @@ -138,7 +150,7 @@ _mod_.container_run_command() { MSG=$(common.tasks.message.msg_color warning 'What command do you want to run?:') COMMAND_CUSTOM=$(common.tasks.prompt.request_input "$MSG") - common.tasks.command_line.run true false "$GLOBAL_DOCKER_COMPOSE_COMMAND $COMMAND_RUN $SERVICE $COMMAND_CUSTOM" + common.tasks.command_line.run true true "$GLOBAL_DOCKER_COMPOSE_COMMAND $COMMAND_RUN $SERVICE $COMMAND_CUSTOM" MSG=$(common.tasks.message.msg_color warning 'Do you want to run another command?') if common.tasks.prompt.confirm_default_yes "$MSG"; then diff --git a/console/docker/tasks/menu b/console/docker/tasks/menu index 4f60fa5..25e3c1f 100644 --- a/console/docker/tasks/menu +++ b/console/docker/tasks/menu @@ -10,6 +10,11 @@ _mod_.build(){ _mod_.main } +_mod_.show(){ + docker.tasks.main.dp_show_container simple + _mod_.main +} + _mod_.start(){ docker.tasks.main.dp_start _mod_.main @@ -41,8 +46,14 @@ _mod_.logs(){ _mod_.entry(){ docker.tasks.main.container_entry + _mod_.main } _mod_.command(){ docker.tasks.main.container_run_command } + +_mod_.recipe_see(){ + cat docker-compose.yml + _mod_.main +} diff --git a/console/efde/props/menu b/console/efde/props/menu index bee572d..acfa2e3 100644 --- a/console/efde/props/menu +++ b/console/efde/props/menu @@ -5,15 +5,15 @@ set -euo pipefail local PATH_MENU="efde.tasks" _mod_MAIN=( - "$PATH_MENU.menu.main,Efde config , Settings and configurations" + "$PATH_MENU.menu.efde,Efde config , Settings and configurations" "symfony.tasks.menu.create_environment,Install Symfony, Dockerization for symfony (WebApp or Apis)" - "$PATH_MENU.menu.comming_soon,Coming Soon - Install Laravel, " - "$PATH_MENU.menu.comming_soon,Coming Soon - Install Magento, " - "$PATH_MENU.menu.comming_soon,Coming Soon - Install Wordpress, " - "$PATH_MENU.menu.comming_soon,Coming Soon - Install Woocomerce, " - "$PATH_MENU.menu.comming_soon,Coming Soon - Install Prestashop, " - "$PATH_MENU.menu.comming_soon,Coming Soon - Install Django, " - "$PATH_MENU.menu.comming_soon,Coming Soon - Tools,Tools for developers, " + "$PATH_MENU.menu.coming_soon,Coming Soon - Install Laravel, " + "$PATH_MENU.menu.coming_soon,Coming Soon - Install Magento, " + "$PATH_MENU.menu.coming_soon,Coming Soon - Install Wordpress, " + "$PATH_MENU.menu.coming_soon,Coming Soon - Install Woocomerce, " + "$PATH_MENU.menu.coming_soon,Coming Soon - Install Prestashop, " + "$PATH_MENU.menu.coming_soon,Coming Soon - Install Django, " + "$PATH_MENU.menu.coming_soon,Coming Soon - Tools,Tools for developers, " ) _mod_EFDE=( diff --git a/console/efde/tasks/config b/console/efde/tasks/config index 5342a04..5dc4a8e 100644 --- a/console/efde/tasks/config +++ b/console/efde/tasks/config @@ -58,15 +58,17 @@ _mod_.set_efde_global(){ common.tasks.prompt.confirm_default_yes "$MSG" && RESPONSE=true _mod_.set_var "CLI_SHOW_DEFAULT" "$RESPONSE" if [ "$RESPONSE" = "false" ]; then - MSG=$(common.tasks.message.msg_color warning "Always show executed commands?") - common.tasks.prompt.confirm_default_yes "$MSG" && RESPONSE=true || RESPONSE=false - _mod_.set_var "CLI_SHOW_CLI" "$RESPONSE" - - MSG=$(common.tasks.message.msg_color warning "Always show command output?") - common.tasks.prompt.confirm_default_yes "$MSG" && RESPONSE=true || RESPONSE=false - _mod_.set_var "CLI_SHOW_OUTPUT" "$RESPONSE" + MSG=$(common.tasks.message.msg_color warning "Always show executed commands?") + common.tasks.prompt.confirm_default_yes "$MSG" && RESPONSE=true || RESPONSE=false + _mod_.set_var "CLI_SHOW_CLI" "$RESPONSE" + MSG=$(common.tasks.message.msg_color warning "Always show command output?") + common.tasks.prompt.confirm_default_yes "$MSG" && RESPONSE=true || RESPONSE=false + _mod_.set_var "CLI_SHOW_OUTPUT" "$RESPONSE" + else + RESPONSE=false + _mod_.set_var "CLI_SHOW_CLI" "$RESPONSE" + _mod_.set_var "CLI_SHOW_OUTPUT" "$RESPONSE" fi - } _mod_.set_config_version() { diff --git a/console/efde/tasks/main b/console/efde/tasks/main index 66fb16b..8017fd7 100644 --- a/console/efde/tasks/main +++ b/console/efde/tasks/main @@ -6,7 +6,7 @@ set -euo pipefail ${GLOBAL_RUN_EFDE} } - _mod_.comming_soon(){ + _mod_.coming_soon(){ common.tasks.message.info "We're excited about the upcoming release!" common.tasks.message.info "Our team is hard at work to bring you the latest features and improvements." common.tasks.message.info "Stay tuned for updates and follow the project's progress on $URL_REPOSITORY." diff --git a/console/efde/tasks/menu b/console/efde/tasks/menu index 1561bf4..c9d7f19 100644 --- a/console/efde/tasks/menu +++ b/console/efde/tasks/menu @@ -1,24 +1,31 @@ #!/usr/bin/env bash set -euo pipefail +{ + TITLE="$(printf '%.s+' {1..45})\nEFDE | Easy and Fast Developer Environment\nSelect an option:" -_mod_.main(){ - common.tasks.menu.print_menu "Select an option:" "${efde_props_menu_EFDE[@]}" -} + _mod_.main(){ + common.tasks.menu.print_menu "$TITLE" "${efde_props_menu_MAIN[@]}" + } -_mod_.config(){ - common.tasks.menu.print_menu "Select an option:" "${efde_props_menu_CONFIG[@]}" -} + _mod_.efde(){ + common.tasks.menu.print_menu "$TITLE" "${efde_props_menu_EFDE[@]}" + } -_mod_.config_show(){ - efde.tasks.config.show_config - _mod_.config -} + _mod_.config(){ + common.tasks.menu.print_menu "$TITLE" "${efde_props_menu_CONFIG[@]}" + } -_mod_.tools(){ - common.tasks.menu.print_menu "Select an option:" "${efde_props_menu_TOOLS[@]}" -} + _mod_.config_show(){ + efde.tasks.config.show_config + _mod_.config + } + + _mod_.tools(){ + common.tasks.menu.print_menu "$TITLE" "${efde_props_menu_TOOLS[@]}" + } -_mod_.comming_soon(){ - efde.tasks.main.comming_soon - _mod_.main + _mod_.coming_soon(){ + efde.tasks.main.coming_soon + _mod_.main + } } diff --git a/console/symfony/tasks/install b/console/symfony/tasks/install index d5ddd92..4fc9d90 100644 --- a/console/symfony/tasks/install +++ b/console/symfony/tasks/install @@ -5,7 +5,10 @@ declare -gA GLOBAL_SYMFONY_INSTALL=( [MESSAGE_WARNING]="Default will install symfony for microservice projects or apis" [MESSAGE_ASK]=$(common.tasks.message.msg_color warning "Do you want to install the packages for webapp?") [MESSAGE_CLONE_GIT]="Enter the url of your repository" - [MESSAJE_CLONE_URL]=$(common.tasks.message.msg_color warning "Enter URL (https):") + [MESSAGE_CLONE_URL]=$(common.tasks.message.msg_color warning "Enter URL (https):") + [MESSAGE_DATABASE]="MYSQL AND PHPMYADMIN Variables" + [MESSAGE_DATABASE_DEFAULT]=$(common.tasks.message.msg_color warning "Do you want to set variables for DATABASE?") + [MESSAGE_DATABASE_VARIABLE]=$(common.tasks.message.msg_color warning "Enter value for variable [VALUE]:") ) _mod_.run_app_cli(){ @@ -38,9 +41,44 @@ _mod_.get_env_version(){ echo $(common.tasks.env_variable.get_variable "VERSION" "$PATH_ENV") } +_mod_.set_database_variables(){ + local VALUE="" + local MSG="${GLOBAL_SYMFONY_INSTALL['MESSAGE_DATABASE_VARIABLE']}" + local -A KEYS=("MYSQL_ROOT_PASSWORD" "MYSQL_USER" "MYSQL_PASSWORD" "MYSQL_DATABASE") + + + common.tasks.message.info "\n${GLOBAL_SYMFONY_INSTALL['MESSAGE_DATABASE']}" + if common.tasks.prompt.confirm_default_yes "${GLOBAL_SYMFONY_INSTALL['MESSAGE_DATABASE_DEFAULT']}" ; then + GLOBAL_SETUP_IMPLEMENTION['MYSQL_ROOT_PASSWORD']=toor + GLOBAL_SETUP_IMPLEMENTION['MYSQL_USER']=efdeuser + GLOBAL_SETUP_IMPLEMENTION['MYSQL_PASSWORD']=efdepassword + GLOBAL_SETUP_IMPLEMENTION['MYSQL_DATABASE']=efdedb + else + for KEY in "${KEYS[@]}"; do + local MSG_CUSTOM=$(echo "$MSG" | sed "s/VALUE/$KEY/g") + while true; do + VALUE=$(common.tasks.prompt.request_input "$MSG_CUSTOM") + if [ -n "$VALUE" ] && [ "${#VALUE}" -ge 4 ]; then + break + else + common.tasks.message.danger "You must enter a value greater than 4 characters" + fi + done + + GLOBAL_SETUP_IMPLEMENTION["$KEY"]="$VALUE" + done + fi + + # Default variables + GLOBAL_SETUP_IMPLEMENTION['PMA_HOST']=db + GLOBAL_SETUP_IMPLEMENTION['PMA_USER']=root + GLOBAL_SETUP_IMPLEMENTION['PMA_PASSWORD']="${GLOBAL_SETUP_IMPLEMENTION['MYSQL_ROOT_PASSWORD']}" +} + _mod_.prepare_setup_environment(){ + _mod_.set_database_variables efde.tasks.implemention.setup_environment - # Siempre entro al proyecto + # IMPORTANT: Siempre entro al proyecto common.tasks.command_line.run false false "cd $(efde.tasks.implemention.get_new_path_project)" } @@ -48,6 +86,7 @@ _mod_.create_new_environment(){ _mod_.question_versions _mod_.question_type _mod_.prepare_setup_environment + docker.tasks.main.dp_all_stop # Importat: If another container exists using the same ports _mod_.run_app_cli "composer create-project symfony/skeleton:$(_mod_.get_env_version).* ." [ "${GLOBAL_SYMFONY_INSTALL['INSTALL_WEBAPP']}" = "true" ] && _mod_.run_app_cli "composer require webapp" _mod_.docker_start @@ -57,7 +96,7 @@ _mod_.clone_environment(){ _mod_.question_versions _mod_.prepare_setup_environment common.tasks.message.warning "${GLOBAL_SYMFONY_INSTALL['MESSAGE_CLONE_GIT']}" - local REPOSITORY_URL=$(common.tasks.prompt.request_input "${GLOBAL_SYMFONY_INSTALL['MESSAJE_CLONE_URL']} ") + local REPOSITORY_URL=$(common.tasks.prompt.request_input "${GLOBAL_SYMFONY_INSTALL['MESSAGE_CLONE_URL']} ") # MMTodo: Mover a un metodo de tasks.git common.tasks.command_line.run true false "git clone $REPOSITORY_URL $(pwd)/app" @@ -70,5 +109,6 @@ _mod_.docker_start(){ docker.tasks.main.dp_all_stop docker.tasks.main.dp_up efde.tasks.implemention.clear_global_variables + common.tasks.message.success "SUCCES: Project installed successfully, check the url http://localhost" } diff --git a/console/symfony/tasks/main b/console/symfony/tasks/main index 7debd22..b4710db 100644 --- a/console/symfony/tasks/main +++ b/console/symfony/tasks/main @@ -14,34 +14,40 @@ _mod_.permissions_fix(){ } _mod_.symfony_console_run_command(){ - local COMMAND_RUN COMMAND_CUSTOM MSG VALUES SEARCH + local -A MSG + local COMMAND_RUN COMMAND_CUSTOM VALUES SEARCH VALUES="" COMMAND_RUN="bin/console" - MSG=$(common.tasks.message.msg_color warning 'Enter the command or press enter for more info:') - COMMAND_CUSTOM=$(common.tasks.prompt.request_input "$MSG") + MSG=( + [MAIN]=$(common.tasks.message.msg_color warning 'Write the command or press ENTER to search:') + [NEXT]=$(common.tasks.message.msg_color warning 'Write the value to search or press ENTER for the full list:') + [MORE]=$(common.tasks.message.msg_color warning 'Find another value or ENTER:') + ) + common.tasks.message.info "USE \n Run bin/console " + COMMAND_CUSTOM=$(common.tasks.prompt.request_input "${MSG['MAIN']}") if [[ -z "$COMMAND_CUSTOM" ]]; then - while true; do - MSG=$(common.tasks.message.msg_color warning 'Enter what you are looking for or press enter for the full list:') - SEARCH=$(common.tasks.prompt.request_input "$MSG") - if [[ -z "$SEARCH" ]]; then - break - else - if [[ -n "$VALUES" ]]; then - VALUES="$VALUES|$SEARCH" - else - VALUES="$SEARCH" - fi - fi - done + while true; do + SEARCH=$(common.tasks.prompt.request_input "${MSG['NEXT']}") + if [[ -z "$SEARCH" ]]; then + break + else + if [[ -n "$VALUES" ]]; then + VALUES="$VALUES|$SEARCH" + else + VALUES="$SEARCH" + MSG['NEXT']=${MSG[MORE]} + fi + fi + done - if [[ -n "$VALUES" ]]; then - COMMAND_CUSTOM="list | egrep --color=always \"$VALUES\"" - else - COMMAND_CUSTOM="list" - fi + if [[ -n "$VALUES" ]]; then + COMMAND_CUSTOM="list | egrep --color=always \"$VALUES\"" + else + COMMAND_CUSTOM="list" + fi fi - _mod_.run_command_app_cli "$COMMAND_RUN $COMMAND_CUSTOM" + common.tasks.command_line.run true true "${GLOBAL_DOCKER_COMPOSE_COMMAND} run --rm app_cli $COMMAND_RUN $COMMAND_CUSTOM" } diff --git a/console/symfony/tasks/menu b/console/symfony/tasks/menu index 4ab8960..606c115 100644 --- a/console/symfony/tasks/menu +++ b/console/symfony/tasks/menu @@ -1,34 +1,35 @@ #!/usr/bin/env bash set -euo pipefail +{ + _mod_.main(){ + common.tasks.menu.print_menu "Select an option:" "${symfony_props_menu_MAIN[@]}" + } -_mod_.main(){ - common.tasks.menu.print_menu "Select an option:" "${symfony_props_menu_MAIN[@]}" -} + _mod_.create_environment(){ + common.tasks.menu.print_menu "Select an option:" "${symfony_props_menu_CREATE_ENVIRONMENT[@]}" + } -_mod_.create_environment(){ - common.tasks.menu.print_menu "Select an option:" "${symfony_props_menu_CREATE_ENVIRONMENT[@]}" -} + _mod_.create_environment_version(){ + common.tasks.menu.print_menu "Select an option:" "${symfony_props_menu_CREATE_ENVIRONMENT_VERSION[@]}" + } -_mod_.create_environment_version(){ - common.tasks.menu.print_menu "Select an option:" "${symfony_props_menu_CREATE_ENVIRONMENT_VERSION[@]}" -} + _mod_.show_config_project(){ + cat "$(efde.tasks.implemention.get_current_path_env_file)" + if common.tasks.prompt.confirm_default_yes $(common.tasks.message.msg_color warning "Back to menu?"); then + common.console_clear + _mod_.main + else + exit + fi + } -_mod_.show_config_project(){ - cat "$(efde.tasks.implemention.get_current_path_env_file)" - if common.tasks.prompt.confirm_default_yes $(common.tasks.message.msg_color warning "Back to menu?"); then - common.console_clear + _mod_.symfony_fix_permissions(){ + symfony.tasks.main.permissions_fix _mod_.main - else - exit - fi -} + } -_mod_.symfony_fix_permissions(){ - symfony.tasks.main.permissions_fix - _mod_.main -} - -_mod_.console(){ - symfony.tasks.main.symfony_console_run_command - _mod_.main + _mod_.console(){ + symfony.tasks.main.symfony_console_run_command + _mod_.main + } } \ No newline at end of file