Initial commit with server startup infrastructure
Core infrastructure: - Uber fx dependency injection - Chi router with middleware stack - SQLite database with embedded migrations - Embedded templates and static assets - Structured logging with slog Features implemented: - Authentication (login, logout, session management, argon2id hashing) - App management (create, edit, delete, list) - Deployment pipeline (clone, build, deploy, health check) - Webhook processing for Gitea - Notifications (ntfy, Slack) - Environment variables, labels, volumes per app - SSH key generation for deploy keys Server startup: - Server.Run() starts HTTP server on configured port - Server.Shutdown() for graceful shutdown - SetupRoutes() wires all handlers with chi router
This commit is contained in:
265
templates/app_detail.html
Normal file
265
templates/app_detail.html
Normal file
@@ -0,0 +1,265 @@
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "title"}}{{.App.Name}} - upaas{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{template "nav" .}}
|
||||
|
||||
<main class="max-w-4xl mx-auto px-4 py-8">
|
||||
<div class="mb-6">
|
||||
<a href="/" class="text-primary-600 hover:text-primary-800 inline-flex items-center">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
|
||||
</svg>
|
||||
Back to Dashboard
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{template "alert-success" .}}
|
||||
{{template "alert-error" .}}
|
||||
|
||||
<!-- Header -->
|
||||
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8">
|
||||
<div>
|
||||
<div class="flex items-center gap-3">
|
||||
<h1 class="text-2xl font-medium text-gray-900">{{.App.Name}}</h1>
|
||||
{{if eq .App.Status "running"}}
|
||||
<span class="badge-success">Running</span>
|
||||
{{else if eq .App.Status "building"}}
|
||||
<span class="badge-warning">Building</span>
|
||||
{{else if eq .App.Status "error"}}
|
||||
<span class="badge-error">Error</span>
|
||||
{{else if eq .App.Status "stopped"}}
|
||||
<span class="badge-neutral">Stopped</span>
|
||||
{{else}}
|
||||
<span class="badge-neutral">{{.App.Status}}</span>
|
||||
{{end}}
|
||||
</div>
|
||||
<p class="text-gray-500 font-mono text-sm mt-1">{{.App.RepoURL}} @ {{.App.Branch}}</p>
|
||||
</div>
|
||||
<div class="flex gap-3">
|
||||
<a href="/apps/{{.App.ID}}/edit" class="btn-secondary">Edit</a>
|
||||
<form method="POST" action="/apps/{{.App.ID}}/deploy" class="inline">
|
||||
<button type="submit" class="btn-success">Deploy Now</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Deploy Key -->
|
||||
<div class="card p-6 mb-6">
|
||||
<h2 class="section-title mb-4">Deploy Key</h2>
|
||||
<p class="text-sm text-gray-500 mb-3">Add this SSH public key to your repository as a read-only deploy key:</p>
|
||||
<div class="copy-field">
|
||||
<code id="deploy-key" class="copy-field-value text-xs">{{.App.SSHPublicKey}}</code>
|
||||
<button
|
||||
type="button"
|
||||
data-copy-target="deploy-key"
|
||||
class="copy-btn"
|
||||
title="Copy to clipboard"
|
||||
>
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Webhook URL -->
|
||||
<div class="card p-6 mb-6">
|
||||
<h2 class="section-title mb-4">Webhook URL</h2>
|
||||
<p class="text-sm text-gray-500 mb-3">Add this URL as a push webhook in your Gitea repository:</p>
|
||||
<div class="copy-field">
|
||||
<code id="webhook-url" class="copy-field-value text-xs">{{.WebhookURL}}</code>
|
||||
<button
|
||||
type="button"
|
||||
data-copy-target="webhook-url"
|
||||
class="copy-btn"
|
||||
title="Copy to clipboard"
|
||||
>
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Environment Variables -->
|
||||
<div class="card p-6 mb-6">
|
||||
<h2 class="section-title mb-4">Environment Variables</h2>
|
||||
{{if .EnvVars}}
|
||||
<div class="overflow-x-auto mb-4">
|
||||
<table class="table">
|
||||
<thead class="table-header">
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Value</th>
|
||||
<th class="text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-body">
|
||||
{{range .EnvVars}}
|
||||
<tr>
|
||||
<td class="font-mono font-medium">{{.Key}}</td>
|
||||
<td class="font-mono text-gray-500">{{.Value}}</td>
|
||||
<td class="text-right">
|
||||
<form method="POST" action="/apps/{{$.App.ID}}/env/{{.ID}}/delete" class="inline" data-confirm="Delete this environment variable?">
|
||||
<button type="submit" class="text-error-500 hover:text-error-700 text-sm">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{end}}
|
||||
<form method="POST" action="/apps/{{.App.ID}}/env" class="flex flex-col sm:flex-row gap-2">
|
||||
<input type="text" name="key" placeholder="KEY" required class="input flex-1 font-mono text-sm">
|
||||
<input type="text" name="value" placeholder="value" required class="input flex-1 font-mono text-sm">
|
||||
<button type="submit" class="btn-primary">Add</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Labels -->
|
||||
<div class="card p-6 mb-6">
|
||||
<h2 class="section-title mb-4">Docker Labels</h2>
|
||||
{{if .Labels}}
|
||||
<div class="overflow-x-auto mb-4">
|
||||
<table class="table">
|
||||
<thead class="table-header">
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Value</th>
|
||||
<th class="text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-body">
|
||||
{{range .Labels}}
|
||||
<tr>
|
||||
<td class="font-mono font-medium">{{.Key}}</td>
|
||||
<td class="font-mono text-gray-500">{{.Value}}</td>
|
||||
<td class="text-right">
|
||||
<form method="POST" action="/apps/{{$.App.ID}}/labels/{{.ID}}/delete" class="inline" data-confirm="Delete this label?">
|
||||
<button type="submit" class="text-error-500 hover:text-error-700 text-sm">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{end}}
|
||||
<form method="POST" action="/apps/{{.App.ID}}/labels" class="flex flex-col sm:flex-row gap-2">
|
||||
<input type="text" name="key" placeholder="label.key" required class="input flex-1 font-mono text-sm">
|
||||
<input type="text" name="value" placeholder="value" required class="input flex-1 font-mono text-sm">
|
||||
<button type="submit" class="btn-primary">Add</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Volumes -->
|
||||
<div class="card p-6 mb-6">
|
||||
<h2 class="section-title mb-4">Volume Mounts</h2>
|
||||
{{if .Volumes}}
|
||||
<div class="overflow-x-auto mb-4">
|
||||
<table class="table">
|
||||
<thead class="table-header">
|
||||
<tr>
|
||||
<th>Host Path</th>
|
||||
<th>Container Path</th>
|
||||
<th>Mode</th>
|
||||
<th class="text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-body">
|
||||
{{range .Volumes}}
|
||||
<tr>
|
||||
<td class="font-mono">{{.HostPath}}</td>
|
||||
<td class="font-mono">{{.ContainerPath}}</td>
|
||||
<td>
|
||||
{{if .ReadOnly}}
|
||||
<span class="badge-neutral">Read-only</span>
|
||||
{{else}}
|
||||
<span class="badge-info">Read-write</span>
|
||||
{{end}}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<form method="POST" action="/apps/{{$.App.ID}}/volumes/{{.ID}}/delete" class="inline" data-confirm="Delete this volume mount?">
|
||||
<button type="submit" class="text-error-500 hover:text-error-700 text-sm">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{end}}
|
||||
<form method="POST" action="/apps/{{.App.ID}}/volumes" class="flex flex-col sm:flex-row gap-2 items-end">
|
||||
<div class="flex-1 w-full">
|
||||
<input type="text" name="host_path" placeholder="/host/path" required class="input font-mono text-sm">
|
||||
</div>
|
||||
<div class="flex-1 w-full">
|
||||
<input type="text" name="container_path" placeholder="/container/path" required class="input font-mono text-sm">
|
||||
</div>
|
||||
<label class="flex items-center gap-2 text-sm text-gray-600 whitespace-nowrap">
|
||||
<input type="checkbox" name="readonly" value="1" class="rounded border-gray-300 text-primary-600 focus:ring-primary-500">
|
||||
Read-only
|
||||
</label>
|
||||
<button type="submit" class="btn-primary">Add</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Recent Deployments -->
|
||||
<div class="card p-6 mb-6">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h2 class="section-title">Recent Deployments</h2>
|
||||
<a href="/apps/{{.App.ID}}/deployments" class="text-primary-600 hover:text-primary-800 text-sm">View All</a>
|
||||
</div>
|
||||
{{if .Deployments}}
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table">
|
||||
<thead class="table-header">
|
||||
<tr>
|
||||
<th>Started</th>
|
||||
<th>Status</th>
|
||||
<th>Commit</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-body">
|
||||
{{range .Deployments}}
|
||||
<tr>
|
||||
<td class="text-gray-500">{{.StartedAt.Format "2006-01-02 15:04:05"}}</td>
|
||||
<td>
|
||||
{{if eq .Status "success"}}
|
||||
<span class="badge-success">Success</span>
|
||||
{{else if eq .Status "failed"}}
|
||||
<span class="badge-error">Failed</span>
|
||||
{{else if eq .Status "building"}}
|
||||
<span class="badge-warning">Building</span>
|
||||
{{else if eq .Status "deploying"}}
|
||||
<span class="badge-info">Deploying</span>
|
||||
{{else}}
|
||||
<span class="badge-neutral">{{.Status}}</span>
|
||||
{{end}}
|
||||
</td>
|
||||
<td class="font-mono text-gray-500 text-xs">
|
||||
{{if .CommitSHA.Valid}}{{slice .CommitSHA.String 0 12}}{{else}}-{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{else}}
|
||||
<p class="text-gray-500 text-sm">No deployments yet.</p>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
<!-- Danger Zone -->
|
||||
<div class="card border-2 border-error-500/20 bg-error-50/50 p-6">
|
||||
<h2 class="text-lg font-medium text-error-700 mb-4">Danger Zone</h2>
|
||||
<p class="text-error-600 text-sm mb-4">Deleting this app will remove all configuration and deployment history. This action cannot be undone.</p>
|
||||
<form method="POST" action="/apps/{{.App.ID}}/delete" data-confirm="Are you sure you want to delete this app? This action cannot be undone.">
|
||||
<button type="submit" class="btn-danger">Delete App</button>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
{{end}}
|
||||
123
templates/app_edit.html
Normal file
123
templates/app_edit.html
Normal file
@@ -0,0 +1,123 @@
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "title"}}Edit {{.App.Name}} - upaas{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{template "nav" .}}
|
||||
|
||||
<main class="max-w-2xl mx-auto px-4 py-8">
|
||||
<div class="mb-6">
|
||||
<a href="/apps/{{.App.ID}}" class="text-primary-600 hover:text-primary-800 inline-flex items-center">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
|
||||
</svg>
|
||||
Back to {{.App.Name}}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<h1 class="text-2xl font-medium text-gray-900 mb-6">Edit Application</h1>
|
||||
|
||||
<div class="card p-6">
|
||||
{{template "alert-error" .}}
|
||||
|
||||
<form method="POST" action="/apps/{{.App.ID}}" class="space-y-6">
|
||||
<div class="form-group">
|
||||
<label for="name" class="label">App Name</label>
|
||||
<input
|
||||
type="text"
|
||||
id="name"
|
||||
name="name"
|
||||
value="{{.App.Name}}"
|
||||
required
|
||||
pattern="[a-z0-9-]+"
|
||||
class="input"
|
||||
>
|
||||
<p class="text-sm text-gray-500 mt-1">Lowercase letters, numbers, and hyphens only</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="repo_url" class="label">Repository URL (SSH)</label>
|
||||
<input
|
||||
type="text"
|
||||
id="repo_url"
|
||||
name="repo_url"
|
||||
value="{{.App.RepoURL}}"
|
||||
required
|
||||
class="input font-mono"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div class="form-group">
|
||||
<label for="branch" class="label">Branch</label>
|
||||
<input
|
||||
type="text"
|
||||
id="branch"
|
||||
name="branch"
|
||||
value="{{.App.Branch}}"
|
||||
required
|
||||
class="input"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="dockerfile_path" class="label">Dockerfile Path</label>
|
||||
<input
|
||||
type="text"
|
||||
id="dockerfile_path"
|
||||
name="dockerfile_path"
|
||||
value="{{.App.DockerfilePath}}"
|
||||
required
|
||||
class="input"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="border-gray-200">
|
||||
|
||||
<h3 class="text-lg font-medium text-gray-900">Optional Settings</h3>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="docker_network" class="label">Docker Network</label>
|
||||
<input
|
||||
type="text"
|
||||
id="docker_network"
|
||||
name="docker_network"
|
||||
value="{{if .App.DockerNetwork.Valid}}{{.App.DockerNetwork.String}}{{end}}"
|
||||
class="input"
|
||||
placeholder="bridge"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="ntfy_topic" class="label">Ntfy Topic URL</label>
|
||||
<input
|
||||
type="url"
|
||||
id="ntfy_topic"
|
||||
name="ntfy_topic"
|
||||
value="{{if .App.NtfyTopic.Valid}}{{.App.NtfyTopic.String}}{{end}}"
|
||||
class="input"
|
||||
placeholder="https://ntfy.sh/my-topic"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="slack_webhook" class="label">Slack Webhook URL</label>
|
||||
<input
|
||||
type="url"
|
||||
id="slack_webhook"
|
||||
name="slack_webhook"
|
||||
value="{{if .App.SlackWebhook.Valid}}{{.App.SlackWebhook.String}}{{end}}"
|
||||
class="input"
|
||||
placeholder="https://hooks.slack.com/services/..."
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-3 pt-4">
|
||||
<a href="/apps/{{.App.ID}}" class="btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn-primary">Save Changes</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
{{end}}
|
||||
126
templates/app_new.html
Normal file
126
templates/app_new.html
Normal file
@@ -0,0 +1,126 @@
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "title"}}New App - upaas{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{template "nav" .}}
|
||||
|
||||
<main class="max-w-2xl mx-auto px-4 py-8">
|
||||
<div class="mb-6">
|
||||
<a href="/" class="text-primary-600 hover:text-primary-800 inline-flex items-center">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
|
||||
</svg>
|
||||
Back to Dashboard
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<h1 class="text-2xl font-medium text-gray-900 mb-6">Create New Application</h1>
|
||||
|
||||
<div class="card p-6">
|
||||
{{template "alert-error" .}}
|
||||
|
||||
<form method="POST" action="/apps" class="space-y-6">
|
||||
<div class="form-group">
|
||||
<label for="name" class="label">App Name</label>
|
||||
<input
|
||||
type="text"
|
||||
id="name"
|
||||
name="name"
|
||||
value="{{.Name}}"
|
||||
required
|
||||
pattern="[a-z0-9-]+"
|
||||
class="input"
|
||||
placeholder="my-app"
|
||||
>
|
||||
<p class="text-sm text-gray-500 mt-1">Lowercase letters, numbers, and hyphens only</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="repo_url" class="label">Repository URL (SSH)</label>
|
||||
<input
|
||||
type="text"
|
||||
id="repo_url"
|
||||
name="repo_url"
|
||||
value="{{.RepoURL}}"
|
||||
required
|
||||
class="input font-mono"
|
||||
placeholder="git@gitea.example.com:user/repo.git"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div class="form-group">
|
||||
<label for="branch" class="label">Branch</label>
|
||||
<input
|
||||
type="text"
|
||||
id="branch"
|
||||
name="branch"
|
||||
value="{{if .Branch}}{{.Branch}}{{else}}main{{end}}"
|
||||
class="input"
|
||||
placeholder="main"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="dockerfile_path" class="label">Dockerfile Path</label>
|
||||
<input
|
||||
type="text"
|
||||
id="dockerfile_path"
|
||||
name="dockerfile_path"
|
||||
value="{{if .DockerfilePath}}{{.DockerfilePath}}{{else}}Dockerfile{{end}}"
|
||||
class="input"
|
||||
placeholder="Dockerfile"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="border-gray-200">
|
||||
|
||||
<h3 class="text-lg font-medium text-gray-900">Optional Settings</h3>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="docker_network" class="label">Docker Network</label>
|
||||
<input
|
||||
type="text"
|
||||
id="docker_network"
|
||||
name="docker_network"
|
||||
value="{{.DockerNetwork}}"
|
||||
class="input"
|
||||
placeholder="bridge"
|
||||
>
|
||||
<p class="text-sm text-gray-500 mt-1">Leave empty to use default bridge network</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="ntfy_topic" class="label">Ntfy Topic URL</label>
|
||||
<input
|
||||
type="url"
|
||||
id="ntfy_topic"
|
||||
name="ntfy_topic"
|
||||
value="{{.NtfyTopic}}"
|
||||
class="input"
|
||||
placeholder="https://ntfy.sh/my-topic"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="slack_webhook" class="label">Slack Webhook URL</label>
|
||||
<input
|
||||
type="url"
|
||||
id="slack_webhook"
|
||||
name="slack_webhook"
|
||||
value="{{.SlackWebhook}}"
|
||||
class="input"
|
||||
placeholder="https://hooks.slack.com/services/..."
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-3 pt-4">
|
||||
<a href="/" class="btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn-primary">Create App</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
{{end}}
|
||||
60
templates/base.html
Normal file
60
templates/base.html
Normal file
@@ -0,0 +1,60 @@
|
||||
{{define "base"}}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>{{block "title" .}}upaas{{end}}</title>
|
||||
<link rel="stylesheet" href="/s/css/tailwind.css">
|
||||
</head>
|
||||
<body class="bg-gray-50 min-h-screen">
|
||||
{{block "content" .}}{{end}}
|
||||
<script src="/s/js/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
|
||||
{{define "nav"}}
|
||||
<nav class="app-bar">
|
||||
<div class="max-w-6xl mx-auto flex justify-between items-center">
|
||||
<a href="/" class="text-xl font-medium text-gray-900 hover:text-primary-600 transition-colors">
|
||||
upaas
|
||||
</a>
|
||||
<div class="flex items-center gap-4">
|
||||
<a href="/apps/new" class="btn-primary">
|
||||
New App
|
||||
</a>
|
||||
<form method="POST" action="/logout" class="inline">
|
||||
<button type="submit" class="btn-text">Logout</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
{{end}}
|
||||
|
||||
{{define "alert-error"}}
|
||||
{{if .Error}}
|
||||
<div class="alert-error" data-auto-dismiss="8000">
|
||||
<div class="flex items-center">
|
||||
<svg class="w-5 h-5 mr-2 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
<span>{{.Error}}</span>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{define "alert-success"}}
|
||||
{{if .Success}}
|
||||
<div class="alert-success" data-auto-dismiss="5000">
|
||||
<div class="flex items-center">
|
||||
<svg class="w-5 h-5 mr-2 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
<span>{{.Success}}</span>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
91
templates/dashboard.html
Normal file
91
templates/dashboard.html
Normal file
@@ -0,0 +1,91 @@
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "title"}}Dashboard - upaas{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{template "nav" .}}
|
||||
|
||||
<main class="max-w-6xl mx-auto px-4 py-8">
|
||||
{{template "alert-success" .}}
|
||||
{{template "alert-error" .}}
|
||||
|
||||
<div class="section-header">
|
||||
<h1 class="text-2xl font-medium text-gray-900">Applications</h1>
|
||||
<a href="/apps/new" class="btn-primary">
|
||||
<svg class="w-5 h-5 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
|
||||
</svg>
|
||||
New App
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{if .Apps}}
|
||||
<div class="card overflow-hidden">
|
||||
<table class="table">
|
||||
<thead class="table-header">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Repository</th>
|
||||
<th>Branch</th>
|
||||
<th>Status</th>
|
||||
<th class="text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-body">
|
||||
{{range .Apps}}
|
||||
<tr class="table-row-hover">
|
||||
<td>
|
||||
<a href="/apps/{{.ID}}" class="text-primary-600 hover:text-primary-800 font-medium">
|
||||
{{.Name}}
|
||||
</a>
|
||||
</td>
|
||||
<td class="text-gray-500 font-mono text-xs">{{.RepoURL}}</td>
|
||||
<td class="text-gray-500">{{.Branch}}</td>
|
||||
<td>
|
||||
{{if eq .Status "running"}}
|
||||
<span class="badge-success">Running</span>
|
||||
{{else if eq .Status "building"}}
|
||||
<span class="badge-warning">Building</span>
|
||||
{{else if eq .Status "error"}}
|
||||
<span class="badge-error">Error</span>
|
||||
{{else if eq .Status "stopped"}}
|
||||
<span class="badge-neutral">Stopped</span>
|
||||
{{else}}
|
||||
<span class="badge-neutral">{{.Status}}</span>
|
||||
{{end}}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<div class="flex justify-end gap-2">
|
||||
<a href="/apps/{{.ID}}" class="btn-text text-sm py-1 px-2">View</a>
|
||||
<a href="/apps/{{.ID}}/edit" class="btn-secondary text-sm py-1 px-2">Edit</a>
|
||||
<form method="POST" action="/apps/{{.ID}}/deploy" class="inline">
|
||||
<button type="submit" class="btn-success text-sm py-1 px-2">Deploy</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="card">
|
||||
<div class="empty-state">
|
||||
<svg class="empty-state-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"/>
|
||||
</svg>
|
||||
<h3 class="empty-state-title">No applications yet</h3>
|
||||
<p class="empty-state-description">Get started by creating your first application.</p>
|
||||
<div class="mt-6">
|
||||
<a href="/apps/new" class="btn-primary">
|
||||
<svg class="w-5 h-5 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
|
||||
</svg>
|
||||
Create App
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</main>
|
||||
{{end}}
|
||||
109
templates/deployments.html
Normal file
109
templates/deployments.html
Normal file
@@ -0,0 +1,109 @@
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "title"}}Deployments - {{.App.Name}} - upaas{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{template "nav" .}}
|
||||
|
||||
<main class="max-w-4xl mx-auto px-4 py-8">
|
||||
<div class="mb-6">
|
||||
<a href="/apps/{{.App.ID}}" class="text-primary-600 hover:text-primary-800 inline-flex items-center">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
|
||||
</svg>
|
||||
Back to {{.App.Name}}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="section-header">
|
||||
<h1 class="text-2xl font-medium text-gray-900">Deployment History</h1>
|
||||
<form method="POST" action="/apps/{{.App.ID}}/deploy">
|
||||
<button type="submit" class="btn-success">Deploy Now</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{{if .Deployments}}
|
||||
<div class="space-y-4">
|
||||
{{range .Deployments}}
|
||||
<div class="card p-6">
|
||||
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 mb-4">
|
||||
<div class="flex items-center gap-2 text-sm text-gray-500">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
||||
</svg>
|
||||
<span>{{.StartedAt.Format "2006-01-02 15:04:05"}}</span>
|
||||
{{if .FinishedAt.Valid}}
|
||||
<span class="text-gray-400">-</span>
|
||||
<span>{{.FinishedAt.Time.Format "15:04:05"}}</span>
|
||||
{{end}}
|
||||
</div>
|
||||
<div>
|
||||
{{if eq .Status "success"}}
|
||||
<span class="badge-success">Success</span>
|
||||
{{else if eq .Status "failed"}}
|
||||
<span class="badge-error">Failed</span>
|
||||
{{else if eq .Status "building"}}
|
||||
<span class="badge-warning">Building</span>
|
||||
{{else if eq .Status "deploying"}}
|
||||
<span class="badge-info">Deploying</span>
|
||||
{{else}}
|
||||
<span class="badge-neutral">{{.Status}}</span>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4 text-sm">
|
||||
{{if .CommitSHA.Valid}}
|
||||
<div>
|
||||
<span class="font-medium text-gray-700">Commit:</span>
|
||||
<span class="font-mono text-gray-500 ml-1">{{.CommitSHA.String}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if .ImageID.Valid}}
|
||||
<div>
|
||||
<span class="font-medium text-gray-700">Image:</span>
|
||||
<span class="font-mono text-gray-500 ml-1 text-xs">{{slice .ImageID.String 0 24}}...</span>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if .ContainerID.Valid}}
|
||||
<div>
|
||||
<span class="font-medium text-gray-700">Container:</span>
|
||||
<span class="font-mono text-gray-500 ml-1 text-xs">{{slice .ContainerID.String 0 12}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{if .Logs.Valid}}
|
||||
<details class="mt-4">
|
||||
<summary class="cursor-pointer text-sm text-primary-600 hover:text-primary-800 font-medium inline-flex items-center">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
|
||||
</svg>
|
||||
View Logs
|
||||
</summary>
|
||||
<pre class="mt-3 p-4 bg-gray-900 text-gray-100 rounded-lg text-xs overflow-x-auto font-mono leading-relaxed">{{.Logs.String}}</pre>
|
||||
</details>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="card">
|
||||
<div class="empty-state">
|
||||
<svg class="empty-state-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/>
|
||||
</svg>
|
||||
<h3 class="empty-state-title">No deployments yet</h3>
|
||||
<p class="empty-state-description">Deploy your application to see the deployment history here.</p>
|
||||
<div class="mt-6">
|
||||
<form method="POST" action="/apps/{{.App.ID}}/deploy">
|
||||
<button type="submit" class="btn-success">Deploy Now</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</main>
|
||||
{{end}}
|
||||
50
templates/login.html
Normal file
50
templates/login.html
Normal file
@@ -0,0 +1,50 @@
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "title"}}Login - upaas{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
<div class="min-h-screen flex items-center justify-center py-12 px-4">
|
||||
<div class="max-w-md w-full">
|
||||
<div class="text-center mb-8">
|
||||
<h1 class="text-3xl font-medium text-gray-900">upaas</h1>
|
||||
<p class="mt-2 text-gray-600">Sign in to continue</p>
|
||||
</div>
|
||||
|
||||
<div class="card p-8">
|
||||
{{template "alert-error" .}}
|
||||
|
||||
<form method="POST" action="/login" class="space-y-6">
|
||||
<div class="form-group">
|
||||
<label for="username" class="label">Username</label>
|
||||
<input
|
||||
type="text"
|
||||
id="username"
|
||||
name="username"
|
||||
value="{{.Username}}"
|
||||
required
|
||||
autofocus
|
||||
autocomplete="username"
|
||||
class="input"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password" class="label">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
autocomplete="current-password"
|
||||
class="input"
|
||||
>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-primary w-full py-3">
|
||||
Sign In
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
69
templates/setup.html
Normal file
69
templates/setup.html
Normal file
@@ -0,0 +1,69 @@
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "title"}}Setup - upaas{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
<div class="min-h-screen flex items-center justify-center py-12 px-4">
|
||||
<div class="max-w-md w-full">
|
||||
<div class="text-center mb-8">
|
||||
<h1 class="text-3xl font-medium text-gray-900">Welcome to upaas</h1>
|
||||
<p class="mt-2 text-gray-600">Create your admin account to get started</p>
|
||||
</div>
|
||||
|
||||
<div class="card p-8">
|
||||
{{template "alert-error" .}}
|
||||
|
||||
<form method="POST" action="/setup" class="space-y-6">
|
||||
<div class="form-group">
|
||||
<label for="username" class="label">Username</label>
|
||||
<input
|
||||
type="text"
|
||||
id="username"
|
||||
name="username"
|
||||
value="{{.Username}}"
|
||||
required
|
||||
autofocus
|
||||
autocomplete="username"
|
||||
class="input"
|
||||
placeholder="admin"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password" class="label">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
autocomplete="new-password"
|
||||
class="input"
|
||||
placeholder="Minimum 8 characters"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password_confirm" class="label">Confirm Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="password_confirm"
|
||||
name="password_confirm"
|
||||
required
|
||||
autocomplete="new-password"
|
||||
class="input"
|
||||
placeholder="Repeat your password"
|
||||
>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-primary w-full py-3">
|
||||
Create Account
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<p class="mt-6 text-center text-sm text-gray-500">
|
||||
This is a single-user system. This account will be the only admin.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
98
templates/templates.go
Normal file
98
templates/templates.go
Normal file
@@ -0,0 +1,98 @@
|
||||
// Package templates provides HTML template handling.
|
||||
package templates
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"sync"
|
||||
)
|
||||
|
||||
//go:embed *.html
|
||||
var templatesRaw embed.FS
|
||||
|
||||
// Template cache variables are global to enable efficient template reuse
|
||||
// across requests without re-parsing on each call.
|
||||
var (
|
||||
//nolint:gochecknoglobals // singleton pattern for template cache
|
||||
baseTemplate *template.Template
|
||||
//nolint:gochecknoglobals // singleton pattern for template cache
|
||||
pageTemplates map[string]*template.Template
|
||||
//nolint:gochecknoglobals // protects template cache access
|
||||
templatesMutex sync.RWMutex
|
||||
)
|
||||
|
||||
// initTemplates parses base template and creates cloned templates for each page.
|
||||
func initTemplates() {
|
||||
templatesMutex.Lock()
|
||||
defer templatesMutex.Unlock()
|
||||
|
||||
if pageTemplates != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Parse base template with shared components
|
||||
baseTemplate = template.Must(template.ParseFS(templatesRaw, "base.html"))
|
||||
|
||||
// Pages that extend base
|
||||
pages := []string{
|
||||
"setup.html",
|
||||
"login.html",
|
||||
"dashboard.html",
|
||||
"app_new.html",
|
||||
"app_detail.html",
|
||||
"app_edit.html",
|
||||
"deployments.html",
|
||||
}
|
||||
|
||||
pageTemplates = make(map[string]*template.Template)
|
||||
|
||||
for _, page := range pages {
|
||||
// Clone base template and parse page-specific template into it
|
||||
clone := template.Must(baseTemplate.Clone())
|
||||
pageTemplates[page] = template.Must(clone.ParseFS(templatesRaw, page))
|
||||
}
|
||||
}
|
||||
|
||||
// GetParsed returns a template executor that routes to the correct page template.
|
||||
func GetParsed() *TemplateExecutor {
|
||||
initTemplates()
|
||||
|
||||
return &TemplateExecutor{}
|
||||
}
|
||||
|
||||
// TemplateExecutor executes templates using the correct cloned template set.
|
||||
type TemplateExecutor struct{}
|
||||
|
||||
// ExecuteTemplate executes the named template with the given data.
|
||||
func (t *TemplateExecutor) ExecuteTemplate(
|
||||
writer io.Writer,
|
||||
name string,
|
||||
data any,
|
||||
) error {
|
||||
templatesMutex.RLock()
|
||||
|
||||
tmpl, ok := pageTemplates[name]
|
||||
|
||||
templatesMutex.RUnlock()
|
||||
|
||||
if !ok {
|
||||
// Fallback for non-page templates
|
||||
err := baseTemplate.ExecuteTemplate(writer, name, data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("execute base template %s: %w", name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Execute the "base" template from the cloned set
|
||||
// (which has page-specific overrides)
|
||||
err := tmpl.ExecuteTemplate(writer, "base", data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("execute page template %s: %w", name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user