Docker для python. Первые шаги

Если не вдаваться в технические детали Docker ближе всего к VirtualBox, VMware или другим средствам виртуализации. Технические отличия заключаются в других способах изоляции запускаемой гостевой (guest) операционной системы и разделения ресурсов основной (host) операционной системы. Как правило каждый работающий в Docker экземпляр гостевой операционной системы предназначен для запуска одного единственного приложения. При этом задействуется меньше ресурсов, чем при запуске в виртуальной машине. Для этого создается своя файловая система, свои виртуальные сетевые интерфейсы - как бы контейнер внутри которого приложение работает. Docker это программное обеспечение для контейнеризации приложений. ...

<span title='2022-01-04 00:00:00 +0000 UTC'>January 4, 2022</span>

Snippet for printing a subclass tree

Sometimes I needed to figure out the class hierarchy. For this, I wrote a small piece of code to visualize the class tree. def format_output(class_name, prefix, is_last): left_simbol = "└" if is_last else "├" return prefix + left_simbol + "───" + class_name def print_subclass_tree(thisclass, prefix=""): for count, subclass in enumerate(thisclass.__subclasses__(), start=1): is_last = count == len(thisclass.__subclasses__()) print(format_output(subclass.__name__, prefix, is_last)) devide_simbol = "" if is_last else "│" print_subclass_tree(subclass, prefix + devide_simbol + "\t") print_subclass_tree(BaseException) # ============ OUTPUT ================== # >>> print_subclass_tree(BaseException) # ├───Exception # │ ├───TypeError # │ ├───StopAsyncIteration # │ ├───StopIteration # │ ├───ImportError # │ │ ├───ModuleNotFoundError # │ │ └───ZipImportError # ... # ├───SystemExit # └───KeyboardInterrupt # >>> from django.views.generic.base import View # >>> print_subclass_tree(View) # ├───TemplateView # ├───RedirectView # ├───BaseDetailView # │ ├───DetailView # │ ├───BaseDateDetailView # │ │ └───DateDetailView # │ └───BaseDeleteView # │ └───DeleteView # ... # └───JavaScriptCatalog # └───JSONCatalog Link: gist.github.com

<span title='2021-12-09 00:00:00 +0000 UTC'>December 9, 2021</span>

Starting a production Django server

I wrote ansible playbook for starting up a production Django server with PostgreSQL, Gunicorn and Nginx. When I tested the script, I used the Ubuntu Server image from this link. All I needed to install additionally was an ssh server for ansible to work. sudo apt update && sudo apt upgrade sudo apt install openssh-server I used a VirtualBox image and set the network settings to bridge mode. The IP address was obtained via the dhcp protocol. The command to display the ip address is ip addr. ...

<span title='2021-10-15 00:00:00 +0000 UTC'>October 15, 2021</span>

Starting a Synapse/Matrix server on Raspberry Pi

Synapse is a reference “homeserver” implementation of Matrix. In this article, I will show step by step how to install a Matrix server on a Raspberry Pi model B (1 generation) with Raspbian Buster. In my setup, the username of the Raspberry Pi user is pi, and the home directory is /home/pi. For more information, see Matrix-Element : How to install the Synapse-Matrix - Raspberry PI - Rock 64 Server. Synapse/Matrix service installation Install the necessary packages: sudo apt -y install build-essential make python3 python3-dev python3-dev python3-virtualenv python3-pip python3-setuptools libffi-dev libpq-dev python3-cffi zlib1g-dev libxml2-dev libxml2-dev libxslt1-dev libssl-dev libjpeg-dev python3-lxml virtualenv libopenjp2-7 libtiff5 Project compilation: mkdir -p ~/synapse virtualenv -p python3 ~/synapse/env cd ~/synapse/ source ~/synapse/env/bin/activate pip install --upgrade pip pip install --upgrade setuptools pip install matrix-synapse[all] Generation of the configuration file for synapse-matrix python3 -m synapse.app.homeserver --server-name YOUR_DOMAIN_NAME --config-path homeserver.yaml --generate-config --report-stats=no deactivate Service configuration vim ~/synapse/homeserver.yaml Edit these parameters: ...

