Skip to content

Commit

Permalink
fix (GRAL): #15 add improvements and fix bugs
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
mmaximo33 committed Jan 11, 2024
1 parent 3ba969f commit 39402f3
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 107 deletions.
2 changes: 1 addition & 1 deletion bin/efde.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions console/common/tasks/command_line
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion console/common/tasks/directory
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions console/docker/props/menu
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
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"
"$PATH_MENU.entry,Entry, Enter the indicated container"
"$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"
)
}
46 changes: 29 additions & 17 deletions console/docker/tasks/main
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"

}

Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions console/docker/tasks/menu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
16 changes: 8 additions & 8 deletions console/efde/props/menu
Original file line number Diff line number Diff line change
Expand Up @@ -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=(
Expand Down
18 changes: 10 additions & 8 deletions console/efde/tasks/config
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion console/efde/tasks/main
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
39 changes: 23 additions & 16 deletions console/efde/tasks/menu
Original file line number Diff line number Diff line change
@@ -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
}
}
46 changes: 43 additions & 3 deletions console/symfony/tasks/install
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down Expand Up @@ -38,16 +41,52 @@ _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)"
}

_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
Expand All @@ -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"
Expand All @@ -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"
}

Loading

0 comments on commit 39402f3

Please sign in to comment.