Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,46 @@ tunnel; the agent just copies bytes between each tunnel stream and the socket.

| Variable | Required | Default | Description |
|-------------------------|----------|--------------------------------|-------------|
| `MIABI_CONTROL_URL` | yes | — | Control plane base URL, e.g. `https://panel.example.com` |
| `MIABI_CONTROL_URL` | yes | — | Control plane base URL, e.g. `https://miabi.example.com` |
| `MIABI_NODE_TOKEN` | yes | — | Join token shown once when the node was added (`mbn_…`) |
| `DOCKER_HOST` | no | `unix:///var/run/docker.sock` | Local Docker endpoint |

The control plane reconnect is automatic with exponential backoff.

## Run

### Install script

Checks that Docker is present and running (it does not install Docker), then starts the
agent and verifies it stayed up:

```sh
curl -fsSL https://get.miabi.io/agent | \
MIABI_CONTROL_URL=https://miabi.example.com MIABI_NODE_TOKEN=mbn_xxxxxxxx bash
```

### Docker

```sh
docker run -d --name miabi-agent --restart unless-stopped \
-e MIABI_CONTROL_URL=https://panel.example.com \
-e MIABI_CONTROL_URL=https://miabi.example.com \
-e MIABI_NODE_TOKEN=mbn_xxxxxxxx \
-v /var/run/docker.sock:/var/run/docker.sock \
ghcr.io/miabi-io/agent:latest
miabi/agent:latest
```

### Binary

Via environment, or the equivalent flags (`--control-url`, `--token`, `--insecure`) — each flag
defaults to its env var and wins when both are set:

```sh
MIABI_CONTROL_URL=https://panel.example.com \
MIABI_CONTROL_URL=https://miabi.example.com \
MIABI_NODE_TOKEN=mbn_xxxxxxxx \
./miabi-agent

# or
./miabi-agent --control-url https://miabi.example.com --token mbn_xxxxxxxx
```

## Build
Expand Down
32 changes: 19 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
// stream to the local Docker socket. All orchestration logic stays on the
// control plane; the agent is a thin, dumb Docker proxy with no DB/Redis access.
//
// Configuration (environment):
// Configuration is read from flags, each defaulting to an environment variable so
// the container form (env) and the binary form (flags) are interchangeable; a
// flag wins when both are given.
//
// MIABI_CONTROL_URL control plane base URL, e.g. https://panel.example.com
// (falls back to MIABI_API_URL)
// MIABI_NODE_TOKEN join token issued when the node was added (mbn_...)
// DOCKER_HOST local Docker endpoint (default unix:///var/run/docker.sock)
// MIABI_AGENT_INSECURE_SKIP_VERIFY skip TLS verification of the control plane (default false)
// --control-url / MIABI_CONTROL_URL control plane base URL, e.g. https://miabi.example.com
// (env falls back to MIABI_API_URL)
// --token / MIABI_NODE_TOKEN join token issued when the node was added (mbn_...)
// --insecure / MIABI_AGENT_INSECURE_SKIP_VERIFY skip TLS verification of the control plane (default false)
// DOCKER_HOST local Docker endpoint (default unix:///var/run/docker.sock)
package main

import (
"context"
"flag"
"os/signal"
"strings"
"syscall"
Expand All @@ -29,26 +32,29 @@ import (
var version = "dev"

func main() {
controlURL := strings.TrimRight(goutils.Env("MIABI_CONTROL_URL", goutils.Env("MIABI_API_URL", "")), "/")
token := goutils.Env("MIABI_NODE_TOKEN", "")

controlURL := flag.String("control-url", goutils.Env("MIABI_CONTROL_URL", goutils.Env("MIABI_API_URL", "")), "control plane base URL, e.g. https://miabi.example.com (env MIABI_CONTROL_URL)")
token := flag.String("token", goutils.Env("MIABI_NODE_TOKEN", ""), "node join token, mbn_... (env MIABI_NODE_TOKEN)")
insecure := flag.Bool("insecure", goutils.EnvBool("MIABI_AGENT_INSECURE_SKIP_VERIFY", false), "skip TLS verification of the control plane (env MIABI_AGENT_INSECURE_SKIP_VERIFY)")
flag.Parse()

dockerHost := goutils.Env("DOCKER_HOST", "unix:///var/run/docker.sock")
insecure := goutils.EnvBool("MIABI_AGENT_INSECURE_SKIP_VERIFY", false)
if goutils.EnvBool("MIABI_DEV_MODE", false) {
logger.New(logger.WithDebugLevel())
} else {
logger.New(logger.WithJSONFormat(), logger.WithInfoLevel())
}

cfg := Config{
ControlURL: controlURL,
Token: token,
ControlURL: strings.TrimRight(*controlURL, "/"),
Token: *token,
DockerHost: dockerHost,
Insecure: insecure,
Insecure: *insecure,
Version: version,
ContainerID: selfContainerID(),
}
if cfg.ControlURL == "" || cfg.Token == "" {
logger.Fatal("MIABI_CONTROL_URL and MIABI_NODE_TOKEN are required")
logger.Fatal("control plane URL and node token are required (--control-url/--token or MIABI_CONTROL_URL/MIABI_NODE_TOKEN)")
}

ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
Expand Down