Documentation
¶
Overview ¶
Package devops implements VORTEX's DevOps agent (build plan M16): SSH-based VPS management — running commands, transferring files, and driving Docker and Nginx on remote servers. It uses golang.org/x/crypto/ssh (already a dependency); file transfer is done over an SSH exec session (base64 stream) rather than SFTP, so no new module is introduced.
This file implements the SSH client.
Index ¶
- type Container
- type ContainerStats
- type DevOpsAgent
- type DockerManager
- func (d *DockerManager) ListContainers(ctx context.Context) ([]Container, error)
- func (d *DockerManager) Logs(ctx context.Context, name string, lines int) (string, error)
- func (d *DockerManager) Pull(ctx context.Context, image string) error
- func (d *DockerManager) RunContainer(ctx context.Context, image, name string, ports, envVars map[string]string) error
- func (d *DockerManager) StartContainer(ctx context.Context, name string) error
- func (d *DockerManager) Stats(ctx context.Context) ([]ContainerStats, error)
- func (d *DockerManager) StopContainer(ctx context.Context, name string) error
- type NginxManager
- func (n *NginxManager) AddSite(ctx context.Context, domain, upstream string, sslEnabled bool) error
- func (n *NginxManager) EnableSSL(ctx context.Context, domain, email string) error
- func (n *NginxManager) ListSites(ctx context.Context) ([]string, error)
- func (n *NginxManager) Reload(ctx context.Context) error
- func (n *NginxManager) RemoveSite(ctx context.Context, domain string) error
- func (n *NginxManager) Status(ctx context.Context) (string, error)
- type Notifier
- type SSHClient
- func (c *SSHClient) Close() error
- func (c *SSHClient) Connect(ctx context.Context) error
- func (c *SSHClient) Download(ctx context.Context, remotePath, localPath string) error
- func (c *SSHClient) ReadRemote(ctx context.Context, remotePath string) ([]byte, error)
- func (c *SSHClient) Run(ctx context.Context, command string) (stdout, stderr string, exitCode int, err error)
- func (c *SSHClient) RunStream(ctx context.Context, command string, outputFn func(line string)) error
- func (c *SSHClient) SetTOFULogger(fn func(host, fingerprint string))
- func (c *SSHClient) Upload(ctx context.Context, localPath, remotePath string) error
- func (c *SSHClient) WriteRemote(ctx context.Context, remotePath string, data []byte) error
- type SSHConfig
- type Server
- func (s *Server) InstallPackage(ctx context.Context, pkg string) error
- func (s *Server) RunCommand(ctx context.Context, cmd string, stream func(string)) (string, error)
- func (s *Server) ServiceRestart(ctx context.Context, service string) error
- func (s *Server) ServiceStatus(ctx context.Context, service string) (string, error)
- func (s *Server) SetApprover(fn func(action string) bool)
- func (s *Server) SystemInfo() (*SystemInfo, error)
- type SystemInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container struct {
ID string `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
Status string `json:"status"`
Ports string `json:"ports"`
}
Container is a Docker container summary.
type ContainerStats ¶
type ContainerStats struct {
Name string `json:"name"`
CPU string `json:"cpu"`
Memory string `json:"memory"`
}
ContainerStats is a container's live resource usage.
type DevOpsAgent ¶
type DevOpsAgent struct {
// contains filtered or unexported fields
}
DevOpsAgent orchestrates SSH/Docker/Nginx operations on connected servers.
func NewDevOpsAgent ¶
func NewDevOpsAgent(gateway agents.AIGateway, notifier Notifier, approver func(action string) bool) *DevOpsAgent
NewDevOpsAgent constructs a DevOps agent. approver gates mutating ops.
func (*DevOpsAgent) Connect ¶
func (a *DevOpsAgent) Connect(ctx context.Context, host, user, keyPath string) error
Connect establishes an SSH connection to host and builds the sub-managers.
func (*DevOpsAgent) Handle ¶
func (a *DevOpsAgent) Handle(ctx context.Context, msg string, progressFn func(string)) (string, error)
Handle routes a natural-language DevOps request to the right operation, streaming progress via progressFn.
func (*DevOpsAgent) Servers ¶
func (a *DevOpsAgent) Servers() []string
Servers returns the connected server hostnames (currently one).
type DockerManager ¶
type DockerManager struct {
// contains filtered or unexported fields
}
DockerManager runs docker commands on a remote server over SSH.
func NewDockerManager ¶
func NewDockerManager(server *Server) *DockerManager
NewDockerManager constructs a manager over a Server.
func (*DockerManager) ListContainers ¶
func (d *DockerManager) ListContainers(ctx context.Context) ([]Container, error)
ListContainers runs `docker ps` and parses the JSON-per-line output.
func (*DockerManager) Pull ¶
func (d *DockerManager) Pull(ctx context.Context, image string) error
Pull pulls an image (approval-gated).
func (*DockerManager) RunContainer ¶
func (d *DockerManager) RunContainer(ctx context.Context, image, name string, ports, envVars map[string]string) error
RunContainer runs a detached container with the given ports/env (approval).
func (*DockerManager) StartContainer ¶
func (d *DockerManager) StartContainer(ctx context.Context, name string) error
StartContainer starts a container (approval-gated).
func (*DockerManager) Stats ¶
func (d *DockerManager) Stats(ctx context.Context) ([]ContainerStats, error)
Stats runs `docker stats --no-stream` and parses CPU/memory per container.
func (*DockerManager) StopContainer ¶
func (d *DockerManager) StopContainer(ctx context.Context, name string) error
StopContainer stops a container (approval-gated).
type NginxManager ¶
type NginxManager struct {
// contains filtered or unexported fields
}
NginxManager manages Nginx on a remote server over SSH.
func NewNginxManager ¶
func NewNginxManager(server *Server) *NginxManager
NewNginxManager constructs a manager over a Server. The server's SSH client must implement fileWriter (the real *SSHClient does).
func (*NginxManager) AddSite ¶
AddSite writes a reverse-proxy site config, enables it, and reloads nginx (approval-gated).
func (*NginxManager) EnableSSL ¶
func (n *NginxManager) EnableSSL(ctx context.Context, domain, email string) error
EnableSSL provisions a Let's Encrypt cert for domain via certbot (approval).
func (*NginxManager) ListSites ¶
func (n *NginxManager) ListSites(ctx context.Context) ([]string, error)
ListSites returns the enabled site names.
func (*NginxManager) Reload ¶
func (n *NginxManager) Reload(ctx context.Context) error
Reload tests the config then reloads nginx (approval-gated).
func (*NginxManager) RemoveSite ¶
func (n *NginxManager) RemoveSite(ctx context.Context, domain string) error
RemoveSite disables a site config and reloads nginx (approval-gated).
type Notifier ¶
Notifier delivers DevOps alerts. Satisfied by *messaging.Router via an adapter (keeps devops decoupled from messaging). Nil-safe at call sites.
type SSHClient ¶
type SSHClient struct {
// contains filtered or unexported fields
}
SSHClient is a connected (or connectable) SSH client.
func NewSSHClient ¶
NewSSHClient builds a client from cfg. It requires a host, user, and at least one auth method (key or password).
func (*SSHClient) Connect ¶
Connect establishes the SSH connection (verifying the host key per config).
func (*SSHClient) Download ¶
Download reads remotePath and writes it to localPath (base64 over exec).
func (*SSHClient) ReadRemote ¶
ReadRemote returns the bytes of remotePath (base64 over exec).
func (*SSHClient) Run ¶
func (c *SSHClient) Run(ctx context.Context, command string) (stdout, stderr string, exitCode int, err error)
Run executes a single command, returning stdout, stderr, and the exit code.
func (*SSHClient) RunStream ¶
func (c *SSHClient) RunStream(ctx context.Context, command string, outputFn func(line string)) error
RunStream runs command and delivers stdout line by line via outputFn (used for long-running commands like builds/deploys).
func (*SSHClient) SetTOFULogger ¶
SetTOFULogger installs a callback invoked when a new host key is trusted on first connect.
type SSHConfig ¶
type SSHConfig struct {
Host string
Port int // default 22
User string
Password string // password auth (if no key)
KeyPath string // path to a private key file
KeyData []byte // inline private key (takes precedence over KeyPath)
Timeout time.Duration // dial/handshake timeout (default 30s)
KnownHosts string // path to known_hosts; empty = TOFU
}
SSHConfig configures an SSH connection.
type Server ¶
type Server struct {
OS string // "ubuntu"|"debian"|"centos"|"alpine"|…
Arch string // "amd64"|"arm64"|…
// contains filtered or unexported fields
}
Server is a managed VPS reached over SSH.
func (*Server) InstallPackage ¶
InstallPackage installs pkg using the detected package manager (approval).
func (*Server) RunCommand ¶
RunCommand runs an arbitrary command (approval-gated), streaming output.
func (*Server) ServiceRestart ¶
ServiceRestart restarts a service (approval-gated).
func (*Server) ServiceStatus ¶
ServiceStatus returns the systemctl status of a service.
func (*Server) SetApprover ¶
SetApprover installs the human-approval callback for mutating operations.
func (*Server) SystemInfo ¶
func (s *Server) SystemInfo() (*SystemInfo, error)
SystemInfo gathers hostname/CPU/memory/disk/uptime/load via SSH.
type SystemInfo ¶
type SystemInfo struct {
Hostname string `json:"hostname"`
OS string `json:"os"`
Arch string `json:"arch"`
CPUs int `json:"cpus"`
MemoryMB int `json:"memory_mb"`
DiskGB int `json:"disk_gb"`
Uptime string `json:"uptime"`
LoadAvg string `json:"load_avg"`
}
SystemInfo summarises a server's resources.