remote

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseVersionFromContent added in v0.1.5

func ParseVersionFromContent(content, imageName string) (int, error)

ParseVersionFromContent extracts the version number from compose.yaml content imageName should be the full image name prefix (e.g., "ssd-myapp-api" without the :version tag) Returns 0, nil if no version found; error on parse failure

func ValidateTempPath

func ValidateTempPath(path string) error

ValidateTempPath validates that a path is safe for temporary operations

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client handles remote operations via SSH

func NewClient

func NewClient(cfg *config.Config) *Client

NewClient creates a new remote client with the default executor

func NewClientWithExecutor

func NewClientWithExecutor(cfg *config.Config, executor CommandExecutor) *Client

NewClientWithExecutor creates a client with a custom executor (for testing)

func NewSSHClient added in v0.6.0

func NewSSHClient(server string) *Client

NewSSHClient creates a client for SSH-only operations (no config required). Used by provision where no ssd.yaml exists yet.

func (*Client) BuildImage

func (c *Client) BuildImage(ctx context.Context, buildDir string, version int) error

BuildImage builds a Docker image on the remote server

func (*Client) Cleanup

func (c *Client) Cleanup(ctx context.Context, path string) error

Cleanup removes a directory on the remote server

func (*Client) CopyFiles added in v0.9.0

func (c *Client) CopyFiles(ctx context.Context, files map[string]string) error

CopyFiles copies local files to the stack directory on the remote server. files maps absolute local paths to container mount paths; only the basename is used for the remote filename in the stack directory. Files are transferred via base64 encoding over SSH, independent of git tracking.

func (*Client) CreateEnvFile

func (c *Client) CreateEnvFile(ctx context.Context, serviceName string) error

CreateEnvFile creates an empty {serviceName}.env file with mode 600 in the stack directory. Existing files are not overwritten, preserving any env vars already set.

func (*Client) CreateEnvFiles added in v0.1.5

func (c *Client) CreateEnvFiles(ctx context.Context, serviceNames []string) error

CreateEnvFiles creates empty {serviceName}.env files for all given services in a single SSH call. Existing files are not overwritten.

func (*Client) CreateStack

func (c *Client) CreateStack(ctx context.Context, composeContent string) error

CreateStack creates a stack directory and compose.yaml file with atomic write

func (*Client) EnsureNetwork

func (c *Client) EnsureNetwork(ctx context.Context, name string) error

EnsureNetwork creates a Docker network if it doesn't exist (idempotent)

func (*Client) GetContainerStatus

func (c *Client) GetContainerStatus(ctx context.Context) (string, error)

GetContainerStatus returns the status of the container

func (*Client) GetCurrentVersion

func (c *Client) GetCurrentVersion(ctx context.Context) (int, error)

GetCurrentVersion reads the current image version from compose.yaml on the server. Reuses cached compose content from ReadManifest when available.

func (*Client) GetEnvFile

func (c *Client) GetEnvFile(ctx context.Context, serviceName string) (string, error)

GetEnvFile reads the {serviceName}.env file from the stack directory

func (*Client) GetLogs

func (c *Client) GetLogs(ctx context.Context, follow bool, tail int) error

GetLogs returns logs from the container

func (*Client) IsServiceRunning

func (c *Client) IsServiceRunning(ctx context.Context, serviceName string) (bool, error)

IsServiceRunning checks if a service is running in the stack

func (*Client) MakeTempDir

func (c *Client) MakeTempDir(ctx context.Context) (string, error)

MakeTempDir creates a temporary directory on the remote server

func (*Client) PullImage

func (c *Client) PullImage(ctx context.Context, image string) error

PullImage pulls a Docker image on the remote server

func (*Client) ReadManifest added in v0.11.0

func (c *Client) ReadManifest(ctx context.Context) (string, error)

ReadManifest reads the current compose.yaml content from the remote server. Returns empty string (no error) if the file does not exist. Results are cached per Client instance; writes via CreateStack/UpdateManifest invalidate the cache.

func (*Client) RemoveEnvVar

func (c *Client) RemoveEnvVar(ctx context.Context, serviceName, key string) error

RemoveEnvVar removes an environment variable from the {serviceName}.env file

func (*Client) RestartStack

func (c *Client) RestartStack(ctx context.Context) error

RestartStack runs docker compose up -d in the stack directory

func (*Client) RolloutService added in v0.5.0

func (c *Client) RolloutService(ctx context.Context, serviceName string) error

