{"modulePath":"github.com/GoCodeAlone/workflow","version":"v0.87.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package dockercompose\n\nPackage dockercompose implements a platform.Provider that maps abstract capability declarations to Docker Compose services, networks, and volumes. It uses only the standard library and invokes docker compose via exec.Command.\n\n## Constants\n\n```go\nconst (\n\tCapContainerRuntime  = \"container_runtime\"\n\tCapDatabase          = \"database\"\n\tCapMessageQueue      = \"message_queue\"\n\tCapNetwork           = \"network\"\n\tCapKubernetesCluster = \"kubernetes_cluster\"\n\tCapLoadBalancer      = \"load_balancer\"\n\tCapNamespace         = \"namespace\"\n\tCapPersistentVolume  = \"persistent_volume\"\n)\n```\nCapability type constants used for mapping abstract declarations to compose resources.\n\n```go\nconst (\n\t// ProviderName is the identifier for the Docker Compose provider.\n\tProviderName = \"docker-compose\"\n\n\t// ProviderVersion is the current version of the Docker Compose provider.\n\tProviderVersion = \"0.1.0\"\n)\n```\n\n## Functions\n\n```go\nfunc NewProvider() platform.Provider\n```\nNewProvider creates a new DockerComposeProvider. This is the ProviderFactory function registered with the engine.\n\n## Types\n\n```go\ntype ComposeCapabilityMapper struct{}\n```\nComposeCapabilityMapper maps abstract capability declarations to Docker Compose resource plans. It understands how to convert capability-level abstractions into the concrete services, networks, and volumes that Docker Compose manages.\n\n```go\nfunc NewCapabilityMapper() *ComposeCapabilityMapper\n```\nNewCapabilityMapper creates a new ComposeCapabilityMapper.\n\n```go\nfunc (m *ComposeCapabilityMapper) CanMap(capabilityType string) bool\n```\nCanMap returns true if this mapper can handle the given capability type.\n\n```go\nfunc (m *ComposeCapabilityMapper) Map(decl platform.CapabilityDeclaration, _ *platform.PlatformContext) ([]platform.ResourcePlan, error)\n```\nMap translates a capability declaration into one or more resource plans.\n\n```go\nfunc (m *ComposeCapabilityMapper) ValidateConstraints(decl platform.CapabilityDeclaration, constraints []platform.Constraint) []platform.ConstraintViolation\n```\nValidateConstraints checks if a capability declaration satisfies all constraints.\n\n```go\ntype ComposeExecutor interface {\n\t// Up starts services defined in the compose file.\n\tUp(ctx context.Context, projectDir string, files ...string) (string, error)\n\n\t// Down stops and removes services defined in the compose file.\n\tDown(ctx context.Context, projectDir string, files ...string) (string, error)\n\n\t// Ps lists running containers for the compose project.\n\tPs(ctx context.Context, projectDir string, files ...string) (string, error)\n\n\t// Logs retrieves logs from compose services.\n\tLogs(ctx context.Context, projectDir string, service string, files ...string) (string, error)\n\n\t// Version returns the docker compose version string.\n\tVersion(ctx context.Context) (string, error)\n\n\t// IsAvailable checks whether docker compose is installed and reachable.\n\tIsAvailable(ctx context.Context) error\n}\n```\nComposeExecutor defines the interface for running docker compose commands. This abstraction allows tests to inject a mock executor.\n\n```go\ntype ComposeFile struct {\n\t// Services maps service names to their definitions.\n\tServices map[string]*ComposeService `yaml:\"services\" json:\"services\"`\n\n\t// Networks maps network names to their definitions.\n\tNetworks map[string]*ComposeNetwork `yaml:\"networks,omitempty\" json:\"networks,omitempty\"`\n\n\t// Volumes maps volume names to their definitions.\n\tVolumes map[string]*ComposeVolume `yaml:\"volumes,omitempty\" json:\"volumes,omitempty\"`\n}\n```\nComposeFile represents the top-level structure of a docker-compose.yml file.\n\n```go\nfunc NewComposeFile() *ComposeFile\n```\nNewComposeFile creates an empty ComposeFile with initialized maps.\n\n```go\nfunc (cf *ComposeFile) AddNetwork(name string, net *ComposeNetwork)\n```\nAddNetwork adds a network to the compose file.\n\n```go\nfunc (cf *ComposeFile) AddService(name string, svc *ComposeService)\n```\nAddService adds a service to the compose file.\n\n```go\nfunc (cf *ComposeFile) AddVolume(name string, vol *ComposeVolume)\n```\nAddVolume adds a volume to the compose file.\n\n```go\nfunc (cf *ComposeFile) MarshalYAML() (string, error)\n```\nMarshalYAML produces a valid docker-compose.yml representation as a string. It uses manual marshaling to control output order and avoid external YAML dependencies (stdlib only).\n\n```go\ntype ComposeNetwork struct {\n\t// Driver is the network driver (e.g., \"bridge\", \"overlay\").\n\tDriver string `yaml:\"driver,omitempty\" json:\"driver,omitempty\"`\n\n\t// External indicates whether the network is externally managed.\n\tExternal bool `yaml:\"external,omitempty\" json:\"external,omitempty\"`\n\n\t// Labels are metadata key-value pairs.\n\tLabels map[string]string `yaml:\"labels,omitempty\" json:\"labels,omitempty\"`\n\n\t// DriverOpts holds driver-specific options.\n\tDriverOpts map[string]string `yaml:\"driver_opts,omitempty\" json:\"driver_opts,omitempty\"`\n\n\t// IPAM configures IP address management.\n\tIPAM *IPAMConfig `yaml:\"ipam,omitempty\" json:\"ipam,omitempty\"`\n}\n```\nComposeNetwork represents a Docker Compose network definition.\n\n```go\ntype ComposeService struct {\n\t// Image is the Docker image to use.\n\tImage string `yaml:\"image\" json:\"image\"`\n\n\t// ContainerName is an explicit container name.\n\tContainerName string `yaml:\"container_name,omitempty\" json:\"container_name,omitempty\"`\n\n\t// Ports maps host ports to container ports.\n\tPorts []string `yaml:\"ports,omitempty\" json:\"ports,omitempty\"`\n\n\t// Environment holds environment variable definitions.\n\tEnvironment map[string]string `yaml:\"environment,omitempty\" json:\"environment,omitempty\"`\n\n\t// Volumes are volume mounts for the service.\n\tVolumes []string `yaml:\"volumes,omitempty\" json:\"volumes,omitempty\"`\n\n\t// Networks lists the networks this service is attached to.\n\tNetworks []string `yaml:\"networks,omitempty\" json:\"networks,omitempty\"`\n\n\t// DependsOn lists services that must start before this one.\n\tDependsOn []string `yaml:\"depends_on,omitempty\" json:\"depends_on,omitempty\"`\n\n\t// Deploy holds deployment configuration like replicas and resource limits.\n\tDeploy *DeployConfig `yaml:\"deploy,omitempty\" json:\"deploy,omitempty\"`\n\n\t// Healthcheck defines a container health check.\n\tHealthcheck *HealthcheckConfig `yaml:\"healthcheck,omitempty\" json:\"healthcheck,omitempty\"`\n\n\t// Restart is the restart policy.\n\tRestart string `yaml:\"restart,omitempty\" json:\"restart,omitempty\"`\n\n\t// Command overrides the default container command.\n\tCommand string `yaml:\"command,omitempty\" json:\"command,omitempty\"`\n\n\t// Labels are metadata key-value pairs applied to the container.\n\tLabels map[string]string `yaml:\"labels,omitempty\" json:\"labels,omitempty\"`\n}\n```\nComposeService represents a single service in docker-compose.yml.\n\n```go\ntype ComposeVolume struct {\n\t// Driver is the volume driver.\n\tDriver string `yaml:\"driver,omitempty\" json:\"driver,omitempty\"`\n\n\t// External indicates whether the volume is externally managed.\n\tExternal bool `yaml:\"external,omitempty\" json:\"external,omitempty\"`\n\n\t// Labels are metadata key-value pairs.\n\tLabels map[string]string `yaml:\"labels,omitempty\" json:\"labels,omitempty\"`\n\n\t// DriverOpts holds driver-specific options.\n\tDriverOpts map[string]string `yaml:\"driver_opts,omitempty\" json:\"driver_opts,omitempty\"`\n}\n```\nComposeVolume represents a Docker Compose volume definition.\n\n```go\ntype DeployConfig struct {\n\t// Replicas is the number of container instances.\n\tReplicas int `yaml:\"replicas,omitempty\" json:\"replicas,omitempty\"`\n\n\t// Resources defines resource limits and reservations.\n\tResources *ResourcesConfig `yaml:\"resources,omitempty\" json:\"resources,omitempty\"`\n}\n```\nDeployConfig holds deployment-related configuration.\n\n```go\ntype DockerComposeProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nDockerComposeProvider implements platform.Provider by mapping abstract capabilities to Docker Compose services, networks, and volumes. It executes docker compose commands via exec.Command and persists state to the local filesystem. No Docker SDK dependency is required.\n\n```go\nfunc NewProviderWithExecutor(exec ComposeExecutor) *DockerComposeProvider\n```\nNewProviderWithExecutor creates a DockerComposeProvider with a custom executor, enabling tests to inject a mock.\n\n```go\nfunc (p *DockerComposeProvider) Capabilities() []platform.CapabilityType\n```\nCapabilities returns the set of capability types this provider supports.\n\n```go\nfunc (p *DockerComposeProvider) Close() error\n```\nClose releases any resources held by the provider.\n\n```go\nfunc (p *DockerComposeProvider) ComposeFilePath() string\n```\nComposeFilePath returns the path to the generated docker-compose.yml.\n\n```go\nfunc (p *DockerComposeProvider) CredentialBroker() platform.CredentialBroker\n```\nCredentialBroker returns nil because Docker Compose does not support credential brokering.\n\n```go\nfunc (p *DockerComposeProvider) Down(ctx context.Context) (string, error)\n```\nDown runs docker compose down for the project.\n\n```go\nfunc (p *DockerComposeProvider) FidelityReports(decls []platform.CapabilityDeclaration) []platform.FidelityReport\n```\nFidelityReports returns fidelity gap reports for capabilities that are not fully implemented by Docker Compose.\n\n```go\nfunc (p *DockerComposeProvider) GenerateComposeFile(plans []platform.ResourcePlan) (*ComposeFile, error)\n```\nGenerateComposeFile builds a ComposeFile from a set of resource plans and writes it to the project directory.\n\n```go\nfunc (p *DockerComposeProvider) Healthy(ctx context.Context) error\n```\nHealthy returns nil if Docker is reachable.\n\n```go\nfunc (p *DockerComposeProvider) Initialize(ctx context.Context, config map[string]any) error\n```\nInitialize validates that Docker is available and sets up the project directory. Config keys:\n\n  - project\\_dir: directory for docker-compose.yml (default: current directory)\n  - state\\_dir: directory for state files (default: project\\_dir/.platform-state)\n\n```go\nfunc (p *DockerComposeProvider) MapCapability(ctx context.Context, decl platform.CapabilityDeclaration, pctx *platform.PlatformContext) ([]platform.ResourcePlan, error)\n```\nMapCapability resolves an abstract capability declaration to provider-specific resource plans using the capability mapper.\n\n```go\nfunc (p *DockerComposeProvider) Name() string\n```\nName returns the provider identifier.\n\n```go\nfunc (p *DockerComposeProvider) ResourceDriver(resourceType string) (platform.ResourceDriver, error)\n```\nResourceDriver returns the driver for a specific resource type.\n\n```go\nfunc (p *DockerComposeProvider) StateStore() platform.StateStore\n```\nStateStore returns the file-system-based state store.\n\n```go\nfunc (p *DockerComposeProvider) Up(ctx context.Context) (string, error)\n```\nUp runs docker compose up for the project.\n\n```go\nfunc (p *DockerComposeProvider) Version() string\n```\nVersion returns the provider version string.\n\n```go\nfunc (p *DockerComposeProvider) WriteComposeFile(cf *ComposeFile) error\n```\nWriteComposeFile writes the compose file to the project directory.\n\n```go\ntype FileStateStore struct {\n\t// contains filtered or unexported fields\n}\n```\nFileStateStore persists platform state as JSON files in a local directory. It implements platform.StateStore for local Docker Compose development.\n\n```go\nfunc NewFileStateStore(baseDir string) (*FileStateStore, error)\n```\nNewFileStateStore creates a FileStateStore rooted at baseDir. The directory is created if it does not exist.\n\n```go\nfunc (s *FileStateStore) AddDependency(_ context.Context, dep platform.DependencyRef) error\n```\nAddDependency records a cross-resource dependency.\n\n```go\nfunc (s *FileStateStore) DeleteResource(_ context.Context, contextPath, resourceName string) error\n```\nDeleteResource removes a resource from state.\n\n```go\nfunc (s *FileStateStore) Dependencies(_ context.Context, contextPath, _ string) ([]platform.DependencyRef, error)\n```\nDependencies returns dependency references for resources that depend on the given resource.\n\n```go\nfunc (s *FileStateStore) GetPlan(_ context.Context, planID string) (*platform.Plan, error)\n```\nGetPlan retrieves an execution plan by ID.\n\n```go\nfunc (s *FileStateStore) GetResource(_ context.Context, contextPath, resourceName string) (*platform.ResourceOutput, error)\n```\nGetResource retrieves a resource's state from the state directory.\n\n```go\nfunc (s *FileStateStore) ListPlans(_ context.Context, _ string, limit int) ([]*platform.Plan, error)\n```\nListPlans lists plans for a context path, ordered by creation time descending.\n\n```go\nfunc (s *FileStateStore) ListResources(_ context.Context, contextPath string) ([]*platform.ResourceOutput, error)\n```\nListResources returns all resources in a context path.\n\n```go\nfunc (s *FileStateStore) Lock(_ context.Context, contextPath string, ttl time.Duration) (platform.LockHandle, error)\n```\nLock acquires an advisory lock for a context path.\n\n```go\nfunc (s *FileStateStore) SavePlan(_ context.Context, plan *platform.Plan) error\n```\nSavePlan persists an execution plan.\n\n```go\nfunc (s *FileStateStore) SaveResource(_ context.Context, contextPath string, output *platform.ResourceOutput) error\n```\nSaveResource persists a resource output to the state directory.\n\n```go\ntype HealthcheckConfig struct {\n\t// Test is the health check command.\n\tTest []string `yaml:\"test\" json:\"test\"`\n\n\t// Interval is the time between health checks.\n\tInterval string `yaml:\"interval,omitempty\" json:\"interval,omitempty\"`\n\n\t// Timeout is the maximum time for a single check.\n\tTimeout string `yaml:\"timeout,omitempty\" json:\"timeout,omitempty\"`\n\n\t// Retries is the number of consecutive failures before unhealthy.\n\tRetries int `yaml:\"retries,omitempty\" json:\"retries,omitempty\"`\n\n\t// StartPeriod is the time to wait before starting checks.\n\tStartPeriod string `yaml:\"start_period,omitempty\" json:\"start_period,omitempty\"`\n}\n```\nHealthcheckConfig defines the container health check.\n\n```go\ntype IPAMConfig struct {\n\t// Driver is the IPAM driver.\n\tDriver string `yaml:\"driver,omitempty\" json:\"driver,omitempty\"`\n\n\t// Config holds per-subnet configuration.\n\tConfig []IPAMPoolConfig `yaml:\"config,omitempty\" json:\"config,omitempty\"`\n}\n```\nIPAMConfig holds IP address management configuration.\n\n```go\ntype IPAMPoolConfig struct {\n\t// Subnet is the subnet CIDR.\n\tSubnet string `yaml:\"subnet,omitempty\" json:\"subnet,omitempty\"`\n}\n```\nIPAMPoolConfig defines a single IPAM subnet pool.\n\n```go\ntype MockCall struct {\n\tMethod string\n\tArgs   []string\n}\n```\nMockCall records a single executor method invocation.\n\n```go\ntype MockExecutor struct {\n\t// UpFn is called when Up is invoked. If nil, returns empty string and no error.\n\tUpFn func(ctx context.Context, projectDir string, files ...string) (string, error)\n\n\t// DownFn is called when Down is invoked.\n\tDownFn func(ctx context.Context, projectDir string, files ...string) (string, error)\n\n\t// PsFn is called when Ps is invoked.\n\tPsFn func(ctx context.Context, projectDir string, files ...string) (string, error)\n\n\t// LogsFn is called when Logs is invoked.\n\tLogsFn func(ctx context.Context, projectDir string, service string, files ...string) (string, error)\n\n\t// VersionFn is called when Version is invoked.\n\tVersionFn func(ctx context.Context) (string, error)\n\n\t// IsAvailableFn is called when IsAvailable is invoked.\n\tIsAvailableFn func(ctx context.Context) error\n\n\t// Calls records all method calls for assertion purposes.\n\tCalls []MockCall\n}\n```\nMockExecutor is a test double for ComposeExecutor that records calls and returns pre-configured responses.\n\n```go\nfunc (m *MockExecutor) Down(ctx context.Context, projectDir string, files ...string) (string, error)\n```\nDown implements ComposeExecutor.\n\n```go\nfunc (m *MockExecutor) IsAvailable(ctx context.Context) error\n```\nIsAvailable implements ComposeExecutor.\n\n```go\nfunc (m *MockExecutor) Logs(ctx context.Context, projectDir string, service string, files ...string) (string, error)\n```\nLogs implements ComposeExecutor.\n\n```go\nfunc (m *MockExecutor) Ps(ctx context.Context, projectDir string, files ...string) (string, error)\n```\nPs implements ComposeExecutor.\n\n```go\nfunc (m *MockExecutor) Up(ctx context.Context, projectDir string, files ...string) (string, error)\n```\nUp implements ComposeExecutor.\n\n```go\nfunc (m *MockExecutor) Version(ctx context.Context) (string, error)\n```\nVersion implements ComposeExecutor.\n\n```go\ntype ResourceSpec struct {\n\t// CPUs is the CPU limit (e.g., \"0.5\", \"2\").\n\tCPUs string `yaml:\"cpus,omitempty\" json:\"cpus,omitempty\"`\n\n\t// Memory is the memory limit (e.g., \"512M\", \"1G\").\n\tMemory string `yaml:\"memory,omitempty\" json:\"memory,omitempty\"`\n}\n```\nResourceSpec defines CPU and memory resource values.\n\n```go\ntype ResourcesConfig struct {\n\t// Limits are the maximum resource constraints.\n\tLimits *ResourceSpec `yaml:\"limits,omitempty\" json:\"limits,omitempty\"`\n\n\t// Reservations are the minimum guaranteed resources.\n\tReservations *ResourceSpec `yaml:\"reservations,omitempty\" json:\"reservations,omitempty\"`\n}\n```\nResourcesConfig holds resource limits and reservations.\n\n```go\ntype ShellExecutor struct {\n\t// ComposeCommand is the base command to use. Defaults to \"docker\" with \"compose\" subcommand.\n\tComposeCommand string\n}\n```\nShellExecutor executes docker compose commands through the system shell.\n\n```go\nfunc NewShellExecutor() *ShellExecutor\n```\nNewShellExecutor creates a ShellExecutor that uses the system docker compose.\n\n```go\nfunc (e *ShellExecutor) Down(ctx context.Context, projectDir string, files ...string) (string, error)\n```\nDown stops and removes services with docker compose down.\n\n```go\nfunc (e *ShellExecutor) IsAvailable(ctx context.Context) error\n```\nIsAvailable checks whether docker compose is installed and reachable.\n\n```go\nfunc (e *ShellExecutor) Logs(ctx context.Context, projectDir string, service string, files ...string) (string, error)\n```\nLogs retrieves logs for a service with docker compose logs.\n\n```go\nfunc (e *ShellExecutor) Ps(ctx context.Context, projectDir string, files ...string) (string, error)\n```\nPs lists containers with docker compose ps.\n\n```go\nfunc (e *ShellExecutor) Up(ctx context.Context, projectDir string, files ...string) (string, error)\n```\nUp starts services with docker compose up -d.\n\n```go\nfunc (e *ShellExecutor) Version(ctx context.Context) (string, error)\n```\nVersion returns the docker compose version.\n\n","path":"github.com/GoCodeAlone/workflow/platform/providers/dockercompose","name":"dockercompose","synopsis":"Package dockercompose implements a platform.Provider that maps abstract capability declarations to Docker Compose services, networks, and volumes.","isRedistributable":true}
