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.
├── Dockerfile
└── test.py
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 .
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
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
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.
-Draw a system configuration diagram in Python using Diagrams | Developers.IO
Recommended Posts