Python console menu
Very often, when working on a project, tasks arise that require entering several commands into the console, for example, rebuilding the frontend, starting / stopping several docker containers, deploying the environment on a new development computer, and so on.
This is generally not difficult, but often such tasks arise very regularly, require repetition, turning into a routine.
And now, in fact, once the idea came up how to reduce the time for this, what means, simplifying the process as much as possible, implementing a small utility that allows you to wrap sets of frequently performed actions in items of a convenient menu displayed in the console.
Decided to implement in Python since Out of the box, it is installed on most Linux distributions, and you won’t need to install additional packages to use it.
It turned out something very convenient available for cloning with github.
All settings (namely, what item should be performed) are stored in the menu.yml file.
The settings file given as an example in the repository is equipped with all the necessary comments, but in order to make everything even clearer there is a working example on the github (https://github.com/hrustbb2/env-example).
An example is an application consisting of three docker containers (php, mysql, nginx) with separate configs for development and production environments and two separate deployment scripts in these environments.
So, clone, run ./env and see a menu of three items:
1 |
0. Exit 1. Develop 2. Production Chose action: _ |
We’ll expand our application in development mode, for this we select item 1, and go to the submenu:
1 |
0. Exit 1. Build 2. Deploy and Up 3. Up 4. Stop 5. Remove Chose action: _ |
Here, first we create our containers by selecting 1, after which you need to come up with and enter the name of the application. Here I want to bring your attention to the fact that the parameters necessary for the execution of certain commands are required to be entered only once, then they are saved in the env.ini file and you do not need to enter them when you restart it. Then, after waiting a little while until the creation of the containers is completed, we will run the script to deploy the application itself, choosing 2.
In this example, the script clones the Laravel startup application into ./app, installs the necessary composer packages, rolls migrations, and creates the .env configuration file. This is done only once at the very beginning, after which the environment is started by selecting item 3. Item 5 serves to delete the created containers after they become no longer needed, for example, when work on the project is completed.
That’s probably all, now open localhost in the browser and continue working.
Sometimes on production there is a need to run some commands automatically on the crown, for example, updating SSL certificates, backup, etc. In this case, run, for example ./env -e 1-2-3, where 1-2-3 is the path to the desired command in the menu.
Related Posts
Leave a Reply Cancel reply
Service
Categories
- DEVELOPMENT (103)
- DEVOPS (53)
- FRAMEWORKS (25)
- IT (25)
- QA (14)
- SECURITY (13)
- SOFTWARE (13)
- UI/UX (6)
- Uncategorized (8)