Documentation
¶
Index ¶
- Constants
- func CollectLogs(ctx context.Context, service Service) (logs.LogStreams, error)
- func MergedLogs(ctx context.Context, service Service) (io.ReadCloser, error)
- func Run(ctx context.Context, stack *Stack, fn func(context.Context) error) error
- func WaitForHTTP(ctx context.Context, url string, statusCode int, timeout time.Duration) error
- func WaitForLogText(ctx context.Context, reader io.Reader, text string, timeout time.Duration) error
- func WaitForTCP(ctx context.Context, host string, port string, timeout time.Duration) error
- func WaitFunc(ctx context.Context, timeout time.Duration, interval time.Duration, ...) error
- type Connectable
- type ContainerService
- func (s *ContainerService) Cleanup(ctx context.Context) error
- func (s *ContainerService) Container() *scaffoldcontainer.Container
- func (s *ContainerService) Create(ctx context.Context) error
- func (s *ContainerService) Endpoints() map[string]string
- func (s *ContainerService) Logs(ctx context.Context) (logs.LogStreams, error)
- func (s *ContainerService) Name() string
- func (s *ContainerService) SetLabels(labels map[string]string)
- func (s *ContainerService) SetNamePrefix(prefix string)
- func (s *ContainerService) SetNetwork(name string)
- type ContainerServiceOption
- func WithEndpoint(name string, scheme string, port string) ContainerServiceOption
- func WithHTTPReady(port string, path string, statusCode int, timeout time.Duration) ContainerServiceOption
- func WithName(name string) ContainerServiceOption
- func WithTCPReady(port string, timeout time.Duration) ContainerServiceOption
- type ContainerStatus
- type EndpointProvider
- type EnvProvider
- type LabelAttachable
- type NamePrefixAttachable
- type NetworkAttachable
- type NetworkStatus
- type ResourceStatus
- type Service
- type Stack
- func (s *Stack) Cleanup(ctx context.Context) error
- func (s *Stack) Create(ctx context.Context) error
- func (s *Stack) Down(ctx context.Context) error
- func (s *Stack) Endpoint(name string) (string, bool)
- func (s *Stack) Endpoints() map[string]string
- func (s *Stack) Env() map[string]string
- func (s *Stack) IsRunning(ctx context.Context) (bool, error)
- func (s *Stack) Labels() map[string]string
- func (s *Stack) Logs(ctx context.Context) (logs.LogStreams, error)
- func (s *Stack) Name() string
- func (s *Stack) Resources(ctx context.Context) (ResourceStatus, error)
- func (s *Stack) RunningContainers(ctx context.Context) ([]ContainerStatus, error)
- func (s *Stack) Service(name string) (Service, bool)
- func (s *Stack) Services() []Service
- func (s *Stack) SetLabels(labels map[string]string)
- func (s *Stack) SetNamePrefix(prefix string)
- func (s *Stack) SetNetwork(name string)
- func (s *Stack) Summary() string
- func (s *Stack) WriteEnvFile(path string) error
- type StackOption
- func WithInheritedLabel(label string, value string) StackOption
- func WithInheritedLabels(labels map[string]string) StackOption
- func WithNamePrefix(prefix string) StackOption
- func WithRunID(runID string) StackOption
- func WithServices(services ...Service) StackOption
- func WithSharedNetwork() StackOption
- type VolumeStatus
Constants ¶
const ( LabelManagedBy = "scaffold.managed-by" LabelStack = "scaffold.stack" LabelService = "scaffold.service" LabelRunID = "scaffold.run-id" )
Variables ¶
This section is empty.
Functions ¶
func CollectLogs ¶
CollectLogs returns the named log streams exposed by a service. For stacks, this recursively returns streams for child services and containers.
func MergedLogs ¶
MergedLogs returns a single reader containing all logs exposed by a service. Use CollectLogs when callers need to choose individual named streams.
func Run ¶
Run creates a stack with ctx, runs fn, and then cleans the stack up. Cleanup is attempted even if fn returns an error.
func WaitForHTTP ¶
WaitForHTTP waits until the URL returns the expected HTTP status code, or until the timeout is reached.
func WaitForLogText ¶
func WaitForLogText(ctx context.Context, reader io.Reader, text string, timeout time.Duration) error
WaitForLogText scans a reader until the requested text appears. This is useful for containers that only advertise readiness through logs.
func WaitForTCP ¶
WaitForTCP waits until a TCP connection can be opened to host:port, or until the timeout is reached.
Types ¶
type Connectable ¶
type Connectable[T any] interface { Connect() (T, error) ConnectWithTimeout(timeout time.Duration) (T, error) }
Connectable is implemented by harnesses that can return a typed client or connection after the service is running.
type ContainerService ¶
type ContainerService struct {
// contains filtered or unexported fields
}
ContainerService is a small service wrapper around Container. It is for simple services that do not need a toolbox package or custom typed clients.
func FromContainer ¶
func FromContainer(container *scaffoldcontainer.Container, options ...ContainerServiceOption) (*ContainerService, error)
FromContainer wraps a plain Docker container as a Service. The service name defaults to the container name. Use WithName when the container is unnamed or when the scaffold service should have a different logical name than the Docker container.
func (*ContainerService) Container ¶
func (s *ContainerService) Container() *scaffoldcontainer.Container
func (*ContainerService) Endpoints ¶
func (s *ContainerService) Endpoints() map[string]string
func (*ContainerService) Logs ¶
func (s *ContainerService) Logs(ctx context.Context) (logs.LogStreams, error)
func (*ContainerService) Name ¶
func (s *ContainerService) Name() string
func (*ContainerService) SetLabels ¶
func (s *ContainerService) SetLabels(labels map[string]string)
func (*ContainerService) SetNamePrefix ¶
func (s *ContainerService) SetNamePrefix(prefix string)
func (*ContainerService) SetNetwork ¶
func (s *ContainerService) SetNetwork(name string)
type ContainerServiceOption ¶
type ContainerServiceOption func(*ContainerService)
func WithEndpoint ¶
func WithEndpoint(name string, scheme string, port string) ContainerServiceOption
WithEndpoint exposes a named endpoint built from a published container port.
func WithHTTPReady ¶
func WithHTTPReady(port string, path string, statusCode int, timeout time.Duration) ContainerServiceOption
WithHTTPReady waits for an HTTP status code on the requested container port after the container starts.
func WithName ¶
func WithName(name string) ContainerServiceOption
WithName sets the scaffold service name for a container-backed service. It is useful when the Docker container is unnamed or when the service name should differ from the Docker container name.
func WithTCPReady ¶
func WithTCPReady(port string, timeout time.Duration) ContainerServiceOption
WithTCPReady waits until the requested container port accepts TCP connections.
type ContainerStatus ¶
type EndpointProvider ¶
EndpointProvider is implemented by services that can expose named local endpoints after creation.
type EnvProvider ¶
EnvProvider is implemented by services that can export environment variables for applications, tests, or CLI commands.
type LabelAttachable ¶
LabelAttachable is implemented by harnesses that can receive Docker labels from a parent stack before they are created.
type NamePrefixAttachable ¶
type NamePrefixAttachable interface {
SetNamePrefix(prefix string)
}
NamePrefixAttachable is implemented by harnesses that can apply a stack name prefix to Docker resources before they are created.
type NetworkAttachable ¶
type NetworkAttachable interface {
SetNetwork(name string)
}
NetworkAttachable is implemented by harnesses that can join a shared Docker network before they are created.
type NetworkStatus ¶
type ResourceStatus ¶
type ResourceStatus struct {
Containers []ContainerStatus
Networks []NetworkStatus
Volumes []VolumeStatus
}
type Service ¶
type Service interface {
Name() string
Create(ctx context.Context) error
Cleanup(ctx context.Context) error
Logs(ctx context.Context) (logs.LogStreams, error)
}
Service is the minimum lifecycle interface used by Stack. Services only need a name, a create step, and a cleanup step to be composable.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack is a simple ordered collection of service groups. Services passed in the same WithServices call are created in parallel. Multiple WithServices calls are created in the order they are applied.
func NewStack ¶
func NewStack(name string, options ...StackOption) *Stack
NewStack builds a stack with the provided options. A stack can contain any service harness that implements the Service interface.
func (*Stack) Cleanup ¶
Cleanup handles service groups in reverse creation order. Services that were created in the same group are cleaned up in parallel.
func (*Stack) Create ¶
Create creates each service group in the order it was added. Services in the same group are created in parallel. If a service fails, services that were already created are cleaned up.
func (*Stack) Down ¶
Down removes Docker resources that match this stack's labels. Unlike Cleanup, Down does not require this process to have created the stack. It is intended for CLI and cross-session cleanup.
func (*Stack) Env ¶
Env returns environment variables contributed by services in the stack. Later services overwrite earlier services if they use the same key.
func (*Stack) IsRunning ¶
IsRunning returns true if Docker has at least one running container that matches this stack's labels.
func (*Stack) Labels ¶
Labels returns the labels that identify the stack in Docker. Service labels are added separately for each child service.
func (*Stack) Logs ¶
Logs returns named log streams for every service in the stack. Child stack and service names are used as path segments, so callers can choose streams such as "api" or "data.postgres".
func (*Stack) Resources ¶
func (s *Stack) Resources(ctx context.Context) (ResourceStatus, error)
Resources returns Docker containers, networks, and volumes that match this stack's labels. This is the broad discovery API for determining which Docker resources belong to a stack.
func (*Stack) RunningContainers ¶
func (s *Stack) RunningContainers(ctx context.Context) ([]ContainerStatus, error)
RunningContainers returns Docker containers that match this stack's labels. This is how a defined Go stack can answer whether its matching local environment is already running.
func (*Stack) Service ¶
Service returns a service by name if it exists in the stack; nil and false if not.
func (*Stack) SetLabels ¶
SetLabels merges labels inherited from a parent stack. Child services and child stacks receive these labels before they are created.
func (*Stack) SetNamePrefix ¶
SetNamePrefix receives a parent stack's prefix. Child services receive that prefix plus this stack's name when the stack is created.
func (*Stack) SetNetwork ¶
SetNetwork pushes an inherited Docker network into this stack and its children. A stack with an inherited network does not own that network. Children services should adopt the network upon start.
func (*Stack) Summary ¶
Summary returns a human-readable description of the stack service groups and known endpoints.
func (*Stack) WriteEnvFile ¶
WriteEnvFile writes stack environment variables to a dotenv-style file.
type StackOption ¶
type StackOption func(*Stack)
StackOption configures a stack at construction time.
func WithInheritedLabel ¶
func WithInheritedLabel(label string, value string) StackOption
WithInheritedLabel adds a key/value inherited label. Inherited labels are pushed down to child services and child stacks.
func WithInheritedLabels ¶
func WithInheritedLabels(labels map[string]string) StackOption
WithInheritedLabels adds multiple inherited labels to the stack.
func WithNamePrefix ¶
func WithNamePrefix(prefix string) StackOption
WithNamePrefix prefixes Docker resource names for services that support SetNamePrefix. For stack "app" and prefix "dev", child service resources receive the prefix "dev-app".
func WithRunID ¶
func WithRunID(runID string) StackOption
WithRunID sets the run identity used when finding existing Docker resources for this stack. If not set, a run id is generated when Create starts.
func WithServices ¶
func WithServices(services ...Service) StackOption
WithServices adds a group of services to the stack. Services passed in the same call are created in parallel. Separate WithServices calls are created in call order.
func WithSharedNetwork ¶
func WithSharedNetwork() StackOption
WithSharedNetwork creates a Docker network for the stack and attaches services that support SetNetwork before they are created.
