services

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

internal/services/manager.go

internal/services/registry.go

Index

Constants

This section is empty.

Variables

View Source
var ComponentRegistry = map[ComponentType]ServiceConfig{
	ComponentSpeechToText: {
		Name:          "whisper",
		Image:         "onerahmet/openai-whisper-asr-webservice:latest",
		PreferredPort: 9000,
		Environment: map[string]string{
			"ASR_MODEL": "base",
		},
	},
	ComponentVectorDB: {
		Name:          "pgvector",
		Image:         "pgvector/pgvector:pg16",
		PreferredPort: 5432,
		Environment: map[string]string{
			"POSTGRES_USER":     "localcloud",
			"POSTGRES_PASSWORD": "localcloud",
			"POSTGRES_DB":       "localcloud",
		},
		Volumes: []string{
			"pgvector_data:/var/lib/postgresql/data",
		},
		HealthCheck: &HealthCheck{
			Type:     "cmd",
			Endpoint: "pg_isready -U localcloud",
			Interval: 10 * time.Second,
			Timeout:  5 * time.Second,
			Retries:  5,
		},
	},
	ComponentStorage: {
		Name:          "minio",
		Image:         "minio/minio:latest",
		PreferredPort: 9000,
		Environment: map[string]string{
			"MINIO_ROOT_USER":     "localcloud",
			"MINIO_ROOT_PASSWORD": "localcloud123",
		},
		Command: []string{"server", "/data", "--console-address", ":9001"},
		Volumes: []string{
			"minio_data:/data",
		},
	},
	ComponentTextToSpeech: {
		Name:          "piper",
		Image:         "lscr.io/linuxserver/piper:latest",
		PreferredPort: 10200,
		Environment: map[string]string{
			"PIPER_VOICE": "en_US-amy-medium",
		},
	},
	ComponentImageGen: {
		Name:          "stable-diffusion-webui",
		Image:         "ghcr.io/automattic/stable-diffusion-webui:latest",
		PreferredPort: 7860,
		Volumes: []string{
			"sd_models:/stable-diffusion-webui/models",
		},
	},
}

ComponentRegistry maps components to their default implementations

Functions

This section is empty.

Types

type ComponentType

type ComponentType string

ComponentType represents abstract component types

const (
	ComponentSpeechToText ComponentType = "speech-to-text"
	ComponentTextToSpeech ComponentType = "text-to-speech"
	ComponentVectorDB     ComponentType = "vector-db"
	ComponentImageGen     ComponentType = "image-generation"
	ComponentStorage      ComponentType = "storage"
)

type HealthCheck

type HealthCheck struct {
	Type     string // http, tcp, cmd
	Endpoint string
	Interval time.Duration
	Timeout  time.Duration
	Retries  int
}

HealthCheck represents health check configuration

type Service

type Service struct {
	Name        string                 `json:"name"`
	Port        int                    `json:"port"`
	ContainerID string                 `json:"container_id"`
	URL         string                 `json:"url"`
	Status      string                 `json:"status"`
	StartedAt   time.Time              `json:"started_at"`
	Health      string                 `json:"health,omitempty"`
	Model       string                 `json:"model,omitempty"`    // For AI services
	Type        string                 `json:"type,omitempty"`     // Service type
	Metadata    map[string]interface{} `json:"metadata,omitempty"` // Additional metadata
}

Service represents a running service

type ServiceConfig

type ServiceConfig struct {
	Name          string
	Image         string
	PreferredPort int
	Environment   map[string]string
	Volumes       []string
	Command       []string
	HealthCheck   *HealthCheck
}

ServiceConfig represents configuration for a service

type ServiceManager

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

ServiceManager manages dynamic service lifecycle

func NewServiceManager

func NewServiceManager(projectName string, docker *docker.Manager, portManager *templates.PortManager) *ServiceManager

NewServiceManager creates a new service manager

func (*ServiceManager) GetPortAllocations

func (sm *ServiceManager) GetPortAllocations() map[int]string

GetPortAllocations returns all port allocations

func (*ServiceManager) GetServiceStatus

func (sm *ServiceManager) GetServiceStatus(name string) (*Service, error)

GetServiceStatus returns the status of a specific service

func (*ServiceManager) GetServiceURL

func (sm *ServiceManager) GetServiceURL(name string) (string, error)

GetServiceURL returns the URL for a service

func (*ServiceManager) IsVectorEnabled

func (sm *ServiceManager) IsVectorEnabled(serviceName string) bool

IsVectorEnabled checks if service is vector-enabled

func (*ServiceManager) ListServices

func (sm *ServiceManager) ListServices() []Service

ListServices returns all running services

func (*ServiceManager) ParseComponentName

func (sm *ServiceManager) ParseComponentName(input string) (string, *ServiceConfig)

ParseComponentName converts various inputs to component type or service name

func (*ServiceManager) RestartService

func (sm *ServiceManager) RestartService(name string) error

RestartService restarts a service

func (*ServiceManager) StartService

func (sm *ServiceManager) StartService(name string, config ServiceConfig) error

StartService starts a service dynamically

func (*ServiceManager) StopService

func (sm *ServiceManager) StopService(name string) error

StopService stops a running service

func (*ServiceManager) WithCustomConfig

func (sm *ServiceManager) WithCustomConfig(name string, config ServiceConfig) error

WithCustomConfig allows using custom service configuration

type ServiceRegistry

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

ServiceRegistry manages service registration and discovery

func NewServiceRegistry

func NewServiceRegistry(projectPath string) *ServiceRegistry

NewServiceRegistry creates a new service registry

func (*ServiceRegistry) Clear

func (sr *ServiceRegistry) Clear() error

Clear removes all services from the registry

func (*ServiceRegistry) Get

func (sr *ServiceRegistry) Get(serviceName string) (*Service, error)

Get returns a service by name

func (*ServiceRegistry) GetByContainerID

func (sr *ServiceRegistry) GetByContainerID(containerID string) (*Service, error)

GetByContainerID returns a service by container ID

func (*ServiceRegistry) GetURL

func (sr *ServiceRegistry) GetURL(serviceName string) (string, error)

GetURL returns the URL for a service

func (*ServiceRegistry) List

func (sr *ServiceRegistry) List() []Service

List returns all registered services

func (*ServiceRegistry) ListByStatus

func (sr *ServiceRegistry) ListByStatus(status string) []Service

ListByStatus returns services with a specific status

func (*ServiceRegistry) Register

func (sr *ServiceRegistry) Register(service Service) error

Register adds a new service to the registry

func (*ServiceRegistry) Unregister

func (sr *ServiceRegistry) Unregister(serviceName string) error

Unregister removes a service from the registry

func (*ServiceRegistry) UpdateHealth

func (sr *ServiceRegistry) UpdateHealth(serviceName, health string) error

UpdateHealth updates the health status of a service

func (*ServiceRegistry) UpdateStatus

func (sr *ServiceRegistry) UpdateStatus(serviceName, status string) error

UpdateStatus updates the status of a service

Directories

Path Synopsis
internal/services/postgres/client.go
internal/services/postgres/client.go
internal/services/vectordb/interface.go
internal/services/vectordb/interface.go
providers/pgvector
internal/services/vectordb/providers/pgvector/pgvector.go
internal/services/vectordb/providers/pgvector/pgvector.go

Jump to

Keyboard shortcuts

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