service.go

51 lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
package platform

// Service represents a Docker container to run on a server
type Service struct {
	Name        string
	Image       string
	Command     []string
	Ports       []Port
	Volumes     []Mount
	Env         map[string]string
	Network     string
	Restart     string
	Healthcheck *Healthcheck
	Resources   *Resources
	Logging     *LogConfig
	Privileged  bool
}

// Healthcheck configures container health checking
type Healthcheck struct {
	Cmd         string // Command to run (e.g., "curl -f http://localhost/health")
	Interval    string // Time between checks (e.g., "30s")
	Timeout     string // Time to wait for check to complete (e.g., "10s")
	Retries     int    // Consecutive failures before unhealthy
	StartPeriod string // Grace period before health checks start (e.g., "5s")
}

// Resources configures CPU and memory limits
type Resources struct {
	CPUs   string // CPU limit (e.g., "0.5", "2")
	Memory string // Memory limit (e.g., "512m", "1g")
}

// LogConfig configures container logging
type LogConfig struct {
	Driver  string            // Log driver (e.g., "json-file", "syslog")
	Options map[string]string // Driver-specific options
}

// Port maps a host port to a container port
type Port struct {
	Host      int
	Container int
	Bind      string // Optional bind address (e.g., "127.0.0.1")
}

// Mount binds a host path to a container path
type Mount struct {
	Source string
	Target string
}