Help us shape the future of Go! Take the 2026 Go Developer Survey

service

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package service provides platform-agnostic service domain models.

Package service provides platform-agnostic service domain models.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BindOptions

type BindOptions struct {
	Propagation string // "private", "shared", "slave", "rshared", "rslave"
	SELinux     string // "z" (shared) or "Z" (private) for SELinux relabeling
}

BindOptions represents bind mount options.

type Build

type Build struct {
	Context             string            // Build context path
	Dockerfile          string            // Dockerfile path
	Target              string            // Build target
	Args                map[string]string // Build arguments
	Labels              map[string]string // Image labels
	CacheFrom           []string          // Cache sources
	Pull                bool              // Always pull base image
	Networks            []string          // Networks for build
	Volumes             []string          // Volumes for build
	Secrets             []string          // Secrets for build
	Tags                []string          // Image tags
	Annotations         []string          // Image annotations
	SetWorkingDirectory string            // Working directory for build
	PodmanArgs          []string          // Additional Podman build args
}

Build represents container build configuration.

func (*Build) Validate

func (b *Build) Validate() error

Validate validates build configuration.

type Container

type Container struct {
	Image             string            // Container image (name:tag)
	Command           []string          // Override CMD
	Args              []string          // Additional arguments
	Env               map[string]string // Environment variables
	EnvFiles          []string          // Environment files to load
	WorkingDir        string            // Working directory
	User              string            // User to run as
	Group             string            // Group to run as
	Ports             []Port            // Port mappings
	Mounts            []Mount           // File/directory mounts
	Resources         Resources         // Resource constraints
	RestartPolicy     RestartPolicy     // Restart behavior
	Healthcheck       *Healthcheck      // Health check configuration
	Security          Security          // Security settings
	Build             *Build            // Build configuration (if image needs building)
	Labels            map[string]string // Container labels
	Hostname          string            // Container hostname
	ContainerName     string            // Explicit container name
	Entrypoint        []string          // Override ENTRYPOINT
	Init              bool              // Run init inside container
	ReadOnly          bool              // Read-only root filesystem
	Logging           Logging           // Logging configuration
	Secrets           []Secret          // Secrets to mount
	EnvSecrets        map[string]string // Secrets to expose as environment variables (secret_name -> env_var_name)
	Network           NetworkMode       // Network mode configuration
	Tmpfs             []string          // Tmpfs mounts
	Ulimits           []Ulimit          // Ulimit settings
	Sysctls           map[string]string // Sysctl settings
	UserNS            string            // User namespace mode
	PodmanArgs        []string          // Additional Podman arguments
	PidsLimit         int64             // Maximum PIDs
	ExtraHosts        []string          // Extra host-to-IP mappings in "hostname:ip" format
	DNS               []string          // Custom DNS servers
	DNSSearch         []string          // DNS search domains
	DNSOptions        []string          // DNS options
	Devices           []string          // Device mappings in "host:container" or "host:container:permissions" format
	DeviceCgroupRules []string          // Device cgroup rules in "type major:minor permissions" format (e.g., "c 13:* rmw")
	PidMode           string            // PID namespace mode
	IpcMode           string            // IPC namespace mode
	CgroupMode        string            // Cgroup namespace mode
	StopSignal        string            // Stop signal (e.g., "SIGTERM")
	StopGracePeriod   time.Duration     // Grace period before forced kill
}

Container represents container runtime configuration.

func (*Container) Validate

func (c *Container) Validate() error

Validate validates container configuration.

type ExternalDependency added in v0.25.0

type ExternalDependency struct {
	Project         string // Project name (validated, not sanitized)
	Service         string // Service name (validated, not sanitized)
	Optional        bool   // If true, warn if missing; if false, error
	ExistsInRuntime bool   // Populated during validation (batch-aware)
}

ExternalDependency represents a dependency on a service in another project.

type Healthcheck

