feat: single port config (dashboard on port, datasette on port+1)
- ARGUS_PORT now sets dashboard port, datasette auto-derives as port+1 - Dashboard dynamically injects correct datasette URL - Simplifies multi-agent deployment (each agent gets own port namespace) - Removed ARGUS_DASHBOARD_PORT env var
This commit is contained in:
parent
88dee44ac0
commit
4d57e93196
4 changed files with 32 additions and 19 deletions
|
|
@ -83,8 +83,7 @@ Environment variables:
|
||||||
| Variable | Default | Description |
|
| Variable | Default | Description |
|
||||||
|----------|---------|-------------|
|
|----------|---------|-------------|
|
||||||
| `ARGUS_DB` | `~/.argus/argus.db` | Database path |
|
| `ARGUS_DB` | `~/.argus/argus.db` | Database path |
|
||||||
| `ARGUS_PORT` | `8100` | Datasette API port |
|
| `ARGUS_PORT` | `8100` | Dashboard port (datasette runs on port+1) |
|
||||||
| `ARGUS_DASHBOARD_PORT` | `8101` | Dashboard port |
|
|
||||||
| `GH_TOKEN` | — | GitHub API token |
|
| `GH_TOKEN` | — | GitHub API token |
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
@ -104,11 +103,13 @@ Environment variables:
|
||||||
┌─────────┴─────────┐
|
┌─────────┴─────────┐
|
||||||
▼ ▼
|
▼ ▼
|
||||||
┌───────────────┐ ┌───────────────┐
|
┌───────────────┐ ┌───────────────┐
|
||||||
│ Datasette │ │ Dashboard │
|
│ Dashboard │ │ Datasette │
|
||||||
│ :8100 (API) │ │ :8101 (HTML) │
|
│ :PORT (HTML) │ │ :PORT+1 (API) │
|
||||||
└───────────────┘ └───────────────┘
|
└───────────────┘ └───────────────┘
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Default: Dashboard on 8100, Datasette on 8101. Set `ARGUS_PORT` to change base port.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
|
||||||
38
bin/argus
38
bin/argus
|
|
@ -21,8 +21,7 @@ from typing import Optional
|
||||||
|
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.0"
|
||||||
DEFAULT_DB_PATH = Path.home() / ".argus" / "argus.db"
|
DEFAULT_DB_PATH = Path.home() / ".argus" / "argus.db"
|
||||||
DEFAULT_PORT = 8100
|
DEFAULT_PORT = 8100 # Dashboard port; datasette runs on port+1
|
||||||
DEFAULT_DASHBOARD_PORT = 8101
|
|
||||||
|
|
||||||
def get_db_path() -> Path:
|
def get_db_path() -> Path:
|
||||||
return Path(os.environ.get("ARGUS_DB", DEFAULT_DB_PATH))
|
return Path(os.environ.get("ARGUS_DB", DEFAULT_DB_PATH))
|
||||||
|
|
@ -474,31 +473,47 @@ def cmd_escalate_resolve(args) -> None:
|
||||||
def cmd_serve(args) -> None:
|
def cmd_serve(args) -> None:
|
||||||
"""Start datasette + dashboard servers."""
|
"""Start datasette + dashboard servers."""
|
||||||
import http.server
|
import http.server
|
||||||
import threading
|
|
||||||
|
|
||||||
db_path = get_db_path()
|
db_path = get_db_path()
|
||||||
dashboard_path = get_dashboard_path()
|
dashboard_path = get_dashboard_path()
|
||||||
|
|
||||||
|
# Single port config: dashboard on port, datasette on port+1
|
||||||
port = args.port or int(os.environ.get("ARGUS_PORT", DEFAULT_PORT))
|
port = args.port or int(os.environ.get("ARGUS_PORT", DEFAULT_PORT))
|
||||||
dashboard_port = args.dashboard_port or int(os.environ.get("ARGUS_DASHBOARD_PORT", DEFAULT_DASHBOARD_PORT))
|
datasette_port = port + 1
|
||||||
|
|
||||||
print(f"Starting Argus servers...")
|
print(f"Starting Argus servers...")
|
||||||
print(f" Datasette: http://localhost:{port}")
|
print(f" Dashboard: http://localhost:{port}")
|
||||||
print(f" Dashboard: http://localhost:{dashboard_port}")
|
print(f" Datasette: http://localhost:{datasette_port}")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
# Start datasette in background
|
# Start datasette in background
|
||||||
datasette_proc = subprocess.Popen(
|
datasette_proc = subprocess.Popen(
|
||||||
["datasette", str(db_path), "-p", str(port), "--cors"],
|
["datasette", str(db_path), "-p", str(datasette_port), "--cors"],
|
||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.DEVNULL
|
stderr=subprocess.DEVNULL
|
||||||
)
|
)
|
||||||
|
|
||||||
# Start simple HTTP server for dashboard
|
# Custom handler that injects the datasette port into the dashboard
|
||||||
|
class ArgusHandler(http.server.SimpleHTTPRequestHandler):
|
||||||
|
def do_GET(self):
|
||||||
|
if self.path == "/" or self.path == "/index.html":
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header("Content-type", "text/html")
|
||||||
|
self.end_headers()
|
||||||
|
with open(dashboard_path) as f:
|
||||||
|
html = f.read()
|
||||||
|
# Inject datasette port config
|
||||||
|
html = html.replace(
|
||||||
|
"const API_BASE = 'http://localhost:8100'",
|
||||||
|
f"const API_BASE = 'http://localhost:{datasette_port}'"
|
||||||
|
)
|
||||||
|
self.wfile.write(html.encode())
|
||||||
|
else:
|
||||||
|
super().do_GET()
|
||||||
|
|
||||||
os.chdir(dashboard_path.parent)
|
os.chdir(dashboard_path.parent)
|
||||||
|
|
||||||
handler = http.server.SimpleHTTPRequestHandler
|
with http.server.HTTPServer(("", port), ArgusHandler) as httpd:
|
||||||
with http.server.HTTPServer(("", dashboard_port), handler) as httpd:
|
|
||||||
try:
|
try:
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
@ -579,8 +594,7 @@ def main():
|
||||||
|
|
||||||
# Serve command
|
# Serve command
|
||||||
serve_parser = subparsers.add_parser("serve", help="Start servers")
|
serve_parser = subparsers.add_parser("serve", help="Start servers")
|
||||||
serve_parser.add_argument("--port", type=int, help=f"Datasette port (default: {DEFAULT_PORT})")
|
serve_parser.add_argument("--port", type=int, help=f"Dashboard port (default: {DEFAULT_PORT}); datasette runs on port+1")
|
||||||
serve_parser.add_argument("--dashboard-port", type=int, help=f"Dashboard port (default: {DEFAULT_DASHBOARD_PORT})")
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,7 @@ argus serve [--port 8100] [--dashboard-port 8101]
|
||||||
| Variable | Default | Description |
|
| Variable | Default | Description |
|
||||||
|----------|---------|-------------|
|
|----------|---------|-------------|
|
||||||
| `ARGUS_DB` | `~/.argus/argus.db` | Database path |
|
| `ARGUS_DB` | `~/.argus/argus.db` | Database path |
|
||||||
| `ARGUS_PORT` | `8100` | Datasette port |
|
| `ARGUS_PORT` | `8100` | Dashboard port (datasette on port+1) |
|
||||||
| `ARGUS_DASHBOARD_PORT` | `8101` | Dashboard port |
|
|
||||||
| `GH_TOKEN` | — | GitHub API token |
|
| `GH_TOKEN` | — | GitHub API token |
|
||||||
|
|
||||||
## Workflow
|
## Workflow
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ Restart=on-failure
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
Environment=ARGUS_DB=/root/.argus/argus.db
|
Environment=ARGUS_DB=/root/.argus/argus.db
|
||||||
Environment=ARGUS_PORT=8100
|
Environment=ARGUS_PORT=8100
|
||||||
Environment=ARGUS_DASHBOARD_PORT=8101
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue