[PYTHON] I tried to draw a configuration diagram using Diagrams

Introduction

I used draw.io to draw the configuration diagram, but I heard that it can be drawn with code using a tool called diagrams, so I tried it.

environment

File structure

├── Dockerfile
└── test.py

Create a Docker image

Documentation has python3.6 or higher and Graphviz installed. Since there is, I created a Dockerfile like that. (I wanted to use alpine this time, so I created it with alpine.)

FROM python:3.8-alpine

WORKDIR /app
RUN apk add --update --no-cache \
    graphviz \
    ttf-freefont \
    curl \
    bash

#Add font
RUN curl -O https://noto-website.storage.googleapis.com/pkgs/NotoSansCJKjp-hinted.zip \
    && mkdir -p /usr/share/fonts/noto \
    && unzip NotoSansCJKjp-hinted.zip -d /usr/share/fonts/noto/ \
    && fc-cache -fv \
    && rm NotoSansCJKjp-hinted.zip

RUN pip install diagrams

After that, build the created Dockerfile. Feel free to tag! This time, let's call it diagrams.

$ docker build -t diagrams .

Prepare the file

Create the file by referring to the Official Document.

from diagrams import Cluster, Diagram
from diagrams.aws.compute import ECS
from diagrams.aws.database import ElastiCache, Aurora
from diagrams.aws.network import ELB
from diagrams.aws.network import Route53

with Diagram("Test", show=False):
    dns = Route53("dns")
    lb = ELB("ALB")
    api = ECS("API")
    redis = ElastiCache("redis")

    with Cluster("DB Cluster"):
        db_test = Aurora("test")
        db_test - [Aurora("test ro")]

    dns >> lb >> api
    api >> db_test
    api >> redis
    db_test >> redis

Output the configuration diagram

Since Docker is used this time, start the container as follows and execute the command.

docker run --rm -v `pwd`:/app diagrams python test.py

After execution, the png file will be added.

├── Dockerfile
├── test.png
└── test.py

Figure created

test.png

Finally

If you just draw a configuration diagram, draw.io is fine, but I think it's a good point to be able to manage it with Git as code. However, when I didn't have the image I wanted, or when I wanted to draw a complicated one (AZ, ECS task, etc.), it was difficult to use, so I think I'll try various things with future updates.

reference

-Draw a system configuration diagram in Python using Diagrams | Developers.IO

Recommended Posts

I tried to draw a configuration diagram using Diagrams
I tried to draw a system configuration diagram with Diagrams on Docker
I tried to draw a route map with Python
I tried to automate [a certain task] using Raspberry Pi
I tried to make a simple text editor using PyQt
I tried to create a linebot (implementation)
I tried using Azure Speech to Text.
I tried to get a database of horse racing using Pandas
I tried to create a linebot (preparation)
How to draw a graph using Matplotlib
I tried to make a regular expression of "amount" using Python
I tried playing a ○ ✕ game using TensorFlow
I tried to make a regular expression of "time" using Python
I tried to implement anomaly detection using a hidden Markov model
I tried to make a regular expression of "date" using Python
I tried to classify text using TensorFlow
I tried to get a list of AMI Names using Boto3
I tried to make a todo application using bottle with python
I tried to make a Web API
I tried using pipenv, so a memo
I tried Diagram as Code (Diagrams) which can manage the configuration diagram code
I tried to predict Covid-19 using Darts
I tried to perform a cluster analysis of customers using purchasing data
I tried to create a sample to access Salesforce using Python and Bottle
I tried to build a super-resolution method / ESPCN
I tried to build a super-resolution method / SRCNN ①
I tried to synthesize WAV files using Pydub.
I tried using Pythonect, a dataflow programming language.
I tried reading a CSV file using Python
I tried using a database (sqlite3) with kivy
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using anytree
I tried using aiomysql
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using openpyxl
I tried using Ipython
I tried to debug.
I tried using ngrok
I tried using face_recognition
I tried to paste
I tried using Jupyter
I tried using PyCaret
I tried using Heapq
I tried using doctest
I tried using folium
I tried using folium
I tried using time-window
[Python] Deep Learning: I tried to implement deep learning (DBN, SDA) without using a library.
I tried to make a translation BOT that works on Discord using googletrans
I tried to make a suspicious person MAP quickly using Geolonia address data
Draw a graph in Julia ... I tried a little analysis
I tried to make a "fucking big literary converter"
I tried to create a table only with Django
I tried to implement a pseudo pachislot in Python