When Python Runs Your Containers Series |
---|
When Python Runs Your Containers (part 1) |
When Python Runs Your Containers (part 2) |
Welcome gentle reader. My name is Silent-Mobius, also known as Alex M. Schapelle. In the past we've introduced you to a small project nameddocker-agent
which was created for remote management of docker containers, which I renamed intomazin-docker. The project was conceived as an idea while I was tinkering with various tools for automation and also found alike project of other developer named@andreagrandi
To Address The Known Wisdom
We have created flask RestAPI application that connects with docker sdk to Docker-Engine and does basic commands with docker containers, for docker containers. You can read all about ithere. Once we made mazin-docker work, but the price was too high:
- Application structure was dumped in one folder
- No tests were available
- Extending application as python library was not an option
To Plan Or Not To Plan
Building application while tinkering, usually produces working software, yet it is less usable when extending with additional features. In wisdom of flask developer council, we need to create applications withLarge Applications asPackages. That is why I've invested in planning the new application structure, that also supports tests in addition to continuous integration.
The revamped structure onDevel branch of theproject
and looks like this:
mazin-docker/├── LICENSE├── nginx.conf├── pyproject.toml├── README.md├── src│ └── mazin_docker│ ├── app.py│ ├── config.py│ ├── docker-compose.yml│ ├── hooks│ │ ├── container_edit.py│ │ ├── container_pull.py│ │ └── __init__.py│ ├── __init__.py│ ├── libs│ │ ├── docker_api.py│ │ ├── __init__.py│ │ ├── models.py│ │ └── utils.py│ └── requirements.txt└── tests ├── conftest.py └── test_app.py
pyproject.toml
: Python project package configuration filenginx.conf
: Reverse proxy configuration file for deploymentsrc
: General name for source code of the project. Mainly suggested to be used for tests covertests
: Folder for test configuration and test scripts__ini__.py
: Python constructor used to initializing the object’s state. The task of constructors is to initialize and also enable export.py
files as loadable librariesapp.py
: Main logic and routing of the applicationconfig.py
: Application configuration filelibs
: Folder for keeping external functions and classes of data structuresdocker-compose.yml
: Initial docker compose file that is used to manage container serviceshooks
: folder that holds custom python scripts that are executed when RestAPI event is invokedrequirements.txt
: requirement file that lists python libraries needed to be included for running or developing the project.
In What Manner Shall It Come To Life ?
The question that is most likely to be asked by you, dear reader, would be: how do I make it work?
Through the iterations of the project, we have changed the structure to be used as a library, thus can be executed with simple python execution:
git clone https://gitlab.com/vaiolabs-io/mazin-docker.gitgit checkout Devel# Devel is our main branchpython3 mazin-docker.py
This shall start the the application for local use and development.
In case of production use case, it would be suggested to use one of the popular wsgi application servers, such asgunicorn
,cherrypy
oruWSGI
.
cdmazin-docker# validate that you are in project folderpip3install-r src/requirements.txt# gunicorn is part of the requirements.txt filegunicorn--reload--worker 5--bind 0.0.0.0:8000 src.mazin_docker.app:app
From here on, we can installnginx
to reverse proxy the service of the application, or apache2 to connect the application directly. In case you are adventures, you can run it as it is, insystemd
service mode, which I've shown in previous article.
Summary
At the moment the project is still in development adding features, thus making it Work In Progress, wIP for short.
In case you'd like to request feature, don't hesitate to reach out or open issue ongitlab
So the die is cast, all is left for you to embrace the future and to remember: Do Try To Have Some Fun
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse