Skip to content

Commit

Permalink
feat (Symfony): #15 complete migration for the environment
Browse files Browse the repository at this point in the history
- Symfony.Tasks
  - Fix install creation of new project or clone existing
  - Added Symony/console
- Docker.Tasks
  - Complete command management
    - Basics (build, start, stop, down)
    - Extra (Apache, All Stop, Debug logs, Run commands, Entry container)
  • Loading branch information
mmaximo33 committed Jan 9, 2024
1 parent b62bc01 commit 3ba969f
Show file tree
Hide file tree
Showing 14 changed files with 322 additions and 72 deletions.
64 changes: 26 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
## Table of Contents

- [Intro](#intro)
- [About](#about)
- [Installing and Updating](#install--update)
- [Install](#install)
- [Update](#update)
- [Usage](#usage)
- [About](#about)
- [Documentation](#documentation)
- [Code of conduct](#code-of-conduct)
- [Maintainers](#maintainers)
Expand All @@ -18,27 +18,6 @@

## Intro

EFDE arises motivated by giving something back to this beautiful community of programmers, computer scientists or curious about technology.

After having gone through some companies, participated in several teams, been a mentor to team members with beginner profiles and even taught this world to family and friends.
I realized that today there are several elements (services, tools, systems, others) that orbit around trying to learn a language, framework or technology.

EFDE aims to standardize, automate and simplify the deployment or preparation of local development environments for different projects. Without losing the flexibility that they can be customized or adjusted according to the need or complexity of the project.

EFDE is not the definitive solution to your problems, sooner or later you will have to understand exactly what is happening behind the things, but you will acquire the answers of what, when, where, for what and why, as you use it.

Who is it for?
It originally arises to help understand and expedite the induction process for those new members of a project or those people who are starting out in the world of programming and are not entirely clear about some knowledge, concepts or bases of services, applications or implementations. .

But it's also thinking of those developers who have a bit more experience and really want to have a little tool to help them do the usual tasks.

Whatever your level, EFDE will be interesting for you!
You are invited to join, use or even contribute to the growth of EFDE to give back to the developer community and open the doors to the new generations.

It is NOT something super innovative, but surely more than one will find it interesting.

## About

EFDE is a project designed to facilitate the management of local development environments, mainly for teams that constantly have new members or beginners who are starting out in this beautiful world of programming.

The objective of the project is to be able to manage implementations with docker such as
Expand Down Expand Up @@ -75,6 +54,8 @@ Anyway, if you want to know more, you can see the following list with the offici

To **install** EFDE, you should run the install script. To do that, you may either download and run the script manually, or use the following cURL or Wget command:

[See Youtube - Short](https://www.youtube.com/shorts/gE3qYC1AUOk)

```sh
curl -o- https://raw.githubusercontent.com/mmaximo33/efde/15-migrate-to-full-bash/bin/install.sh | bash
```
Expand Down Expand Up @@ -115,34 +96,41 @@ wget -qO- https://raw.githubusercontent.com/mmaximo33/efde/15-migrate-to-full-ba
# By running '$ efde --help'
-----------------------------------------------------------------------
You want to run efde --help now? [Y/n]?

```

[See Youtube - Short](https://www.youtube.com/shorts/gE3qYC1AUOk)
### Usage

- Once installed, you can run EFDE from any directory
- If you are in a project created with EFDE, it will give you the options available for that environment

### Update
```sh
# Run command in console
efde
```

You can update in two ways
## Captures

- Installing it again according to [Install](#install)
- Running efde with the **--update** option
![efde + symfony](./docs/images/efde_symfony.png)

```sh
efde --update
```
## About
EFDE arises motivated by giving something back to this beautiful community of programmers, computer scientists or curious about technology.

## Usage
After having gone through some companies, participated in several teams, been a mentor to team members with beginner profiles and even taught this world to family and friends.
I realized that today there are several elements (services, tools, systems, others) that orbit around trying to learn a language, framework or technology.

Once installed, you can run EFDE from any directory
EFDE aims to standardize, automate and simplify the deployment or preparation of local development environments for different projects. Without losing the flexibility that they can be customized or adjusted according to the need or complexity of the project.

```sh
efde --help
```
EFDE is not the definitive solution to your problems, sooner or later you will have to understand exactly what is happening behind the things, but you will acquire the answers of what, when, where, for what and why, as you use it.

## Captures
Who is it for?
It originally arises to help understand and expedite the induction process for those new members of a project or those people who are starting out in the world of programming and are not entirely clear about some knowledge, concepts or bases of services, applications or implementations. .

![efde + symfony](./docs/images/efde_symfony.png)
But it's also thinking of those developers who have a bit more experience and really want to have a little tool to help them do the usual tasks.

Whatever your level, EFDE will be interesting for you!
You are invited to join, use or even contribute to the growth of EFDE to give back to the developer community and open the doors to the new generations.

It is NOT something super innovative, but surely more than one will find it interesting.

## Documentation

Expand Down
5 changes: 3 additions & 2 deletions bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"end")
efde_echo >&2 "# $PROJECT_NAME is successfully installed and configured."
efde_echo >&2 "# Select the directory and create your new project"
efde_echo >&2 "# By running '$ efde --help'"
efde_echo >&2 "# By running '$ efde'"
;;
*)
efde_echo >&2 "# Error step"
Expand Down Expand Up @@ -293,7 +293,6 @@
efde_project_install_from_git

efde_reset
efde_confirm_default_yes "You want to run efde --help now?" && efde
}

efde_project_install_from_git() {
Expand All @@ -311,6 +310,8 @@
efde_create_bin

efde_print_step end

#efde_confirm_default_yes "You want to run efde now?" && efde
}

efde_project_install_existing_folder(){
Expand Down
13 changes: 7 additions & 6 deletions console/common/tasks/command_line
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
set -euo pipefail

_mod_.run() {
if [ "$#" -ne 3 ]; then
if [ "$#" -lt 3 ]; then
local USE=""
USE+="Error: Three parameters are required:\n"
USE+="Error: At least three parameters are required:\n"
USE+=" - FORCE_SHOW_CLI FORCE_SHOW_OUTPUT COMMAND_LINE\n"
USE+="\n parameters:\n ${@}\n"
USE+="\n Example:\n"
USE+=" - $FUNCNAME FORCE_SHOW_CLI=true FORCE_SHOW_OUTPUT=true COMMAND_LINE\n"
USE+=" - $FUNCNAME 1 0 'cd folder'"
common.tasks.message.danger $USE
common.tasks.message.danger "$USE"
return 1
fi

local FORCE_SHOW_CLI FORCE_SHOW_OUTPUT COMMAND_LINE

FORCE_SHOW_CLI=$1
FORCE_SHOW_OUTPUT=$2
COMMAND_LINE="$3"
shift 2
COMMAND_LINE="$@"

if [ "${GLOBAL_EFDE_CONFIG['CLI_SHOW_DEFAULT']}" = "false" ]; then
FORCE_SHOW_CLI=${GLOBAL_EFDE_CONFIG['CLI_SHOW_CLI']}
Expand All @@ -30,8 +31,8 @@ _mod_.run() {
fi

if [ "${FORCE_SHOW_OUTPUT}" = "false" ]; then
${COMMAND_LINE} > /dev/null 2>&1
eval ${COMMAND_LINE} > /dev/null 2>&1
else
${COMMAND_LINE}
eval ${COMMAND_LINE}
fi
}
4 changes: 3 additions & 1 deletion console/common/tasks/menu
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ _mod_.print_menu(){
# fi
else
[[ "$choice" == "q" ]] && exit 0
[[ "$choice" == "r" ]] && { common.console_clear; ${GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['function_old']}; return; }
# MMToDo: Bug in return functions
[[ "$choice" == "r" ]] && { common.tasks.message.danger "We detected a BUG, we are working to correct the return"; ${GLOBAL_RUN_EFDE}; }
#[[ "$choice" == "r" ]] && { common.console_clear; ${GLOBAL_MENU_RESPONSE_ARRAY_ASOCITIVE['function_old']}; return; }
common.console_clear
common.tasks.message.danger "The '$choice' option is not in the list."
_mod_.print_menu "$question" "${options[@]}"
Expand Down
17 changes: 17 additions & 0 deletions console/docker/props/menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
{
# shellcheck disable=SC2168
local PATH_MENU="docker.tasks.menu"

_mod_MAIN=(
"$PATH_MENU.build,Build docker, Rebuild the project containers"
"$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"
)
}
119 changes: 112 additions & 7 deletions console/docker/tasks/main
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ else
GLOBAL_DOCKER_COMPOSE_COMMAND="docker-compose"
fi

_mod_.dp_command_run(){
local COMMAND_RUN="${GLOBAL_DOCKER_COMPOSE_COMMAND} $@"
common.tasks.command_line.run true false "${COMMAND_RUN}"
}

_mod_.dp_up(){
_mod_.dp_command_run "up -d --build"
}
Expand All @@ -26,21 +31,121 @@ _mod_.dp_all_stop(){
local CONTAINERS=$(docker ps -q)
if [ -n "$CONTAINERS" ]; then
common.tasks.command_line.run false false "docker stop $CONTAINERS"
else
common.tasks.message.info "> There are no containers running at this time."
fi
}

_mod_.dp_command_run(){
local COMMAND_RUN="${GLOBAL_DOCKER_COMPOSE_COMMAND} $@"
common.tasks.command_line.run true false "${COMMAND_RUN}"
}


_mod_.apache_stop(){
if systemctl is-active --quiet apache2; then
local QUESTION="APACHE2 is ON, do you want to turn it OFF?"
if common.tasks.prompt.confirm_default_yes "$QUESTION" ; then
local COMMAND_RUN="sudo service apache2 stop"
common.tasks.command_line.run true false ${COMMAND_RUN}
common.tasks.command_line.run true false "$COMMAND_RUN"
fi
fi
}

_mod_.dp_down(){
_mod_.dp_command_run "down"
}

_mod_.dp_logs(){
local COMMAND_RUN VALUES MSG 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:')

while true; do
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

if [[ -n "$VALUES" ]]; then
COMMAND_RUN="${COMMAND_RUN} | egrep --color=always -E \"$VALUES\""
fi
common.tasks.command_line.run true true "${COMMAND_RUN}"
}

_mod_.dp_show_container(){
local COMMAND="ps"
if [[ $# -gt 0 && "$1" == "simple" ]]; then
COMMAND="ps --format \"table {{.Name}}\t{{.Image}}\t{{.Service}}\""
fi
_mod_.dp_command_run "$COMMAND"

}

#_mod_.container_select() {
# local MSG SERVICE
# _mod_.dp_show_container simple
#
# local MSG=$(common.tasks.message.msg_color warning 'Enter service name:')
# local SERVICE
# SERVICE=$(common.tasks.prompt.request_input "$MSG")
#
# while [[ -z "$SERVICE" || -z $(docker-compose ps -q --services | grep -w "$SERVICE") ]]; do
# common.tasks.message.warning "Invalid service name. Please enter a valid service."
# SERVICE=$(common.tasks.prompt.request_input "$MSG")
# done
#
# _mod_.dp_command_run "ps --filter name=$SERVICE"
# echo "$SERVICE"
#}


_mod_.container_entry(){
local COMMAND_RUN VALUES MSG SERVICE

_mod_.dp_show_container simple
MSG=$(common.tasks.message.msg_color warning 'Enter service name:')
SERVICE=$(common.tasks.prompt.request_input "$MSG")

MSG=$(common.tasks.message.msg_color warning 'You want to open a new instance? RUN=Y or EXEC=N')
if common.tasks.prompt.confirm_default_yes "$MSG"; then
COMMAND_RUN="run --rm"
else
COMMAND_RUN="exec"
fi
_mod_.dp_command_run "$COMMAND_RUN $SERVICE bash"
}

_mod_.container_run_command() {
local COMMAND_RUN COMMAND_CUSTOM MSG SERVICE

_mod_.dp_show_container simple

MSG=$(common.tasks.message.msg_color warning 'Enter service name:')
SERVICE=$(common.tasks.prompt.request_input "$MSG")

MSG=$(common.tasks.message.msg_color warning 'You want to open a new instance? RUN=Y or EXEC=N')
if common.tasks.prompt.confirm_default_yes "$MSG"; then
COMMAND_RUN="run --rm"
else
COMMAND_RUN="exec"
fi

while true; do
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"

MSG=$(common.tasks.message.msg_color warning 'Do you want to run another command?')
if common.tasks.prompt.confirm_default_yes "$MSG"; then
continue
else
break
fi
done
}

48 changes: 48 additions & 0 deletions console/docker/tasks/menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -euo pipefail

_mod_.main(){
common.tasks.menu.print_menu "Select an option:" "${docker_props_menu_MAIN[@]}"
}

_mod_.build(){
docker.tasks.main.dp_up
_mod_.main
}

_mod_.start(){
docker.tasks.main.dp_start
_mod_.main
}

_mod_.stop(){
docker.tasks.main.dp_stop
_mod_.main
}

_mod_.stop_all(){
docker.tasks.main.dp_all_stop
_mod_.main
}

_mod_.apache_stop(){
docker.tasks.main.apache_stop
_mod_.main
}

_mod_.down(){
docker.tasks.main.dp_down
_mod_.main
}

_mod_.logs(){
docker.tasks.main.dp_logs
}

_mod_.entry(){
docker.tasks.main.container_entry
}

_mod_.command(){
docker.tasks.main.container_run_command
}
Loading

0 comments on commit 3ba969f

Please sign in to comment.