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|
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Production-Ready GenieACS Single-Container Deployment for Hugging Face
|
| 2 |
+
|
| 3 |
+
This repository contains a complete, production-ready configuration for deploying a self-contained **GenieACS** server on Hugging Face Spaces (using a Docker Space).
|
| 4 |
+
|
| 5 |
+
GenieACS is a high-performance TR-069 Auto Configuration Server (ACS) designed to manage customer-premises equipment (CPE).
|
| 6 |
+
|
| 7 |
+
## Architecture Overview
|
| 8 |
+
|
| 9 |
+
Since Hugging Face Spaces expose only a single web port (**7860**) to the public, this container uses a multi-layered service architecture coordinated by **Supervisor** and reverse-proxied by **Nginx**:
|
| 10 |
+
|
| 11 |
+
```
|
| 12 |
+
Public Traffic (HTTPS) ---> [ Hugging Face SSL Proxy ]
|
| 13 |
+
|
|
| 14 |
+
| Port 7860 (HTTP)
|
| 15 |
+
v
|
| 16 |
+
[ Nginx Reverse Proxy ]
|
| 17 |
+
________________________|________________________
|
| 18 |
+
| | | | |
|
| 19 |
+
/ (UI UI-API) /api/ /files/ /cwmp /healthz
|
| 20 |
+
| | | | |
|
| 21 |
+
v v v v v
|
| 22 |
+
[ UI ] [ NBI ] [ FS ] [ CWMP ] [ Health ]
|
| 23 |
+
Port 3000 Port 7557 Port 7567 Port 7547 200 'OK'
|
| 24 |
+
\____________|___________|____________/
|
| 25 |
+
|
|
| 26 |
+
v
|
| 27 |
+
[ MongoDB 8.0 ]
|
| 28 |
+
Port 27017 (Auth Enabled)
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
### Components In Container
|
| 32 |
+
1. **Nginx (7860)**: Performs path-based routing, terminates WebSocket connections, manages connection timeouts, handles Gzip compression, and applies security headers.
|
| 33 |
+
2. **MongoDB Community Edition (27017)**: Local database engine configured with WiredTiger, auth-enabled, and tuned to restrict memory consumption.
|
| 34 |
+
3. **GenieACS CWMP (7547)**: Receives TR-069 device Inform messages and coordinates download/upload workflows.
|
| 35 |
+
4. **GenieACS NBI (7557)**: Northbound Interface (JSON API) used to configure settings and query device states.
|
| 36 |
+
5. **GenieACS FS (7567)**: File server for holding and distributing firmware updates, configurations, and scripts.
|
| 37 |
+
6. **GenieACS UI (3000)**: Web-based administrative user interface.
|
| 38 |
+
7. **Supervisor Orchestrator**: Starts services, orders dependencies (waiting on MongoDB), handles log rotation, and monitors health.
|
| 39 |
+
8. **Health Monitor Daemon**: Loops every 30 seconds to verify all endpoints. If any service crashes, it automatically heals by restarting it via `supervisorctl`.
|
| 40 |
+
9. **Hugging Face Hub Integration**: Periodically uploads compressed `mongodump` database archives to a private Hugging Face Dataset.
|
| 41 |
+
|
| 42 |
+
---
|
| 43 |
+
|
| 44 |
+
## Exposed Ports & Routing
|
| 45 |
+
|
| 46 |
+
All external requests arrive through port `7860`. Nginx maps the public endpoints to internal ports as follows:
|
| 47 |
+
|
| 48 |
+
| External Path | Internal Port | Service Description |
|
| 49 |
+
|---|---|---|
|
| 50 |
+
| `/` | `3000` | GenieACS Administrative Web UI |
|
| 51 |
+
| `/api/` | `7557` | GenieACS Northbound API (NBI) |
|
| 52 |
+
| `/files/` | `7567` | GenieACS File Server (FS) |
|
| 53 |
+
| `/cwmp` | `7547` | GenieACS Device Connection Engine (CWMP) |
|
| 54 |
+
| `/healthz` | (Static Nginx) | Simple health validation endpoint |
|
| 55 |
+
|
| 56 |
+
---
|
| 57 |
+
|
| 58 |
+
## Environment Variables
|
| 59 |
+
|
| 60 |
+
The container is configured entirely using environment variables. When deploying to Hugging Face, configure these in the Space's **Settings > Variables and Secrets**.
|
| 61 |
+
|
| 62 |
+
### Core Settings
|
| 63 |
+
* `ADMIN_USERNAME`: Web UI administrator username (managed inside GenieACS database).
|
| 64 |
+
* `ADMIN_PASSWORD`: Web UI administrator password.
|
| 65 |
+
* `LOG_LEVEL`: GenieACS logging level (`info`, `warn`, `error`, `debug`). Defaults to `info`.
|
| 66 |
+
* `TZ`: System timezone (e.g., `UTC` or `America/New_York`).
|
| 67 |
+
|
| 68 |
+
### Database Settings
|
| 69 |
+
* `MONGODB_URI`: Connection string for an *external* MongoDB instance (optional). If left blank, the container automatically spawns its own internal MongoDB on port 27017.
|
| 70 |
+
* `GENIEACS_UI_JWT_SECRET`: Secret key for signing Web UI session tokens. If not provided, the entrypoint generates a secure random secret on first boot and persists it inside `/data/genieacs_jwt.secret`.
|
| 71 |
+
|
| 72 |
+
### Hugging Face Backup & Restore
|
| 73 |
+
* `HF_TOKEN`: Hugging Face API write access token. Required to run backups or restores on boot.
|
| 74 |
+
* `HF_DATASET`: Target Hugging Face private dataset repo (e.g., `username/genieacs-backups`).
|
| 75 |
+
* `BACKUP_INTERVAL`: Number of seconds between automated backups. Defaults to `86400` (24 hours).
|
| 76 |
+
* `BACKUP_RETENTION`: Number of recent backup archives to retain both locally and in the Hugging Face Dataset. Defaults to `5`.
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## Deployment to Hugging Face Spaces
|
| 81 |
+
|
| 82 |
+
1. Create a new **Space** on Hugging Face.
|
| 83 |
+
2. Select **Docker** as the Space type.
|
| 84 |
+
3. Choose the **Blank** template.
|
| 85 |
+
4. Set the Space visibility to **Private** or **Public** (Note: A private Space is recommended if managing sensitive device credentials).
|
| 86 |
+
5. Open the Space's **Settings** and add your variables:
|
| 87 |
+
* Create a private Dataset on Hugging Face (e.g., `yourusername/genieacs-backups`).
|
| 88 |
+
* Set `HF_TOKEN` as a **Secret** containing your Hugging Face API write token.
|
| 89 |
+
* Set `HF_DATASET` to `yourusername/genieacs-backups`.
|
| 90 |
+
6. Push this repository's code to the Space's Git repository. Hugging Face will automatically compile the Dockerfile and start the container.
|
| 91 |
+
|
| 92 |
+
---
|
| 93 |
+
|
| 94 |
+
## Backup & Restore Workflow
|
| 95 |
+
|
| 96 |
+
### Automated Backups
|
| 97 |
+
Backups run on a cron-like schedule inside the Supervisor wrapper. The script does the following:
|
| 98 |
+
1. Triggers `mongodump` to extract the database state into a compressed archive.
|
| 99 |
+
2. Packages it into a `.tar.gz` named `mongo_YYYYMMDD_HHMMSS.tar.gz`.
|
| 100 |
+
3. Calls python `hf_helper.py` using `huggingface_hub` to upload the file to your private Hugging Face Dataset.
|
| 101 |
+
4. Triggers retention cleanups to remove older backups on both local storage and Hugging Face.
|
| 102 |
+
|
| 103 |
+
### Manual Backup
|
| 104 |
+
To trigger an immediate backup, access the container shell or run:
|
| 105 |
+
```bash
|
| 106 |
+
/app/backup.sh
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### Automated Restore on Boot
|
| 110 |
+
When a fresh container starts, if `HF_TOKEN` and `HF_DATASET` are set, the entrypoint script automatically:
|
| 111 |
+
1. Lists all backups in the dataset.
|
| 112 |
+
2. Downloads the latest backup archive.
|
| 113 |
+
3. Restores it using `mongorestore --drop`.
|
| 114 |
+
4. Restarts all services to load the restored state.
|
| 115 |
+
|
| 116 |
+
### Manual Restore
|
| 117 |
+
To restore to a specific backup, pass the filename as an argument:
|
| 118 |
+
```bash
|
| 119 |
+
/app/restore.sh mongo_20260712_063000.tar.gz
|
| 120 |
+
```
|
| 121 |
+
If you omit the filename, it will find and download the latest available backup.
|
| 122 |
+
|
| 123 |
---
|
| 124 |
+
|
| 125 |
+
## Performance Tuning & 500+ Concurrent Devices
|
| 126 |
+
|
| 127 |
+
This container has been tailored to handle 500+ concurrent TR-069 devices under moderate inform cycles:
|
| 128 |
+
|
| 129 |
+
* **MongoDB Memory Caps**: Cap WiredTiger cache size to `512MB` in `/app/config/mongodb.conf` to protect against container OOM crashes.
|
| 130 |
+
* **Keepalive optimization**: Nginx keeps TCP connections open (`keepalive_timeout 600s`) to prevent connection handshakes during dense Inform bursts.
|
| 131 |
+
* **Buffering Controls**: Buffered proxies are disabled on `/cwmp` (`proxy_buffering off`) to provide direct, low-latency device streams.
|
| 132 |
+
* **Log Rotation**: Logs are rotated at `10MB` sizes with 3 historical backups per log file, ensuring files never fill up the disk.
|
| 133 |
+
|
| 134 |
+
---
|
| 135 |
+
|
| 136 |
+
## Troubleshooting & Verification
|
| 137 |
+
|
| 138 |
+
### Inspecting logs
|
| 139 |
+
All logs are stored inside `/var/log/supervisor/` and `/app/logs/`.
|
| 140 |
+
* Nginx: `/var/log/supervisor/nginx_stdout.log` / `nginx_stderr.log`
|
| 141 |
+
* MongoDB: `/var/log/supervisor/mongodb_stdout.log`
|
| 142 |
+
* CWMP: `/var/log/supervisor/cwmp_stdout.log`
|
| 143 |
+
* Backups: `/var/log/supervisor/backup_scheduler_stdout.log`
|
| 144 |
+
* Health Check Monitor: `/var/log/supervisor/healthcheck_stdout.log`
|
| 145 |
+
|
| 146 |
+
### Verifying Service status
|
| 147 |
+
You can run the health check script manually to query all internal ports:
|
| 148 |
+
```bash
|
| 149 |
+
/app/healthcheck.sh
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
---
|
| 153 |
|
| 154 |
+
## Security Guidelines
|
| 155 |
+
|
| 156 |
+
1. **MongoDB Shielding**: MongoDB is bound only to `127.0.0.1`. It cannot be reached from outside the container, and Nginx does not proxy its port.
|
| 157 |
+
2. **Access Control**: On first initialization, secure random credentials are created for administrative database and app users, saving configuration details in `/data/mongodb_secrets.env`.
|
| 158 |
+
3. **Reverse Proxy Security**: Directory listings are disabled, standard server headers are stripped, and strict Content Security Policies (CSP) are configured.
|
docker-entrypoint.sh
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
set -e
|
|
|
|
| 3 |
|
| 4 |
# Hardcoded Default Variables (User only configures HF_TOKEN, ADMIN_PASSWORD, GENIEACS_UI_JWT_SECRET, HF_DATASET, and ADMIN_USERNAME)
|
| 5 |
export BACKUP_INTERVAL=86400
|
|
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
set -e
|
| 3 |
+
set -x
|
| 4 |
|
| 5 |
# Hardcoded Default Variables (User only configures HF_TOKEN, ADMIN_PASSWORD, GENIEACS_UI_JWT_SECRET, HF_DATASET, and ADMIN_USERNAME)
|
| 6 |
export BACKUP_INTERVAL=86400
|