RolloutService performs a zero-downtime update using docker rollout. Ensures the docker-rollout plugin is installed before attempting the rollout.

func (*Client) Rsync

func (c *Client) Rsync(ctx context.Context, localPath, remotePath string) error

Rsync syncs local directory to remote server using git archive. Only git-tracked files are transferred, automatically respecting .gitignore.

func (*Client) SSH

func (c *Client) SSH(ctx context.Context, command string) (string, error)

SSH executes a command on the remote server

func (*Client) SSHInteractive

func (c *Client) SSHInteractive(ctx context.Context, command string) error

SSHInteractive runs an SSH command with output streamed to terminal. Output is streamed in real time via stdout/stderr passthrough.

func (*Client) SetEnvVar

func (c *Client) SetEnvVar(ctx context.Context, serviceName, key, value string) error

SetEnvVar sets or updates an environment variable in the {serviceName}.env file

func (*Client) StackExists

func (c *Client) StackExists(ctx context.Context) (bool, error)

StackExists checks if the stack directory and compose.yaml exist on the remote server

func (*Client) StartService

func (c *Client) StartService(ctx context.Context, serviceName string) error

StartService starts a specific service in the stack

func (*Client) UpdateManifest added in v0.11.0

func (c *Client) UpdateManifest(ctx context.Context, version int) error

UpdateManifest updates the image tag in compose.yaml via server-side sed. Single SSH call instead of read-modify-write.

func (*Client) UploadEnvFile added in v0.14.0

func (c *Client) UploadEnvFile(ctx context.Context, serviceName, localPath string) error

UploadEnvFile replaces {serviceName}.env on the server with the content of localPath. Written with mode 600. Empty files are accepted. Caller must have validated localPath (see config.ValidateEnvFile) before invoking.

type CommandExecutor

type CommandExecutor interface {
	// Run executes a command with a 5 minute timeout and returns stdout
	Run(ctx context.Context, name string, args ...string) (string, error)
	// RunInteractive executes a command with a 30 minute timeout and stdout/stderr connected to terminal
	RunInteractive(ctx context.Context, name string, args ...string) error
}

CommandExecutor abstracts command execution for testing

type RealExecutor

type RealExecutor struct{}

RealExecutor implements CommandExecutor using real exec.Command

func NewRealExecutor

func NewRealExecutor() *RealExecutor

NewRealExecutor creates a new RealExecutor

func (*RealExecutor) Run

func (e *RealExecutor) Run(ctx context.Context, name string, args ...string) (string, error)

Run executes a command with a 5 minute timeout and returns the output

func (*RealExecutor) RunInteractive

func (e *RealExecutor) RunInteractive(ctx context.Context, name string, args ...string) error

RunInteractive executes a command with a 30 minute timeout and output streamed to terminal

type RemoteClient

type RemoteClient interface {
	SSH(ctx context.Context, command string) (string, error)
	SSHInteractive(ctx context.Context, command string) error
	Rsync(ctx context.Context, localPath, remotePath string) error
	GetCurrentVersion(ctx context.Context) (int, error)
	BuildImage(ctx context.Context, buildDir string, version int) error
	UpdateManifest(ctx context.Context, version int) error
	RestartStack(ctx context.Context) error
	GetContainerStatus(ctx context.Context) (string, error)
	GetLogs(ctx context.Context, follow bool, tail int) error
	Cleanup(ctx context.Context, path string) error
	MakeTempDir(ctx context.Context) (string, error)
	StackExists(ctx context.Context) (bool, error)
	ReadManifest(ctx context.Context) (string, error)
	IsServiceRunning(ctx context.Context, serviceName string) (bool, error)
	EnsureNetwork(ctx context.Context, name string) error
	CreateEnvFile(ctx context.Context, serviceName string) error
	CreateEnvFiles(ctx context.Context, serviceNames []string) error
	GetEnvFile(ctx context.Context, serviceName string) (string, error)
	UploadEnvFile(ctx context.Context, serviceName, localPath string) error
	SetEnvVar(ctx context.Context, serviceName, key, value string) error
	RemoveEnvVar(ctx context.Context, serviceName, key string) error
	CreateStack(ctx context.Context, composeContent string) error
	PullImage(ctx context.Context, image string) error
	StartService(ctx context.Context, serviceName string) error
	RolloutService(ctx context.Context, serviceName string) error
	CopyFiles(ctx context.Context, files map[string]string) error
}

RemoteClient defines the interface for remote operations

Jump to

Keyboard shortcuts

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