refactor: complete opsserver migration

This commit is contained in:
2026-04-28 14:35:26 +00:00
parent 49c1830168
commit 3da7e431c2
8 changed files with 102 additions and 3058 deletions
+22 -117
View File
@@ -2,7 +2,7 @@
> 🚀 Self-hosted Docker Swarm platform with Caddy reverse proxy, automatic SSL, and real-time WebSocket updates
**Onebox** transforms any Linux server into a powerful container hosting platform. Deploy Docker Swarm services with automatic HTTPS, DNS configuration, and Caddy reverse proxy running as a Docker service - all managed through a beautiful Angular web interface with real-time updates.
**Onebox** transforms any Linux server into a powerful container hosting platform. Deploy Docker Swarm services with automatic HTTPS, DNS configuration, and Caddy reverse proxy running as a Docker service - all managed through a modern web interface with real-time updates.
## Issue Reporting and Security
@@ -17,7 +17,7 @@ For reporting bugs, issues, or security vulnerabilities, please visit [community
- **Private Registry Included** - Built-in Docker registry with token-based auth and auto-deploy on push
- **Zero Config SSL** - Automatic Let's Encrypt certificates with inline `load_pem` (no volume mounts needed)
- **Cloudflare Integration** - Automatic DNS record management and zone synchronization
- **Modern Stack** - Deno runtime + SQLite database + Angular 19 UI
- **Modern Stack** - Deno runtime + SQLite database + typed web UI
## Features ✨
@@ -34,7 +34,7 @@ For reporting bugs, issues, or security vulnerabilities, please visit [community
- 📊 **Metrics Collection** - Historical CPU, memory, and network stats (every 60s)
- 📝 **Centralized Logging** - Container logs with streaming and retention policies
- 🎨 **Angular Web UI** - Modern, responsive interface with real-time updates
- 🎨 **Web UI** - Modern, responsive interface with real-time updates
- 👥 **Multi-user Support** - Role-based access control (admin/user)
- 💾 **SQLite Database** - Embedded, zero-configuration storage
@@ -43,7 +43,7 @@ For reporting bugs, issues, or security vulnerabilities, please visit [community
- 🚀 **Auto-update on Push** - Push to registry and services update automatically
- 🔐 **Private Registry Support** - Use Docker Hub, Gitea, or custom registries
- 🔄 **Systemd Integration** - Run as a daemon with auto-restart
- 🎛️ **Full CLI & API** - Manage everything from terminal or HTTP API
- 🎛️ **Full CLI** - Manage everything from terminal or web interface
## Quick Start 🏁
@@ -103,13 +103,13 @@ Onebox is built with modern technologies for performance and developer experienc
```
┌─────────────────────────────────────────────────┐
Angular 19 Web UI
Web UI
│ (Real-time WebSocket Updates) │
└─────────────────┬───────────────────────────────┘
│ HTTP/WS
┌─────────────────▼───────────────────────────────┐
Deno HTTP Server (Port 3000) │
REST API + WebSocket Broadcast
OpsServer (Port 3000)
TypedRequest + TypedSocket
└─────────────────┬───────────────────────────────┘
┌─────────────────▼───────────────────────────────┐
@@ -140,7 +140,7 @@ Onebox is built with modern technologies for performance and developer experienc
| **Caddy Reverse Proxy** | Docker Swarm service with HTTP/2, HTTP/3, SNI, and WebSocket support |
| **Docker Swarm** | Container orchestration (all workloads run as services) |
| **SQLite Database** | Configuration, metrics, and user data |
| **WebSocket Server** | Real-time bidirectional communication |
| **OpsServer** | TypedRequest API and TypedSocket real-time updates |
| **Let's Encrypt** | Automatic SSL certificate management |
| **Cloudflare API** | DNS record automation |
@@ -235,9 +235,8 @@ onebox config show
onebox config set <key> <value>
# Example: Configure Cloudflare
onebox config set cloudflareAPIKey your-api-key
onebox config set cloudflareEmail your@email.com
onebox config set cloudflareZoneID your-zone-id
onebox config set cloudflareToken your-api-token
onebox config set cloudflareZoneId your-zone-id
```
### System Status
@@ -324,7 +323,6 @@ onebox/
│ │ ├── reverseproxy.ts # Reverse proxy orchestration
│ │ ├── caddy.ts # Caddy Docker service management
│ │ ├── docker.ts # Docker Swarm API
│ │ ├── httpserver.ts # REST API + WebSocket
│ │ ├── services.ts # Service orchestration
│ │ ├── certmanager.ts # SSL certificate management
│ │ ├── cert-requirement-manager.ts # Certificate requirements
@@ -333,8 +331,10 @@ onebox/
│ │ ├── registries.ts # External registry management
│ │ ├── dns.ts # DNS record management
│ │ ├── cloudflare-sync.ts # Cloudflare zone sync
│ │ ── daemon.ts # Systemd daemon management
│ └── apiclient.ts # API client utilities
│ │ ── daemon.ts # Systemd daemon management
├── opsserver/ # Active server implementation
│ │ ├── classes.opsserver.ts # TypedRequest + TypedSocket server
│ │ └── handlers/ # Typed request handlers
│ ├── database/ # Database layer (repository pattern)
│ │ ├── index.ts # Main OneboxDatabase class
│ │ ├── base.repository.ts # Base repository class
@@ -348,105 +348,17 @@ onebox/
│ ├── types.ts # TypeScript interfaces
│ ├── logging.ts # Logging utilities
│ └── plugins.ts # Dependency imports
├── ui/ # Angular 19 web interface
├── ts_web/ # Web interface source
├── test/ # Test files
├── mod.ts # Main entry point
└── deno.json # Deno configuration
```
### API Endpoints
### Active Server Surface
The HTTP server exposes a comprehensive REST API:
The active server surface is the `OpsServer`, which serves the bundled web UI and exposes typed operations via `TypedRequest` and real-time events via `TypedSocket`.
#### Authentication
| Method | Endpoint | Description |
| ------ | ----------------- | ----------------------------------- |
| `POST` | `/api/auth/login` | User authentication (returns token) |
#### Services
| Method | Endpoint | Description |
| -------- | --------------------------------- | ------------------------- |
| `GET` | `/api/services` | List all services |
| `POST` | `/api/services` | Create/deploy service |
| `GET` | `/api/services/:name` | Get service details |
| `PUT` | `/api/services/:name` | Update service |
| `DELETE` | `/api/services/:name` | Delete service |
| `POST` | `/api/services/:name/start` | Start service |
| `POST` | `/api/services/:name/stop` | Stop service |
| `POST` | `/api/services/:name/restart` | Restart service |
| `GET` | `/api/services/:name/logs` | Get service logs |
| `WS` | `/api/services/:name/logs/stream` | Stream logs via WebSocket |
#### SSL Certificates
| Method | Endpoint | Description |
| ------ | ------------------------ | ----------------------- |
| `GET` | `/api/ssl/list` | List all certificates |
| `GET` | `/api/ssl/:domain` | Get certificate details |
| `POST` | `/api/ssl/obtain` | Request new certificate |
| `POST` | `/api/ssl/:domain/renew` | Force renew certificate |
#### Domains
| Method | Endpoint | Description |
| ------ | ---------------------- | ---------------------------- |
| `GET` | `/api/domains` | List all domains |
| `GET` | `/api/domains/:domain` | Get domain details |
| `POST` | `/api/domains/sync` | Sync domains from Cloudflare |
#### DNS Records
| Method | Endpoint | Description |
| -------- | ------------------ | ------------------------ |
| `GET` | `/api/dns` | List DNS records |
| `POST` | `/api/dns` | Create DNS record |
| `DELETE` | `/api/dns/:domain` | Delete DNS record |
| `POST` | `/api/dns/sync` | Sync DNS from Cloudflare |
#### Registry
| Method | Endpoint | Description |
| -------- | ----------------------------- | ----------------------------- |
| `GET` | `/api/registry/tags/:service` | Get registry tags for service |
| `GET` | `/api/registry/tokens` | List registry tokens |
| `POST` | `/api/registry/tokens` | Create registry token |
| `DELETE` | `/api/registry/tokens/:id` | Delete registry token |
#### System
| Method | Endpoint | Description |
| ------ | --------------- | ------------------------------- |
| `GET` | `/api/status` | System status |
| `GET` | `/api/settings` | Get settings |
| `PUT` | `/api/settings` | Update settings |
| `WS` | `/api/ws` | WebSocket for real-time updates |
### WebSocket Messages
Real-time updates are broadcast via WebSocket:
```typescript
// Service lifecycle updates
{
type: 'service_update',
action: 'created' | 'updated' | 'deleted' | 'started' | 'stopped',
service: { id, name, status, ... }
}
// Service status changes
{
type: 'service_status',
service: { id, name, status, ... }
}
// System status updates
{
type: 'system_status',
status: { docker, reverseProxy, services, ... }
}
```
The previously documented legacy `/api/*` REST interface has been removed.
## Advanced Usage 🚀
@@ -472,13 +384,7 @@ docker push localhost:4000/myapp:latest
### Registry Token Management
```bash
# Create a CI/CD token via API
curl -X POST http://localhost:3000/api/registry/tokens \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "github-actions", "type": "ci", "scope": ["myapp"], "expiresIn": "90d"}'
# Use token for docker login
# Create a CI/CD token in the web UI, then use it for docker login
docker login localhost:4000 -u ci -p <token>
```
@@ -486,9 +392,8 @@ docker login localhost:4000 -u ci -p <token>
```bash
# Configure Cloudflare (one-time setup)
onebox config set cloudflareAPIKey your-api-key
onebox config set cloudflareEmail your@email.com
onebox config set cloudflareZoneID your-zone-id
onebox config set cloudflareToken your-api-token
onebox config set cloudflareZoneId your-zone-id
# Deploy with automatic DNS
onebox service add myapp \
@@ -562,7 +467,7 @@ onebox ssl force-renew yourdomain.com
- ✅ Ensure firewall allows WebSocket connections
- ✅ Check browser console for connection errors
- ✅ Verify `/api/ws` endpoint is accessible
- ✅ Verify the dashboard socket connection is established
### Service Not Starting