feat: initial commit of mini-paas engine and documentation

This commit is contained in:
2026-10-23 13:57:39 -03:00
commit e0e2201230
17 changed files with 2263 additions and 0 deletions

474
internal/ui/dashboard.html Normal file
View File

@@ -0,0 +1,474 @@
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mini PaaS Dashboard</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-base: #090d16;
--bg-card: #111827;
--bg-card-hover: #172033;
--border: #1f293d;
--text-main: #f3f4f6;
--text-muted: #9ca3af;
--primary: #3b82f6;
--primary-glow: rgba(59, 130, 246, 0.2);
--success: #10b981;
--warning: #f59e0b;
--danger: #ef4444;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Plus Jakarta Sans', sans-serif;
background-color: var(--bg-base);
color: var(--text-main);
min-height: 100vh;
padding: 2.5rem 1.5rem;
line-height: 1.5;
}
.container {
max-width: 1000px;
margin: 0 auto;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 2.5rem;
padding-bottom: 1.5rem;
border-bottom: 1px solid var(--border);
}
.logo-area h1 {
font-size: 1.75rem;
font-weight: 700;
display: flex;
align-items: center;
gap: 0.75rem;
letter-spacing: -0.02em;
}
.logo-badge {
background: linear-gradient(135deg, #2563eb, #3b82f6);
color: white;
font-size: 0.75rem;
padding: 0.2rem 0.6rem;
border-radius: 9999px;
text-transform: uppercase;
font-weight: 700;
letter-spacing: 0.05em;
}
.header-meta {
font-family: 'JetBrains Mono', monospace;
font-size: 0.85rem;
color: var(--text-muted);
background: #131c2e;
padding: 0.4rem 0.8rem;
border-radius: 6px;
border: 1px solid var(--border);
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
margin-bottom: 2rem;
}
.stat-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 12px;
padding: 1.25rem;
}
.stat-title {
font-size: 0.8rem;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.05em;
margin-bottom: 0.35rem;
}
.stat-value {
font-size: 1.75rem;
font-weight: 700;
font-family: 'JetBrains Mono', monospace;
}
.section-title {
font-size: 1.15rem;
font-weight: 600;
margin-bottom: 1rem;
display: flex;
align-items: center;
justify-content: space-between;
}
.apps-list {
display: grid;
gap: 1rem;
margin-bottom: 2.5rem;
}
.app-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 12px;
padding: 1.25rem 1.5rem;
display: flex;
align-items: center;
justify-content: space-between;
transition: all 0.2s ease;
}
.app-card:hover {
border-color: #2b3952;
background: var(--bg-card-hover);
}
.app-info {
display: flex;
align-items: center;
gap: 1.25rem;
}
.app-icon {
width: 44px;
height: 44px;
border-radius: 10px;
background: #1e293b;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.25rem;
}
.app-details h3 {
font-size: 1.1rem;
font-weight: 600;
margin-bottom: 0.2rem;
}
.app-meta {
font-family: 'JetBrains Mono', monospace;
font-size: 0.8rem;
color: var(--text-muted);
display: flex;
gap: 1rem;
}
.badge {
font-family: 'JetBrains Mono', monospace;
font-size: 0.72rem;
padding: 0.25rem 0.6rem;
border-radius: 9999px;
font-weight: 600;
display: inline-flex;
align-items: center;
gap: 0.35rem;
}
.badge-running {
background: rgba(16, 185, 129, 0.15);
color: #34d399;
border: 1px solid rgba(16, 185, 129, 0.3);
}
.badge-running::before {
content: '';
width: 6px;
height: 6px;
background: #34d399;
border-radius: 50%;
box-shadow: 0 0 6px #34d399;
}
.badge-starting {
background: rgba(245, 158, 11, 0.15);
color: #fbbf24;
border: 1px solid rgba(245, 158, 11, 0.3);
}
.badge-crashed {
background: rgba(239, 68, 68, 0.15);
color: #f87171;
border: 1px solid rgba(239, 68, 68, 0.3);
}
.app-actions {
display: flex;
align-items: center;
gap: 0.75rem;
}
.btn {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem 1rem;
border-radius: 8px;
font-size: 0.85rem;
font-weight: 500;
text-decoration: none;
cursor: pointer;
transition: all 0.15s ease;
border: 1px solid transparent;
}
.btn-primary {
background: var(--primary);
color: white;
}
.btn-primary:hover {
background: #2563eb;
}
.btn-secondary {
background: #1e293b;
color: var(--text-main);
border-color: var(--border);
}
.btn-secondary:hover {
background: #283548;
}
.empty-state {
text-align: center;
padding: 3.5rem 1.5rem;
background: var(--bg-card);
border: 1px dashed var(--border);
border-radius: 12px;
color: var(--text-muted);
}
.guide-box {
background: #0d131f;
border: 1px solid var(--border);
border-radius: 12px;
padding: 1.5rem;
}
.guide-box h4 {
font-size: 0.95rem;
margin-bottom: 0.75rem;
color: #93c5fd;
}
.guide-code {
background: #06090e;
padding: 0.85rem 1rem;
border-radius: 6px;
font-family: 'JetBrains Mono', monospace;
font-size: 0.82rem;
color: #e2e8f0;
overflow-x: auto;
margin-bottom: 0.75rem;
border: 1px solid #1a2233;
}
/* Modal Logs */
.modal-backdrop {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.75);
backdrop-filter: blur(4px);
z-index: 999;
align-items: center;
justify-content: center;
}
.modal {
background: #0d131f;
border: 1px solid var(--border);
border-radius: 12px;
width: 90%;
max-width: 800px;
max-height: 80vh;
display: flex;
flex-direction: column;
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}
.modal-header {
padding: 1rem 1.5rem;
border-bottom: 1px solid var(--border);
display: flex;
justify-content: space-between;
align-items: center;
}
.modal-header h3 {
font-size: 1.1rem;
font-family: 'JetBrains Mono', monospace;
}
.close-btn {
background: none;
border: none;
color: var(--text-muted);
font-size: 1.5rem;
cursor: pointer;
}
.modal-body {
padding: 1rem;
overflow-y: auto;
background: #06090e;
font-family: 'JetBrains Mono', monospace;
font-size: 0.8rem;
color: #38bdf8;
flex: 1;
white-space: pre-wrap;
line-height: 1.4;
}
</style>
</head>
<body>
<div class="container">
<header>
<div class="logo-area">
<h1>Mini PaaS <span class="logo-badge">Go Engine</span></h1>
</div>
<div class="header-meta">
Host: <strong>{{.Domain}}</strong>
</div>
</header>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-title">Aplicações Ativas</div>
<div class="stat-value" style="color: var(--success)">{{.ActiveCount}}</div>
</div>
<div class="stat-card">
<div class="stat-title">Porta do PaaS</div>
<div class="stat-value">{{.Port}}</div>
</div>
<div class="stat-card">
<div class="stat-title">Diretório de Apps</div>
<div class="stat-value" style="font-size: 1rem; padding-top: 0.5rem; word-break: break-all;">{{.AppsDir}}</div>
</div>
</div>
<div class="section-title">
<span>Aplicações Instaladas</span>
<button onclick="location.reload()" class="btn btn-secondary" style="font-size: 0.75rem; padding: 0.35rem 0.75rem;">Atualizar</button>
</div>
<div class="apps-list">
{{if not .Apps}}
<div class="empty-state">
<p style="font-size: 1.1rem; margin-bottom: 0.5rem; color: #fff;">Nenhum binário detectado em <code>{{.AppsDir}}</code></p>
<p>Crie uma subpasta (ex: <code>{{.AppsDir}}/page_teste</code>) e coloque um binário Go lá dentro.</p>
</div>
{{end}}
{{range .Apps}}
<div class="app-card">
<div class="app-info">
<div class="app-icon">📦</div>
<div class="app-details">
<h3>{{.Name}}</h3>
<div class="app-meta">
<span>Porta: <strong>:{{.Port}}</strong></span>
<span>PID: <strong>{{.PID}}</strong></span>
<span>Uptime: <strong>{{.Uptime}}</strong></span>
</div>
</div>
</div>
<div class="app-actions">
{{if eq .Status "RUNNING"}}
<span class="badge badge-running">RUNNING</span>
{{else if eq .Status "STARTING"}}
<span class="badge badge-starting">STARTING</span>
{{else}}
<span class="badge badge-crashed">CRASHED ({{.CrashCount}})</span>
{{end}}
<button onclick="viewLogs('{{.Name}}')" class="btn btn-secondary">Logs</button>
<a href="/{{.Name}}/" class="btn btn-primary" target="_blank">Acessar &rarr;</a>
</div>
</div>
{{end}}
</div>
<div class="guide-box">
<h4>Como subir uma nova aplicação Go?</h4>
<p style="font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.75rem;">
Compile seu binário para Linux 64-bit e coloque na pasta correspondente do volume no CasaOS:
</p>
<div class="guide-code">
# 1. Compilar para Linux
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app main.go
# 2. Criar a pasta do seu app dentro do volume do Mini PaaS
mkdir -p /DATA/AppData/mini-paas/apps/meu_app
# 3. Copiar o binário 'app' para lá (o Mini PaaS detectará automaticamente em ~3s)
cp app /DATA/AppData/mini-paas/apps/meu_app/
</div>
<p style="font-size: 0.82rem; color: var(--text-muted);">
Seu app deve escutar na variável de ambiente <code>PORT</code>: <code>http.ListenAndServe(":" + os.Getenv("PORT"), nil)</code>.
</p>
</div>
</div>
<!-- Modal Logs -->
<div id="modalLogs" class="modal-backdrop">
<div class="modal">
<div class="modal-header">
<h3 id="modalAppName">Logs da Aplicação</h3>
<button class="close-btn" onclick="closeLogs()">&times;</button>
</div>
<pre id="modalLogsContent" class="modal-body">Carregando logs...</pre>
</div>
</div>
<script>
function viewLogs(appName) {
document.getElementById('modalAppName').innerText = 'Logs: ' + appName;
document.getElementById('modalLogsContent').innerText = 'Carregando logs...';
document.getElementById('modalLogs').style.display = 'flex';
fetch('/_paas/api/logs?app=' + encodeURIComponent(appName))
.then(res => res.text())
.then(data => {
document.getElementById('modalLogsContent').innerText = data || '(Nenhum log registrado ainda)';
})
.catch(err => {
document.getElementById('modalLogsContent').innerText = 'Erro ao carregar logs: ' + err;
});
}
function closeLogs() {
document.getElementById('modalLogs').style.display = 'none';
}
window.onclick = function(event) {
const modal = document.getElementById('modalLogs');
if (event.target === modal) {
closeLogs();
}
};
</script>
</body>
</html>