type Healthcheck struct {
	Test          []string      // Health check command
	Interval      time.Duration // Check interval
	Timeout       time.Duration // Check timeout
	Retries       int           // Consecutive failures before unhealthy
	StartPeriod   time.Duration // Initialization grace period
	StartInterval time.Duration // Interval during start period
}

Healthcheck represents a health check configuration.

func (*Healthcheck) Validate

func (h *Healthcheck) Validate() error

Validate validates healthcheck configuration.

type IPAM

type IPAM struct {
	Driver  string            // IPAM driver
	Config  []IPAMConfig      // IPAM configurations
	Options map[string]string // Driver options
}

IPAM represents IP address management configuration.

func (*IPAM) Validate

func (i *IPAM) Validate() error

Validate validates IPAM configuration.

type IPAMConfig

type IPAMConfig struct {
	Subnet  string // Subnet in CIDR format
	Gateway string // Gateway address
	IPRange string // IP range for allocation
}

IPAMConfig represents a single IPAM configuration.

type InitContainer added in v0.24.0

type InitContainer struct {
	Image   string            // Container image (required)
	Command []string          // Command to run (required)
	Env     map[string]string // Environment variables (optional, can inherit from main service)
	Mounts  []Mount           // Mounts (optional, can inherit from main service)
	Network NetworkMode       // Network mode (optional, can inherit from main service)
}

InitContainer represents an init container configuration. Init containers run before the main service and must complete successfully.

type Logging

type Logging struct {
	Driver  string            // Log driver (json-file, journald, etc.)
	Options map[string]string // Driver-specific options
}

Logging represents logging configuration.

type Mount

type Mount struct {
	Source       string            // Source path or volume name
	Target       string            // Container path
	Type         MountType         // "bind", "volume", "tmpfs"
	ReadOnly     bool              // Read-only mount
	Options      map[string]string // Mount options
	BindOptions  *BindOptions      // Bind-specific options
	TmpfsOptions *TmpfsOptions     // Tmpfs-specific options
}

Mount represents a filesystem mount.

type MountType

type MountType string

MountType represents the type of mount.

const (
	MountTypeBind   MountType = "bind"
	MountTypeVolume MountType = "volume"
	MountTypeTmpfs  MountType = "tmpfs"
)

Mount type constants.

type Network

type Network struct {
	Name     string            // Network name
	Driver   string            // Network driver (bridge, overlay, etc.)
	Options  map[string]string // Driver options
	Labels   map[string]string // Network labels
	IPAM     *IPAM             // IP address management
	Internal bool              // Internal network (no external access)
	IPv6     bool              // Enable IPv6
	External bool              // External network (not managed)
	Quadlet  *QuadletNetwork   `json:"quadlet,omitempty"` // Quadlet-specific options (systemd/Linux only)
}

Network represents a network definition.

func (*Network) Validate

func (n *Network) Validate() error

Validate validates network configuration.

type NetworkMode

type NetworkMode struct {
	Mode            string   // "bridge", "host", "none", "container:<name>", "service:<name>"
	Aliases         []string // Network aliases
	ServiceNetworks []string // Networks this service joins (for service-to-service DNS)
}

NetworkMode represents network configuration mode.

type Port

type Port struct {
	Host      string // Host address (optional)
	HostPort  uint16 // Host port
	Container uint16 // Container port
	Protocol  string // "tcp" or "udp" (default: tcp)
}

Port represents a port mapping.

type QuadletNetwork added in v0.23.0

type QuadletNetwork struct {
	ContainersConfModule []string          // Additional .conf modules to load
	GlobalArgs           []string          // Global Podman arguments for network creation
	PodmanArgs           []string          // Additional Podman arguments for network creation
	DisableDNS           bool              // Disable DNS for this network
	DNS                  []string          // DNS servers for this network
	Options              map[string]string // Advanced network options (in addition to base Options)
}

QuadletNetwork contains systemd Quadlet-specific network options. These fields are only used when rendering to systemd Quadlet units and are ignored by other platforms.

type QuadletVolume added in v0.23.0

