Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Vaiolabs profile imageAlex M. Schapelle
Alex M. Schapelle forVaiolabs

Posted on • Edited on

     

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
Enter fullscreen modeExit fullscreen mode
  • pyproject.toml: Python project package configuration file
  • nginx.conf: Reverse proxy configuration file for deployment
  • src : General name for source code of the project. Mainly suggested to be used for tests cover
  • tests: 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 libraries
  • app.py : Main logic and routing of the application
  • config.py : Application configuration file
  • libs : Folder for keeping external functions and classes of data structures
  • docker-compose.yml: Initial docker compose file that is used to manage container services
  • hooks : folder that holds custom python scripts that are executed when RestAPI event is invoked
  • requirements.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
Enter fullscreen modeExit fullscreen mode

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
Enter fullscreen modeExit fullscreen mode

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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

More fromVaiolabs

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp