File tree Expand file tree Collapse file tree 6 files changed +78
-0
lines changed
dockerfiles/graphviz-server Expand file tree Collapse file tree 6 files changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ services:
5
5
dockerfile : graphviz.Dockerfile
6
6
volumes :
7
7
- ../cache:/data
8
+ graphviz-server :
9
+ build :
10
+ context : ./dockerfiles/graphviz-server
11
+ dockerfile : Dockerfile
12
+ ports :
13
+ - 8080:8080
8
14
apache :
9
15
image : httpd:latest
10
16
volumes :
Original file line number Diff line number Diff line change
1
+ # Use an official Python runtime as a parent image
2
+ FROM python:3.10-slim
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Install graphviz
8
+ RUN apt-get update && apt-get install -y graphviz && rm -rf /var/lib/apt/lists/*
9
+
10
+ # Copy the current directory contents into the container at /app
11
+ COPY . /app
12
+
13
+ # Install any needed packages specified in requirements.txt
14
+ RUN pip install --no-cache-dir -r requirements.txt
15
+
16
+ # Define environment variable
17
+ ENV NAME World
18
+
19
+ # Run app.py when the container launches
20
+ CMD ["python" , "server.py" ]
Original file line number Diff line number Diff line change
1
+ Flask
2
+ graphviz
Original file line number Diff line number Diff line change
1
+ from flask import Flask , request , send_file
2
+ import graphviz
3
+
4
+ app = Flask (__name__ )
5
+
6
+ @app .route ('/graph' , methods = ['POST' ])
7
+ def graph ():
8
+ # Get the dot format graph from the request
9
+ dot_string = request .data .decode ()
10
+
11
+ try :
12
+ # Create a graph from the dot string
13
+ dot = graphviz .Source (dot_string )
14
+ # Render the graph to a file
15
+ output_path = '/tmp/graph'
16
+ dot .render (output_path , format = 'png' , cleanup = True )
17
+
18
+ # Send the file back
19
+ return send_file (output_path + '.png' , mimetype = 'image/png' )
20
+ except Exception as e :
21
+ return str (e ), 400
22
+
23
+ if __name__ == '__main__' :
24
+ app .run (debug = True , host = '0.0.0.0' , port = 8080 )
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ # URL of the graph endpoint
4
+ url = 'http://localhost:8080/graph'
5
+
6
+ # DOT language description of the graph
7
+ dot_text = """
8
+ digraph G {
9
+ A -> B;
10
+ B -> C;
11
+ C -> A;
12
+ }
13
+ """
14
+
15
+ # Send the DOT string as a POST request to the server
16
+ response = requests .post (url , data = dot_text )
17
+
18
+ # Check if the request was successful
19
+ if response .status_code == 200 :
20
+ # Save the image
21
+ with open ('output_graph.png' , 'wb' ) as f :
22
+ f .write (response .content )
23
+ print ("Graph image saved as 'output_graph.png'." )
24
+ else :
25
+ print ("Failed to generate graph:" , response .text )
Original file line number Diff line number Diff line change 1
1
pyyaml
2
2
networkx
3
+ requests
You can’t perform that action at this time.
0 commit comments