mirror of
https://github.com/philippemerle/KubeDiagrams.git
synced 2026-08-22 14:36:24 +00:00
fix(webapp): update dependencies and simplify draw.io support
This commit is contained in:
+7
-7
@@ -432,18 +432,18 @@ python3 app.py # Start Flask server in debug mode
|
||||
### Technologies Used
|
||||
|
||||
**Backend**:
|
||||
- Flask 3.1.2 - Web framework
|
||||
- Gunicorn 23.0.0 - WSGI server
|
||||
- KubeDiagrams 0.6.0 - Diagram generation
|
||||
- PyYAML 6.0.2 - YAML parsing
|
||||
- Flask 3.1.3 - Web framework
|
||||
- Gunicorn 26.0.0 - WSGI server
|
||||
- KubeDiagrams (main) - Diagram generation
|
||||
- PyYAML 6.0.3 - YAML parsing
|
||||
- Werkzeug 3.1.6 - WSGI utilities
|
||||
|
||||
**Frontend**:
|
||||
- React 19.1.0 - UI framework
|
||||
- Vite 6.3.5 - Build tool
|
||||
- TailwindCSS 4.1.6 - Styling
|
||||
- Lucide React - Icons
|
||||
- Motion - Animations
|
||||
|
||||
- Lucide React 0.552.0 - Icons
|
||||
- Motion 12.11.4 - Animations
|
||||
---
|
||||
|
||||
## Contributing
|
||||
|
||||
@@ -4,11 +4,10 @@ click==8.2.1
|
||||
diagrams==0.25.1
|
||||
distlib==0.4.0
|
||||
filelock==3.25.2
|
||||
Flask==3.1.2
|
||||
Flask==3.1.3
|
||||
flask-cors==6.0.1
|
||||
graphviz==0.20.3
|
||||
graphviz2drawio==1.1.0
|
||||
gunicorn==23.0.0
|
||||
gunicorn==26.0.0
|
||||
identify==2.6.17
|
||||
itsdangerous==2.2.0
|
||||
Jinja2==3.1.6
|
||||
@@ -23,4 +22,4 @@ python-discovery==1.1.3
|
||||
PyYAML==6.0.3
|
||||
svg.path==7.0
|
||||
virtualenv==21.2.0
|
||||
Werkzeug==3.1.3
|
||||
Werkzeug==3.1.6
|
||||
|
||||
@@ -3,13 +3,12 @@ import subprocess
|
||||
import os
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from graphviz2drawio.graphviz2drawio import convert as drawio_convert
|
||||
|
||||
from constants import MIME_TYPES
|
||||
from .models import DiagramResult
|
||||
from .file_manager import FileManager
|
||||
from .utils import parse_extra_args, has_fatal_error, encode_content
|
||||
|
||||
|
||||
def generate_from_helm(
|
||||
chart_url: str,
|
||||
output_format: str = "png",
|
||||
@@ -29,49 +28,11 @@ def generate_from_helm(
|
||||
# Extraction du nom de base
|
||||
parsed = urlparse(chart_url)
|
||||
base_name = os.path.basename(parsed.path).replace(".tgz", "").replace(".tar.gz", "")
|
||||
|
||||
|
||||
# Pour les URLs OCI
|
||||
if chart_url.startswith('oci://'):
|
||||
base_name = chart_url.rstrip('/').split('/')[-1]
|
||||
|
||||
# draw.io: generate .dot first, then convert via graphviz2drawio
|
||||
if output_format == "drawio":
|
||||
dot_output = os.path.abspath(f"{base_name}.dot")
|
||||
try:
|
||||
cmd = ["helm-diagrams", chart_url, "-o", f"{base_name}.dot"]
|
||||
if extra_args.strip():
|
||||
cmd.extend(parse_extra_args(extra_args))
|
||||
proc = subprocess.run(cmd, check=False, capture_output=True, text=True)
|
||||
stdout_output = proc.stdout or ""
|
||||
stderr_output = proc.stderr or ""
|
||||
has_error = proc.returncode != 0 or has_fatal_error(stdout_output, stderr_output)
|
||||
if "Error:" in stderr_output or "execution error" in stderr_output.lower():
|
||||
has_error = True
|
||||
if has_error:
|
||||
FileManager.cleanup_files(dot_output)
|
||||
return DiagramResult(
|
||||
success=False, error="helm-diagrams failed to generate the diagram.",
|
||||
command=" ".join(cmd), stdout=stdout_output, stderr=stderr_output
|
||||
)
|
||||
drawio_xml = drawio_convert(dot_output)
|
||||
FileManager.cleanup_files(dot_output)
|
||||
return DiagramResult(
|
||||
success=True,
|
||||
diagram=drawio_xml,
|
||||
mime_type=MIME_TYPES.get("drawio", "application/xml"),
|
||||
filename=f"{base_name}.drawio",
|
||||
message="Helm diagram successfully generated.",
|
||||
command=" ".join(cmd),
|
||||
stdout=stdout_output,
|
||||
stderr=stderr_output
|
||||
)
|
||||
except Exception as e:
|
||||
FileManager.cleanup_files(dot_output)
|
||||
return DiagramResult(
|
||||
success=False, error=f"draw.io conversion failed: {e}",
|
||||
command=" ".join(cmd) if 'cmd' in locals() else None
|
||||
)
|
||||
|
||||
requested_output = os.path.abspath(f"{base_name}.{output_format}")
|
||||
png_output = os.path.abspath(f"{base_name}.png")
|
||||
|
||||
@@ -173,3 +134,4 @@ def generate_from_helm(
|
||||
error=f"Internal error: {e}",
|
||||
command=" ".join(cmd) if 'cmd' in locals() else None
|
||||
)
|
||||
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
from graphviz2drawio.graphviz2drawio import convert as drawio_convert
|
||||
|
||||
from constants import MIME_TYPES
|
||||
from .models import DiagramResult
|
||||
from .file_manager import FileManager
|
||||
from .utils import parse_extra_args, has_fatal_error, encode_content
|
||||
|
||||
|
||||
def generate_from_helmfile(
|
||||
helmfile_content: str,
|
||||
output_format: str = "png",
|
||||
@@ -28,9 +27,7 @@ def generate_from_helmfile(
|
||||
DiagramResult: Result of the generation
|
||||
"""
|
||||
with FileManager.create_temp_file(helmfile_content, suffix=".yaml", mode='wb') as temp_helmfile_path:
|
||||
is_drawio = output_format == "drawio"
|
||||
actual_format = "dot" if is_drawio else output_format
|
||||
output_path = temp_helmfile_path + f".{actual_format}"
|
||||
output_path = temp_helmfile_path + f".{output_format}"
|
||||
|
||||
try:
|
||||
# Command helmfile template
|
||||
@@ -91,20 +88,6 @@ def generate_from_helmfile(
|
||||
stderr=stderr_output
|
||||
)
|
||||
|
||||
if is_drawio:
|
||||
drawio_xml = drawio_convert(output_path)
|
||||
FileManager.cleanup_files(output_path)
|
||||
return DiagramResult(
|
||||
success=True,
|
||||
diagram=drawio_xml,
|
||||
mime_type=MIME_TYPES.get("drawio", "application/xml"),
|
||||
filename="helmfile-diagram.drawio",
|
||||
message="Helmfile diagram successfully generated.",
|
||||
command=f"{' '.join(template_cmd)} | {' '.join(cmd)}",
|
||||
stdout=stdout_output,
|
||||
stderr=stderr_output
|
||||
)
|
||||
|
||||
content = FileManager.read_file_content(output_path, binary=True)
|
||||
encoded = encode_content(content, output_format)
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
"""Service for generating diagrams from Kubernetes manifests."""
|
||||
import subprocess
|
||||
|
||||
from graphviz2drawio.graphviz2drawio import convert as drawio_convert
|
||||
|
||||
from constants import MIME_TYPES
|
||||
from .models import DiagramResult
|
||||
from .file_manager import FileManager
|
||||
from .utils import parse_extra_args, has_fatal_error, encode_content
|
||||
|
||||
|
||||
def generate_from_manifest(
|
||||
manifest_content: str,
|
||||
output_format: str = "png",
|
||||
@@ -29,50 +28,8 @@ def generate_from_manifest(
|
||||
with FileManager.create_temp_file(manifest_content, suffix='.yaml') as tmp_manifest:
|
||||
base_name = FileManager.get_base_name_from_path(tmp_manifest)
|
||||
|
||||
# draw.io: generate .dot first, then convert via graphviz2drawio
|
||||
if output_format == "drawio":
|
||||
dot_output, _ = FileManager.get_output_paths(tmp_manifest, "dot")
|
||||
drawio_output, _ = FileManager.get_output_paths(tmp_manifest, "drawio")
|
||||
try:
|
||||
cmd = ["kube-diagrams", tmp_manifest, "-o", dot_output]
|
||||
if without_namespace:
|
||||
cmd.append("--without-namespace")
|
||||
if extra_args.strip():
|
||||
cmd.extend(parse_extra_args(extra_args))
|
||||
proc = subprocess.run(cmd, check=False, capture_output=True, text=True)
|
||||
stdout_output = proc.stdout or ""
|
||||
stderr_output = proc.stderr or ""
|
||||
if proc.returncode != 0 or has_fatal_error(stdout_output, stderr_output):
|
||||
FileManager.cleanup_files(dot_output)
|
||||
return DiagramResult(
|
||||
success=False,
|
||||
error="KubeDiagrams failed. See command output below.",
|
||||
command=" ".join(cmd),
|
||||
stdout=stdout_output,
|
||||
stderr=stderr_output
|
||||
)
|
||||
drawio_xml = drawio_convert(dot_output)
|
||||
FileManager.cleanup_files(dot_output)
|
||||
return DiagramResult(
|
||||
success=True,
|
||||
diagram=drawio_xml,
|
||||
mime_type=MIME_TYPES.get("drawio", "application/xml"),
|
||||
filename=f"{base_name}.drawio",
|
||||
message="Diagram successfully generated.",
|
||||
command=" ".join(cmd),
|
||||
stdout=stdout_output,
|
||||
stderr=stderr_output
|
||||
)
|
||||
except Exception as e:
|
||||
FileManager.cleanup_files(dot_output)
|
||||
return DiagramResult(
|
||||
success=False,
|
||||
error=f"draw.io conversion failed: {e}",
|
||||
command=" ".join(cmd) if 'cmd' in locals() else None
|
||||
)
|
||||
|
||||
requested_output, png_output = FileManager.get_output_paths(tmp_manifest, output_format)
|
||||
|
||||
|
||||
try:
|
||||
# Command
|
||||
cmd = ["kube-diagrams", tmp_manifest, "-o", requested_output]
|
||||
@@ -140,3 +97,4 @@ def generate_from_manifest(
|
||||
error=f"Internal error: {e}",
|
||||
command=" ".join(cmd) if 'cmd' in locals() else None
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user