Skip to content
18 changes: 18 additions & 0 deletions docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://raw.githubusercontent.com/whilesmart/docs-kit/main/schema/docs.schema.json",
"name": "FlatRun Agent",
"description": "Lightweight Go backend for flat-file Docker Compose orchestration with a REST API, container lifecycle management, and plugin architecture",
"icon": "server",
"category": {
"language": "go",
"framework": "app"
},
"sidebar": [
{ "title": "Overview", "path": "docs/overview.md" },
{ "title": "Installation", "path": "docs/installation.md" },
{ "title": "Configuration", "path": "docs/configuration.md" },
{ "title": "API Reference", "path": "docs/api-reference.md" },
{ "title": "Plugin Architecture", "path": "docs/PLUGIN_ARCHITECTURE.md" },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency: All other documentation files use kebab-case (e.g., api-reference.md). It is recommended to rename PLUGIN_ARCHITECTURE.md to plugin-architecture.md for consistency and better URL readability in some static site generators.

Suggested change
{ "title": "Plugin Architecture", "path": "docs/PLUGIN_ARCHITECTURE.md" },
{ "title": "Plugin Architecture", "path": "docs/plugin-architecture.md" },

{ "title": "Security", "path": "docs/security.md" }
]
}
43 changes: 43 additions & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## API Reference

### Authentication

| Method | Endpoint | Description |
|---|---|---|
| POST | `/api/auth/login` | Login with API key |
| GET | `/api/auth/validate` | Validate JWT token |
| GET | `/api/auth/status` | Check auth status |

### Deployments

| Method | Endpoint | Description |
|---|---|---|
| GET | `/api/deployments` | List all deployments |
| POST | `/api/deployments` | Create new deployment |
| GET | `/api/deployments/:name` | Get deployment details |
| DELETE | `/api/deployments/:name` | Delete deployment |
| POST | `/api/deployments/:name/start` | Start deployment |
| POST | `/api/deployments/:name/stop` | Stop deployment |
| POST | `/api/deployments/:name/restart` | Restart deployment |
| GET | `/api/deployments/:name/logs` | Get deployment logs |

### Docker Resources

| Method | Endpoint | Description |
|---|---|---|
| GET | `/api/containers` | List containers |
| GET | `/api/images` | List images |
| GET | `/api/volumes` | List volumes |
| GET | `/api/networks` | List networks |
| POST | `/api/networks` | Create network |
| DELETE | `/api/networks/:name` | Delete network |

### Other

| Method | Endpoint | Description |
|---|---|---|
| GET | `/api/health` | Health check |
| GET | `/api/stats` | System statistics |
| GET | `/api/certificates` | List SSL certificates |
| GET | `/api/templates` | List Quick App templates |
| GET | `/api/plugins` | List installed plugins |
57 changes: 57 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Configuration

Copy the example configuration and edit it:

```bash
cp config.example.yml config.yml
```

### Reference

```yaml
deployments_path: /home/user/deployments

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example path /home/user/deployments is a user-specific path. For a system-wide agent, it's better to suggest a path like /var/lib/flatrun/deployments to match standard Linux directory hierarchies.

Suggested change
deployments_path: /home/user/deployments
deployments_path: /var/lib/flatrun/deployments

docker_socket: unix:///var/run/docker.sock

api:
host: 0.0.0.0
port: 8090
enable_cors: true
allowed_origins:
- http://localhost:5173
- http://localhost:3000

auth:
enabled: true
api_keys:
- "your-secure-api-key-here"
jwt_secret: "generate-a-secure-random-string-here"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding a specific instruction to generate a secret is better than using a placeholder string which might be accidentally left in production configurations.

Suggested change
jwt_secret: "generate-a-secure-random-string-here"
jwt_secret: "REPLACE_WITH_SECURE_RANDOM_STRING"


nginx:
container_name: nginx
config_path: /deployments/nginx/conf.d

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration example uses /deployments/nginx/conf.d as a path, while the deployments_path at the top of the file suggests /home/user/deployments. This might confuse users about where the nginx configuration should reside relative to the deployments root.

Suggested change
config_path: /deployments/nginx/conf.d
config_path: /var/lib/flatrun/nginx/conf.d

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency issue: The config_path refers to /deployments/... but the global deployments_path (line 12) is defined as /home/user/deployments. Using relative paths or consistent absolute paths is recommended to prevent confusion.

Suggested change
config_path: /deployments/nginx/conf.d
config_path: /home/user/deployments/nginx/conf.d

reload_command: nginx -s reload

certbot:
container_name: certbot
email: your-email@example.com
staging: true

logging:
level: info
format: json

health:
check_interval: 30s
metrics_retention: 24h
```

### Key Options

| Option | Description |
|---|---|
| `deployments_path` | Directory containing docker-compose deployments |
| `api.port` | API server port (default: 8090) |
| `auth.api_keys` | Valid API keys for authentication |
| `auth.jwt_secret` | Secret for signing JWT tokens |
| `logging.level` | Log level: debug, info, warn, error |
| `health.check_interval` | Health check frequency |
81 changes: 81 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
## Installation

### Prerequisites

