composer

package module
v0.0.0-...-555ca75 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MPL-2.0 Imports: 18 Imported by: 0

README

Composer

A lightweight SDK for orchestrating multi-service systems in Go tests and development environments.

Modern systems are complex. Running end-to-end tests or local dev environments often means juggling databases, APIs, message queues, and services that depend on each other.

Composer gives you a semantic Go API to define, orchestrate, and manage these systems. Write your service definitions in code, get type safety, and integrate directly with your test suites.

Quick Example

m := composer.NewManifest()

// Database with health check
m.AddSpec(composer.NewSpec("postgres").
    Image("postgres", "15").
    Port("pg", 5432).
    Env("POSTGRES_PASSWORD", "test").
    HealthCheckHTTP("http://localhost:5432", 200, 1*time.Second, 500*time.Millisecond, 2*time.Second))

// API that depends on healthy database
m.AddSpec(composer.NewSpec("api").
    Image("myapi", "latest").
    Args("--db={{Service \"postgres\" \"pg\"}}").
    DependsOn("postgres", "healthy"))

// Run everything
runtime, _ := composer.NewRuntime(m, &composer.RuntimeConfig{
    LogsLocation: "./logs",
})
runtime.Run(context.Background())

Features

  • Dependency management: Services start in the right order based on dependencies
  • Health checks: Wait for services to be ready before starting dependents
  • Templates: Reference services and ports using {{Service "name" "port"}} syntax
  • Multiple drivers: Run Docker containers or local processes
  • Log streaming: Automatically capture logs to files

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectsTo

type ConnectsTo struct {
	Service string
	Port    string
}

type DependsOn

type DependsOn struct {
	Name      string
	Condition string
}

type Docker

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

func NewDocker

func NewDocker() (*Docker, error)

func (*Docker) RunTask

func (d *Docker) RunTask(ctx context.Context, s *Spec, updater DriverUpdater) (TaskHandle, error)

type Driver

type Driver interface {
	RunTask(ctx context.Context, s *Spec, updater DriverUpdater) (TaskHandle, error)
}

type DriverType

type DriverType string
const (
	DriverTypeDocker DriverType = "docker"
	DriverTypeExec   DriverType = "exec"
)

type DriverUpdater

type DriverUpdater interface {
	TaskUpdated(event TaskStatus)
}

type Exec

type Exec struct {
}

func NewExec

func NewExec() *Exec

func (*Exec) RunTask

func (e *Exec) RunTask(ctx context.Context, s *Spec, updater DriverUpdater) (TaskHandle, error)

type ImagePuller

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

func NewImagePuller

func NewImagePuller(client *client.Client) *ImagePuller

func (*ImagePuller) Pull

func (p *ImagePuller) Pull(ctx context.Context, imageRef string) error

type Manifest

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

func NewManifest

func NewManifest() *Manifest

func (*Manifest) AddSpec

func (m *Manifest) AddSpec(spec *Spec) *Manifest

func (*Manifest) Specs

func (m *Manifest) Specs() []*Spec

func (*Manifest) Validate

func (m *Manifest) Validate() error

type Port

type Port struct {
	Name string
	Port int
}

type Runtime

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

func NewRuntime

func NewRuntime(manifest *Manifest, config *RuntimeConfig) (*Runtime, error)

func (*Runtime) ApplyTemplate

func (r *Runtime) ApplyTemplate(spec *Spec) ([]string, map[string]string, error)

func (*Runtime) NotifyTaskUpdated

func (r *Runtime) NotifyTaskUpdated()

func (*Runtime) Run

func (r *Runtime) Run(ctx context.Context) error

func (*Runtime) Stop

func (r *Runtime) Stop()

type RuntimeConfig

type RuntimeConfig struct {
	LogsLocation string
	Logger       *slog.Logger
}

type Spec

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

func NewSpec

func NewSpec(name string) *Spec

func (*Spec) Args

func (s *Spec) Args(args ...string) *Spec

func (*Spec) ConnectsTo

func (s *Spec) ConnectsTo(service, port string) *Spec

func (*Spec) DependsOn

func (s *Spec) DependsOn(name, condition string) *Spec

func (*Spec) DriverType

func (s *Spec) DriverType() DriverType

func (*Spec) Env

func (s *Spec) Env(key, value string) *Spec

func (*Spec) GetPort

func (s *Spec) GetPort(name string) *Port

func (*Spec) HealthCheckHTTP

func (s *Spec) HealthCheckHTTP(url string, expectedStatus int, initialDelay, interval, timeout time.Duration) *Spec

func (*Spec) Image

func (s *Spec) Image(image, tag string) *Spec

func (*Spec) Name

func (s *Spec) Name() string

func (*Spec) Port

func (s *Spec) Port(name string, port int) *Spec

func (*Spec) UseExec

func (s *Spec) UseExec() *Spec

type TaskHandle

type TaskHandle interface {
	Stop() error
	Logs() (io.ReadCloser, error)
	Err() error
}

type TaskStatus

type TaskStatus string
const (
	TaskStatusPending  TaskStatus = "pending"
	TaskStatusStarting TaskStatus = "starting"
	TaskStatusDeployed TaskStatus = "deployed"
	TaskStatusStopped  TaskStatus = "stopped"
)

type TaskUpdater

type TaskUpdater interface {
	NotifyTaskUpdated()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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