type QuadletVolume struct {
	ContainersConfModule []string // Additional .conf modules to load
	GlobalArgs           []string // Global Podman arguments for volume creation
	PodmanArgs           []string // Additional Podman arguments for volume creation
}

QuadletVolume contains systemd Quadlet-specific volume options. These fields are only used when rendering to systemd Quadlet units and are ignored by other platforms.

type Resources

type Resources struct {
	Memory            string // Memory limit (e.g., "512m", "2g")
	MemoryReservation string // Memory soft limit
	MemorySwap        string // Memory + swap limit
	CPUShares         int64  // CPU shares (relative weight)
	CPUQuota          int64  // CPU quota in microseconds
	CPUPeriod         int64  // CPU period in microseconds
	PidsLimit         int64  // Maximum PIDs
	ShmSize           string // Shared memory size (e.g., "64m", "1g")
}

Resources represents resource constraints.

type RestartPolicy

type RestartPolicy string

RestartPolicy represents the container restart policy.

const (
	RestartPolicyNo            RestartPolicy = "no"
	RestartPolicyAlways        RestartPolicy = "always"
	RestartPolicyOnFailure     RestartPolicy = "on-failure"
	RestartPolicyUnlessStopped RestartPolicy = "unless-stopped"
)

Restart policy constants.

type Secret

type Secret struct {
	Source string // Secret source identifier
	Target string // Target path in container (optional)
	UID    string // Owner UID (optional)
	GID    string // Owner GID (optional)
	Mode   string // File permissions (optional)
	Type   string // Secret type (optional)
}

Secret represents a secret to mount in the container.

type Security

type Security struct {
	Privileged      bool     // Run with elevated privileges
	CapAdd          []string // Linux capabilities to add
	CapDrop         []string // Linux capabilities to drop
	SecurityOpt     []string // Security options
	ReadonlyRootfs  bool     // Read-only root filesystem
	SELinuxType     string   // SELinux type label
	AppArmorProfile string   // AppArmor profile
	SeccompProfile  string   // Seccomp profile
	GroupAdd        []string // Additional groups to join
}

Security represents security settings.

type Spec

type Spec struct {
	Name                 string               // Service name (unique identifier, may be prefixed)
	OriginalName         string               // Original unprefixed service name (for DNS aliases)
	Description          string               // Human-readable description
	Container            Container            // Container configuration
	Volumes              []Volume             // Volume mounts
	Networks             []Network            // Network attachments
	DependsOn            []string             // Service dependencies (service names)
	ExternalDependencies []ExternalDependency // Cross-project service dependencies
	Annotations          map[string]string    // Platform-agnostic metadata
}

Spec represents a platform-agnostic service specification. It is the core domain model that gets converted from Docker Compose and rendered to platform-specific artifacts (systemd units, launchd plists, etc.).

func (*Spec) Validate

func (s *Spec) Validate() error

Validate validates a service specification.

type TmpfsOptions added in v0.24.7

type TmpfsOptions struct {
	Size string // Size limit (e.g., "64m", "1g")
	Mode uint32 // File mode (e.g., 1777, 0755)
	UID  int    // Owner UID
	GID  int    // Owner GID
}

TmpfsOptions represents tmpfs mount options.

type Ulimit

type Ulimit struct {
	Name string // Ulimit name
	Soft int64  // Soft limit
	Hard int64  // Hard limit
}

Ulimit represents a ulimit setting.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface.

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors represents multiple validation errors.

func (ValidationErrors) Error

func (e ValidationErrors) Error() string

Error implements the error interface.

type Volume

type Volume struct {
	Name     string            // Volume name
	Driver   string            // Volume driver (default: local)
	Options  map[string]string // Driver options
	Labels   map[string]string // Volume labels
	External bool              // External volume (not managed)
	Quadlet  *QuadletVolume    `json:"quadlet,omitempty"` // Quadlet-specific options (systemd/Linux only)
}

Volume represents a named volume definition.

func (*Volume) Validate

func (v *Volume) Validate() error

Validate validates volume configuration.

Jump to

Keyboard shortcuts

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