Documentation
¶
Index ¶
- func ParseVersionFromContent(content, imageName string) (int, error)
- func ValidateTempPath(path string) error
- type Client
- func (c *Client) BuildImage(ctx context.Context, buildDir string, version int) error
- func (c *Client) Cleanup(ctx context.Context, path string) error
- func (c *Client) CreateEnvFile(ctx context.Context, serviceName string) error
- func (c *Client) CreateEnvFiles(ctx context.Context, serviceNames []string) error
- func (c *Client) CreateStack(ctx context.Context, composeContent string) error
- func (c *Client) EnsureNetwork(ctx context.Context, name string) error
- func (c *Client) GetContainerStatus(ctx context.Context) (string, error)
- func (c *Client) GetCurrentVersion(ctx context.Context) (int, error)
- func (c *Client) GetEnvFile(ctx context.Context, serviceName string) (string, error)
- func (c *Client) GetLogs(ctx context.Context, follow bool, tail int) error
- func (c *Client) IsServiceRunning(ctx context.Context, serviceName string) (bool, error)
- func (c *Client) MakeTempDir(ctx context.Context) (string, error)
- func (c *Client) PullImage(ctx context.Context, image string) error
- func (c *Client) ReadCompose(ctx context.Context) (string, error)
- func (c *Client) RemoveEnvVar(ctx context.Context, serviceName, key string) error
- func (c *Client) RestartStack(ctx context.Context) error
- func (c *Client) RolloutService(ctx context.Context, serviceName string) error
- func (c *Client) Rsync(ctx context.Context, localPath, remotePath string) error
- func (c *Client) SSH(ctx context.Context, command string) (string, error)
- func (c *Client) SSHInteractive(ctx context.Context, command string) error
- func (c *Client) SetEnvVar(ctx context.Context, serviceName, key, value string) error
- func (c *Client) StackExists(ctx context.Context) (bool, error)
- func (c *Client) StartService(ctx context.Context, serviceName string) error
- func (c *Client) UpdateCompose(ctx context.Context, version int) error
- type CommandExecutor
- type RealExecutor
- type RemoteClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseVersionFromContent ¶ added in v0.1.5
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 ¶
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 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
NewSSHClient creates a client for SSH-only operations (no config required). Used by provision where no ssd.yaml exists yet.
func (*Client) BuildImage ¶
BuildImage builds a Docker image on the remote server
func (*Client) CreateEnvFile ¶
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
CreateEnvFiles creates empty {serviceName}.env files for all given services in a single SSH call. Existing files are not overwritten.
func (*Client) CreateStack ¶
CreateStack creates a stack directory and compose.yaml file with atomic write
func (*Client) EnsureNetwork ¶
EnsureNetwork creates a Docker network if it doesn't exist (idempotent)
func (*Client) GetContainerStatus ¶
GetContainerStatus returns the status of the container
func (*Client) GetCurrentVersion ¶
GetCurrentVersion reads the current image version from compose.yaml on the server. Reuses cached compose content from ReadCompose when available.
func (*Client) GetEnvFile ¶
GetEnvFile reads the {serviceName}.env file from the stack directory
func (*Client) IsServiceRunning ¶
IsServiceRunning checks if a service is running in the stack
func (*Client) MakeTempDir ¶
MakeTempDir creates a temporary directory on the remote server
func (*Client) ReadCompose ¶ added in v0.1.5
ReadCompose 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/UpdateCompose invalidate the cache.
func (*Client) RemoveEnvVar ¶
RemoveEnvVar removes an environment variable from the {serviceName}.env file
func (*Client) RestartStack ¶
RestartStack runs docker compose up -d in the stack directory
func (*Client) RolloutService ¶ added in v0.5.0
RolloutService performs a zero-downtime update using docker rollout
func (*Client) Rsync ¶
Rsync syncs local directory to remote server using git archive. Only git-tracked files are transferred, automatically respecting .gitignore.
func (*Client) SSHInteractive ¶
SSHInteractive runs an SSH command with output streamed to terminal. Output is streamed in real time via stdout/stderr passthrough.
func (*Client) SetEnvVar ¶
SetEnvVar sets or updates an environment variable in the {serviceName}.env file
func (*Client) StackExists ¶
StackExists checks if the stack directory and compose.yaml exist on the remote server
func (*Client) StartService ¶
StartService starts a specific service in the stack
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) RunInteractive ¶
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
UpdateCompose(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)
ReadCompose(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)
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
}
RemoteClient defines the interface for remote operations