prole/installer/ui/screens/gitops.py
chrisfu 5e0a1bda85 feat: Add GitOps (Gitea) and Supabase integration, plus database options
- Makefile: Added 'init' and 'deploy' targets for k3s parity and Gitea staging.

- OpenTofu: Fixed namespace handling in k3s main.tf to prevent metadata overwrites.

- UI: Added 'GitOps' and 'Database Options' configuration screens.

- Core: Enhanced monitoring, milestones, and environment handling for new services.

- Supabase: Integrated full Helm chart and manifest rendering logic.

- Gitea: Added deployment scripts and GitOps sync support.

- Database: Added Percona/Postgres Dockerfile templates and improved TDE scripts.

- Tests: Added coverage for new UI screens and navigation flows.
2026-02-26 18:32:15 -08:00

301 lines
10 KiB
Python

"""GitOps (Gitea) configuration and deployment screen."""
from __future__ import annotations
import os
import subprocess
import threading
import tkinter as tk
from installer import screen as ui
from installer.core.env import PROJECT_ROOT, _normalize_cluster_env, _parse_bool
class GitOpsScreenMixin:
"""GitOps / Gitea deployment screen."""
def _render_gitops_config_page(self):
content_width = self.bg_canvas.winfo_width() or 975
right_margin = content_width - 48
ui.canvas_text(
self,
right_margin,
40,
"Prole",
fill="#6e6e73",
font=("SF Pro Text", 32, "bold"),
anchor="ne",
)
ui.canvas_text(
self,
right_margin,
85,
"Infrastructure Automated.",
fill="#6e6e73",
font=("SF Pro Text", 18),
anchor="ne",
)
self._render_title("GitOps / Gitea", y=150)
description = (
"Deploys self-hosted GitOps (Gitea) via etc/init_gitea.sh.\n"
"Defaults to the 'gitea' namespace; update below to override."
)
self._render_paragraph(description, y=210)
enable_cb = tk.Checkbutton(
self.bg_canvas,
text="Enable GitOps (Gitea)",
variable=self.gitops_enabled,
command=self._on_gitops_toggle,
bg="white",
fg="black",
activebackground="white",
selectcolor="white",
font=("SF Pro Text", 11),
)
enable_window = self.bg_canvas.create_window(
48, 250, window=enable_cb, anchor="nw"
)
self._canvas_items.append(enable_window)
self._overlay_widgets.append(enable_cb)
# Namespace input
ui.canvas_text(
self,
48,
290,
"Kubernetes Namespace",
fill="black",
font=("SF Pro Text", 12, "bold"),
)
ns_entry = tk.Entry(
self.bg_canvas,
textvariable=self.gitops_namespace,
bg="white",
fg="black",
insertbackground="black",
highlightbackground="#CCCCCC",
highlightthickness=1,
relief="flat",
font=("SF Pro Text", 11),
)
ns_window = self.bg_canvas.create_window(
48, 315, window=ns_entry, anchor="nw", width=220, height=30
)
self._canvas_items.append(ns_window)
self._overlay_widgets.append(ns_entry)
y = 360
initial_status = "Ready" if self.gitops_enabled.get() else "Disabled"
self._gitops_status_var = tk.StringVar(value=initial_status)
status_item = ui.canvas_text(
self,
48,
y,
f"Status: {initial_status}",
fill="black",
font=("SF Pro Text", 12),
)
def update_status_text(*_):
try:
self.bg_canvas.itemconfig(
status_item, text=f"Status: {self._gitops_status_var.get()}"
)
except Exception:
pass
self._gitops_status_var.trace_add("write", update_status_text)
# Console output
self._gitops_console = self._create_console_output(
y=400, title="Deployment Output", width=880, height=330
)
# Deploy button
self._gitops_deploy_button = tk.Button(
self.bg_canvas,
text="Deploy Gitea",
command=self.run_gitops_deploy,
bg="#F5F5DC",
fg="black",
activebackground="#E5E5D5",
activeforeground="black",
highlightbackground="#F5F5DC",
highlightcolor="#F5F5DC",
highlightthickness=0,
relief="flat",
bd=0,
cursor="hand2",
disabledforeground="#8B8B7A",
font=("SF Pro Text", 11),
padx=20,
pady=10,
)
btn_window = self.bg_canvas.create_window(
48, 760, window=self._gitops_deploy_button, anchor="nw"
)
self._overlay_widgets.append(self._gitops_deploy_button)
self._canvas_items.append(btn_window)
def run_gitops_deploy(self):
if getattr(self, "_gitops_deploying", False):
return
if not self.gitops_enabled.get():
self._gitops_status_var.set("Disabled")
self.update_footer()
return
self._gitops_deploying = True
self._gitops_deploy_button.configure(state="disabled")
self._gitops_status_var.set("Deploying...")
self._gitops_success = False
self._gitops_console.clear()
self.update_footer()
def worker():
namespace = (
(self.gitops_namespace.get() or "").strip()
or os.environ.get("GITEA_NAMESPACE")
or "gitea"
)
env = os.environ.copy()
env["PROLE_HOME"] = str(PROJECT_ROOT)
env["PROLE_SERVICE"] = str(PROJECT_ROOT)
env["NAMESPACE"] = namespace
env["GITEA_NAMESPACE"] = namespace
self._gitops_console.write("Starting Gitea deployment...\n")
script_path = PROJECT_ROOT / "etc" / "init_gitea.sh"
if not script_path.exists():
self._gitops_console.write(f"Error: {script_path} not found.\n")
self.safe_after(
lambda: self._gitops_status_var.set("Failed (Script not found)")
)
self.safe_after(
lambda: self._gitops_deploy_button.configure(state="normal")
)
self._gitops_deploying = False
return
mode = (os.environ.get("PROLE_MODE") or "").strip()
if not mode:
cluster_env = _normalize_cluster_env(self.cluster_env.get())
if cluster_env == "dev":
mode = "k3d"
elif cluster_env in ("service", "prod"):
mode = "k3s" if cluster_env == "service" else "k8s"
else:
mode = "k3d"
args = ["--mode", mode, "--namespace", namespace]
cfg_path = None
try:
if self._cfg_path_override and self._cfg_path_override.exists():
cfg_path = self._cfg_path_override
else:
conf_dir = self._resolve_prole_conf_dir()
candidate = conf_dir / "prole.cfg"
if candidate.exists():
cfg_path = candidate
if not cfg_path:
candidate = PROJECT_ROOT / "conf" / "prole.cfg"
if candidate.exists():
cfg_path = candidate
except Exception:
cfg_path = None
if cfg_path:
args.extend(["-c", str(cfg_path)])
if _parse_bool(os.environ.get("GITEA_FOREGROUND"), False):
args.append("--foreground")
self._gitops_console.write(f"Mode: {mode}\n")
cmd = ["bash", str(script_path)] + args
try:
proc = subprocess.Popen(
cmd,
cwd=str(PROJECT_ROOT),
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
)
except Exception as e:
self._gitops_console.write(f"Failed to start deploy: {e}\n")
self.safe_after(
lambda: self._gitops_status_var.set("Failed (Launch error)")
)
self.safe_after(
lambda: self._gitops_deploy_button.configure(state="normal")
)
self._gitops_deploying = False
return
if proc.stdout:
for line in iter(proc.stdout.readline, ""):
if line:
self._gitops_console.write(line)
proc.stdout.close()
rc = proc.wait()
if rc == 0:
self._gitops_success = True
self.safe_after(
lambda: self._gitops_status_var.set("Deployed Successfully")
)
self._gitops_console.write(
"\nGitOps deployment completed successfully.\n"
)
else:
self._gitops_success = False
self.safe_after(
lambda: self._gitops_status_var.set(f"Failed (Code {rc})")
)
self._gitops_console.write(
f"\nGitOps deployment failed with exit code {rc}.\n"
)
self._gitops_deploying = False
self.safe_after(
lambda: self._gitops_deploy_button.configure(state="normal")
)
self.safe_after(self.update_footer)
threading.Thread(target=worker, daemon=True).start()
def _on_gitops_toggle(self):
enabled = self.gitops_enabled.get()
try:
self.prole_cfg_data["Optional Features"]["GITOPS_ENABLED"] = str(enabled)
self._save_prole_cfg()
except Exception:
pass
if not enabled:
self._gitops_success = False
if hasattr(self, "_gitops_status_var"):
self._gitops_status_var.set("Disabled")
try:
self._gitops_console.write("GitOps disabled. Deployment skipped.\n")
except Exception:
pass
self.update_footer()
return
if hasattr(self, "_gitops_status_var"):
self._gitops_status_var.set("Enabled")
try:
self._gitops_console.clear()
self._gitops_console.write("GitOps enabled. Starting deployment...\n")
except Exception:
pass
self.update_footer()
self.safe_after(self.run_gitops_deploy)