- Go 1.21 or later (for building from source)
- Docker and Docker Compose v2
- Access to Docker socket (`/var/run/docker.sock`)
- Linux server (Ubuntu 20.04+, Debian 11+, or similar)

### Option 1: Build from Source

```bash
git clone https://github.com/flatrun/agent.git
cd agent
make build
```

Or manually:

```bash
go mod download
go build -o flatrun-agent ./cmd/agent
```

### Option 2: Download Binary

```bash
wget https://github.com/flatrun/agent/releases/latest/download/flatrun-agent
chmod +x flatrun-agent
```

### Running

Development mode:

```bash
make run
# or
./flatrun-agent --config config.yml
```

### Production with Systemd

Move the binary to a system location:

```bash
sudo mv flatrun-agent /usr/local/bin/
sudo chmod +x /usr/local/bin/flatrun-agent
```

Create `/etc/systemd/system/flatrun-agent.service`:

```ini
[Unit]
Description=FlatRun Agent
After=network.target docker.service

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding After=docker.service is good, but for better robustness, BindsTo=docker.service or PartOf=docker.service ensures the agent stops if the Docker daemon crashes or is stopped, which is critical since the agent depends entirely on it.

Suggested change
After=network.target docker.service
After=network.target docker.service
BindsTo=docker.service

Requires=docker.service

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding Requires=docker.service ensures the service fails if Docker isn't available, but BindsTo=docker.service is even stronger, ensuring that if Docker is stopped or restarted, the FlatRun Agent follows suit.

Suggested change
Requires=docker.service
Requires=docker.service
BindsTo=docker.service


[Service]
Type=simple
User=root

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security Best Practice: Running the agent as root is generally discouraged unless strictly necessary. Since the agent primarily needs access to the Docker socket, it is safer to create a dedicated system user and add them to the docker group.

Suggested change
User=root
User=flatrun
Group=docker

WorkingDirectory=/opt/flatrun

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The installation guide should include a step to create the /opt/flatrun directory, otherwise the service will fail to start due to a missing WorkingDirectory.

Suggested change
WorkingDirectory=/opt/flatrun
WorkingDirectory=/opt/flatrun
# Ensure you run: sudo mkdir -p /opt/flatrun && sudo chown flatrun:flatrun /opt/flatrun

ExecStart=/usr/local/bin/flatrun-agent --config /opt/flatrun/config.yml

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The systemd service unit points to a config file in /opt/flatrun/config.yml, but the guide doesn't explicitly mention copying the config file to this directory. Users following this guide step-by-step will encounter a failure on startup.

Suggested change
ExecStart=/usr/local/bin/flatrun-agent --config /opt/flatrun/config.yml
ExecStart=/usr/local/bin/flatrun-agent --config /opt/flatrun/config.yml
# Note: Ensure you copy your config.yml to /opt/flatrun/ before starting.

Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
```

Enable and start:

```bash
sudo systemctl daemon-reload
sudo systemctl enable flatrun-agent
sudo systemctl start flatrun-agent
sudo systemctl status flatrun-agent
sudo journalctl -u flatrun-agent -f
```
19 changes: 19 additions & 0 deletions docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Overview

FlatRun Agent is the backend service that manages Docker deployments through a simple filesystem-based approach. It monitors your deployments directory and provides a REST API for the FlatRun UI.

### Features

- Docker Compose deployment management
- Container lifecycle control (start, stop, restart)
- Real-time container monitoring and logs
- Docker resource management (images, volumes, networks)
- SSL certificate monitoring
- Quick App templates for rapid deployment
- JWT-based API authentication
- Health monitoring and statistics
- Plugin architecture for extensibility

### Architecture

The agent follows a flat-file approach: each deployment is a directory containing a `docker-compose.yml` file. The agent watches the configured deployments directory and manages the containers through the Docker API. It communicates with the FlatRun UI through a REST API and uses JWT tokens for authentication.
23 changes: 23 additions & 0 deletions docs/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Security

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The security section is currently a list of troubleshooting tips and basics. Consider adding a specific section about Docker socket security, as providing access to /var/run/docker.sock is equivalent to giving root access to the host.

Suggested change
## Security
- Use strong, unique API keys.
- Generate a secure JWT secret: `openssl rand -base64 32`.
- Run behind a reverse proxy (nginx) with HTTPS in production.
- **Restrict Docker socket access**: Ensure only the `docker` group and the `flatrun` user can access the socket. Avoid exposing the socket over TCP.
- Keep the agent updated.

- Use strong, unique API keys.
- Generate a secure JWT secret: `openssl rand -base64 32`.
- Run behind a reverse proxy (nginx) with HTTPS in production.
- Restrict Docker socket access appropriately.
- Keep the agent updated.

### Troubleshooting

**Agent won't start:**
- Check Docker is running: `systemctl status docker`
- Verify Docker socket permissions: `ls -la /var/run/docker.sock`
- Validate the config YAML syntax

**Authentication issues:**
- Ensure the API key matches between UI and agent config
- Verify JWT secret is set
- Check CORS origins include your UI URL

**Can't see deployments:**
- Verify `deployments_path` exists and is readable
- Check each deployment has a valid `docker-compose.yml`
Loading