Documentation
¶
Index ¶
- func BuildArgFlags(buildArgs map[string]string) string
- func BuildSecretsScript(secrets map[string]string) (prelude, flags string)
- func ImageTag(image string) string
- 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) CopyFiles(ctx context.Context, files map[string]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) 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) GetStatus(ctx context.Context, serviceName string) ([]ServiceStatus, 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) ReadManifest(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) SetOutput(stdout, stderr io.Writer)
- func (c *Client) StackExists(ctx context.Context) (bool, error)
- func (c *Client) StartService(ctx context.Context, serviceName string) error
- func (c *Client) UpdateManifest(ctx context.Context, version int) error
- func (c *Client) UploadEnvFile(ctx context.Context, serviceName, localPath string) error
- type CommandExecutor
- type RealExecutor
- type RemoteClient
- type ServiceStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildArgFlags ¶ added in v0.23.0
BuildArgFlags renders a resolved build_args map as shell-escaped `--build-arg K=V` flags, sorted by key so the command is identical across deploys. Shared by both runtimes.
func BuildSecretsScript ¶ added in v0.24.0
BuildSecretsScript renders the shell prelude that materialises each build secret on the server, plus the matching `--secret id=K,src=...` flags. Returns two empty strings when there is nothing to do.
The files are written into a private `mktemp -d` directory, deliberately NOT inside the build context: a Dockerfile with `COPY . .` would otherwise bake them into the image, which is exactly what --secret exists to prevent. `umask 077` makes the directory and files unreadable to other users, and the EXIT/HUP/INT/TERM trap removes them however the build ends — including a dropped SSH connection.
Values reach the server base64-encoded rather than as plain text. That is the same transport UploadEnvFile already uses; it is encoding, not protection, so the value is still briefly visible in `ps` on the server. What it does buy is the thing this feature is for: the credential never reaches an image layer or `docker history`.
func ImageTag ¶ added in v0.21.0
ImageTag extracts the tag from an image reference. A registry port (registry.local:5000/web) is not a tag, so only the final path element is inspected. Untagged images report "-".
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 ¶
func (c *Client) BuildImage(ctx context.Context, buildDir string, version int, buildArgs, buildSecrets map[string]string) error
BuildImage builds a Docker image on the remote server.
buildArgs and buildSecrets are already-resolved values (see deploy.resolveBuildInputs); they may be credentials, so they are shell-escaped and never logged here. Secrets additionally travel via BuildKit --secret, which keeps them out of the image and its history.
func (*Client) CopyFiles ¶ added in v0.9.0
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 ¶
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) GetCurrentVersion ¶
GetCurrentVersion reads the current image version from compose.yaml on the server. Reuses cached compose content from ReadManifest when available.
func (*Client) GetEnvFile ¶
GetEnvFile reads the {serviceName}.env file from the stack directory
func (*Client) GetStatus ¶ added in v0.21.0
GetStatus returns one row per running container in the stack. An empty serviceName covers the whole stack; a named service narrows it to that service's containers.
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) ReadManifest ¶ added in v0.11.0
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 ¶
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. Ensures the docker-rollout plugin is installed before attempting the 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) SetOutput ¶ added in v0.19.0
SetOutput delegates to the underlying executor. nil writers restore the default os.Stdout/os.Stderr. Used by ui.Reporter Stream() to capture subprocess output into a tail window.
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
func (*Client) UpdateManifest ¶ added in v0.11.0
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
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. By
// default stdout/stderr go to the user's terminal; SetOutput
// redirects them (used by ui.Reporter's Stream tail window).
RunInteractive(ctx context.Context, name string, args ...string) error
// SetOutput overrides the writers used by RunInteractive. Passing nil
// for a writer restores the default (os.Stdout / os.Stderr).
SetOutput(stdout, stderr io.Writer)
}
CommandExecutor abstracts command execution for testing.
type RealExecutor ¶
type RealExecutor struct {
// contains filtered or unexported fields
}
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 the configured writers (defaults: os.Stdout / os.Stderr).
func (*RealExecutor) SetOutput ¶ added in v0.19.0
func (e *RealExecutor) SetOutput(stdout, stderr io.Writer)
SetOutput overrides the interactive-command writers. nil restores the default (os.Stdout / os.Stderr). Not safe for concurrent use — callers are expected to set, run, and restore from a single goroutine.
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, buildArgs, buildSecrets map[string]string) error
UpdateManifest(ctx context.Context, version int) error
RestartStack(ctx context.Context) 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
// SetOutput redirects the writers used by SSHInteractive (and anything
// built on top of it: BuildImage, PullImage, StartService, RolloutService).
// Passing nil restores os.Stdout/os.Stderr. Used by ui.Reporter to feed
// subprocess output into a tail window.
SetOutput(stdout, stderr io.Writer)
}
RemoteClient defines the interface for remote operations
type ServiceStatus ¶ added in v0.21.0
type ServiceStatus struct {
Service string
State string // running, exited, restarting, pending, ...
Health string // healthy, unhealthy, starting, not ready — empty when unknown
Uptime string // compact: 15s, 18m, 3h, 2d — "-" when not running
Version string // image tag — "-" when the image is untagged
Ports string // published host→container ports — empty when none
}
ServiceStatus is one running instance of a service, as observed on the server. Both runtimes fill the same shape so `ssd status` renders one table regardless of runtime.
func ParseComposeStatus ¶ added in v0.21.0
func ParseComposeStatus(output string) ([]ServiceStatus, error)
ParseComposeStatus turns `docker compose ps --format json` output into rows sorted by service name. Compose emits a JSON array on some versions and newline-delimited objects on others, so both are accepted.