<span title='2021-10-03 00:00:00 +0000 UTC'>October 3, 2021</span>

Starting a remote docker development server on DigitalOcean droplet

Thanks Fedor Borshev for awesome tutorial “Как писать код на МОЩНОЙ удалённой машине DigitalOcean”. I repeated Fedor’s experience with Windows + WSL2. Video: Link to ansible playbook for for deploying docker on DO droplet and empty django project for testing: github. Links: [1] Ansible playbook for for deploying docker on DO droplet [2] Youtube-канал “Почему не работает?”

<span title='2021-08-15 00:00:00 +0000 UTC'>August 15, 2021</span>

How to push to GitHub via HTTPS if you have enabled two-factor authentication

If you enabled two-factor authentication in your Github account you won’t be able to push via HTTPS using your accounts password. Instead you need to generate a personal access token. This can be done in the application settings of your Github account. Using this token as your password should allow you to push to your remote repository via HTTPS. Use your username as usual. You may also need to update the origin for your repository if set to https: ...

<span title='2021-07-31 00:00:00 +0000 UTC'>July 31, 2021</span>

The first acquaintance with the Cisco DevNet Sandbox

Cisco allows you to perform laboratory work or test the APIs in sandbox. It is completely free. All the necessary devices are available in the sandbox permanently or by reservation. Here’s what Cisco writes about it: DevNet Sandbox makes Cisco’s free spread of technology available to developers and engineers by providing packaged labs we call Sandboxes. That’s right, totally free! There are two types of sandboxes, Always-On and Reservation. Each sandbox typically highlight one Cisco product (think, CallManager, APIC, etc). Sandboxes can be used for development, testing APIs, learning how to configure a product, training, hack-a-thons, and much more! ...

<span title='2021-07-25 00:00:00 +0000 UTC'>July 25, 2021</span>

A dynamic GitHub profile with GitHub Actions

Thanks Yannick Chenot for the article How to Build a Dynamic GitHub Profile with GitHub Actions and PHP! It describes how to set up automatic updating of links to the latest blog posts in the GitHub profile using GitHub Actions. I will not retell the article, and you can read about the profile on GitHub here. Here is my python solution import requests from bs4 import BeautifulSoup url = "https://vostbur.github.io" main_page = BeautifulSoup(requests.get(url).content, "html.parser") content = f"### Last posts from [blog]({url}):\n\n" for article_div in main_page.find_all("div", {"class": "mb-4"}): article_url = article_div.find("a", href=True) content += f" - [{article_url.text}]({article_url['href']})\n" with open("README.md", "w", encoding="utf-8") as f: f.write(content) Yaml file for GitHub Actions ...

<span title='2021-07-22 00:00:00 +0000 UTC'>July 22, 2021</span>

Deploying the django app on the DigitalOcean App Platform

For deploying Django apps, I tried PaaS such as Heroku and Pythonanywhere. It’s the turn of the DigitalOcean App Platform. And so far, this is the easiest and fastest way to deploy a Django app in production. There is awesome guide on how to do this on DigitalOcean’s tutorials. For testing, I wrote a small application that generates a configuration snippet for configuring ssh on cisco devices. For simplicity, I didn’t use a database and static content. For such an application, in fact, there is no need for a server side, just JavaScript is enough :) ...

<span title='2021-07-21 00:00:00 +0000 UTC'>July 21, 2021</span>

Запуск CSR1000v в VirtualBox и VMware

В прошлой статье я рассказал как подготовить и запустить любую версию виртуального маршрутизатора Cisco - Cloud Services Router (СSR1000v) в VirtualBox под Windows. С версии Cisco IOS XE 3.13S можно обойтись без настройки последовательного интерфейса. Запускать будем всё тот же релиз 3.15.0S. С официального сайта нужно скачать файлы csr1000v-universalk9.03.15.00.S.155-2.S-std.iso и csr1000v-universalk9.03.15.00.S.155-2.S-std.ova По-моему, сейчас это самая поздняя версия CSR, доступная с аккаунтом Cisco, версии новее требуют различные партнерские отношения с Cisco. Зарегистрироваться можно по адресу. ...

<span title='2021-07-20 00:00:00 +0000 UTC'>July 20, 2021</span>