devops

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

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

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) Logs

func (d *DockerManager) Logs(ctx context.Context, name string, lines int) (string, error)

Logs returns the last `lines` of a container's logs.

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

func (n *NginxManager) AddSite(ctx context.Context, domain, upstream string, sslEnabled bool) error

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).

func (*NginxManager) Status

func (n *NginxManager) Status(ctx context.Context) (string, error)

Status returns the systemctl status of nginx.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, title, body string) error
}

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

func NewSSHClient(cfg SSHConfig) (*SSHClient, error)

NewSSHClient builds a client from cfg. It requires a host, user, and at least one auth method (key or password).

func (*SSHClient) Close

func (c *SSHClient) Close() error

Close closes the connection.

func (*SSHClient) Connect

func (c *SSHClient) Connect(ctx context.Context) error

Connect establishes the SSH connection (verifying the host key per config).

func (*SSHClient) Download

func (c *SSHClient) Download(ctx context.Context, remotePath, localPath string) error

Download reads remotePath and writes it to localPath (base64 over exec).

func (*SSHClient) ReadRemote

func (c *SSHClient) ReadRemote(ctx context.Context, remotePath string) ([]byte, error)

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

func (c *SSHClient) SetTOFULogger(fn func(host, fingerprint string))

SetTOFULogger installs a callback invoked when a new host key is trusted on first connect.

func (*SSHClient) Upload

func (c *SSHClient) Upload(ctx context.Context, localPath, remotePath string) error

Upload writes localPath's bytes to remotePath via an SSH exec session (base64-streamed to `base64 -d > remote`), avoiding an SFTP dependency.

func (*SSHClient) WriteRemote

func (c *SSHClient) WriteRemote(ctx context.Context, remotePath string, data []byte) error

WriteRemote writes data to remotePath over an exec session.

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 NewServer

func NewServer(ssh *SSHClient) (*Server, error)

NewServer connects to ssh and detects the OS + architecture.

func (*Server) InstallPackage

func (s *Server) InstallPackage(ctx context.Context, pkg string) error

InstallPackage installs pkg using the detected package manager (approval).

func (*Server) RunCommand

func (s *Server) RunCommand(ctx context.Context, cmd string, stream func(string)) (string, error)

RunCommand runs an arbitrary command (approval-gated), streaming output.

func (*Server) ServiceRestart

func (s *Server) ServiceRestart(ctx context.Context, service string) error

ServiceRestart restarts a service (approval-gated).

func (*Server) ServiceStatus

func (s *Server) ServiceStatus(ctx context.Context, service string) (string, error)

ServiceStatus returns the systemctl status of a service.

func (*Server) SetApprover

func (s *Server) SetApprover(fn func(action string) bool)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL