project

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package project loads Docker Compose files and configures client resources.

This package is not a passive loader. It actively drives resource creation by calling into the client package. The typical flow is:

  1. CLI creates a client.Client
  2. project.Load() parses the compose file
  3. project.ToStack() configures resources on the client and builds a Stack
  4. CLI runs the Stack to execute operations on Incus

Index

Constants

This section is empty.

Variables

View Source
var ErrNoComposeFile = errors.New("no compose.yaml found, either change to a directory with a `compose.yaml` or use `--file`")

ErrNoComposeFile says there was no compose file to load, so a caller that can work without one can tell that apart from a broken one.

Functions

func LoadModel

func LoadModel(ctx context.Context, opts ...LoadOption) (map[string]any, error)

LoadModel loads the raw compose model without interpolation. Useful for extracting variable definitions before resolution.

func ServiceGraph

func ServiceGraph(serviceConfigs types.Services, reverse bool) ([]string, error)

ServiceGraph returns services in dependency order using topological sort. If reverse is true, returns reverse order (useful for shutdown).

Types

type LoadOption

type LoadOption func(*LoadOptions)

LoadOption is a functional option for LoadProject.

func LoadEnvFiles

func LoadEnvFiles(files []string) LoadOption

LoadEnvFiles sets alternative environment files.

func LoadFiles

func LoadFiles(files []string) LoadOption

LoadFiles sets the compose configuration file paths.

func LoadInstanceMarks added in v1.2.0

func LoadInstanceMarks(marks map[string]string) LoadOption

LoadInstanceMarks stamps config on every instance the project creates.

func LoadName

func LoadName(name string) LoadOption

LoadName sets the project name.

func LoadOsEnv

func LoadOsEnv() LoadOption

LoadOsEnv includes OS environment variables in the project environment. Without this, only .env files and compose file env vars are used (more portable).

func LoadProfiles

func LoadProfiles(profiles []string) LoadOption

LoadProfiles sets the profiles to enable.

func LoadProjectMarks added in v1.2.0

func LoadProjectMarks(marks map[string]string) LoadOption

LoadProjectMarks stamps config on the Incus project itself.

func LoadWorkingDir

func LoadWorkingDir(dir string) LoadOption

LoadWorkingDir sets the working directory.

type LoadOptions

type LoadOptions struct {
	// Project name
	Name string

	// Compose configuration file paths
	Files []string

	// Working directory (if empty, uses current directory or path of first file)
	WorkingDir string

	// Alternative environment files
	EnvFiles []string

	// Profiles to enable
	Profiles []string

	// OsEnv includes OS environment variables in project env (default: false for portability)
	OsEnv bool

	// InstanceMarks is config stamped on every instance the project creates.
	InstanceMarks map[string]string

	// ProjectMarks is config stamped on the Incus project itself.
	ProjectMarks map[string]string
}

LoadOptions holds configuration for Load and LoadModel.

func NewLoadOptions

func NewLoadOptions(opts ...LoadOption) LoadOptions

NewLoadOptions creates LoadOptions with the given options applied.

type Project

type Project struct {
	*types.Project `yaml:",inline"`

	ClientConfig XICProject `json:"-" yaml:"-"`

	// InstanceMarks is stamped on every instance; see LoadInstanceMarks.
	InstanceMarks map[string]string `json:"-" yaml:"-"`
}

Project wraps a Docker Compose project with Incus client integration.

func New

func New() *Project

New creates a new Project.

func (*Project) InstanceNames

func (p *Project) InstanceNames() []string

InstanceNames returns the Incus instance names for all services.

func (*Project) Load

func (p *Project) Load(ctx context.Context, opts ...LoadOption) (*Project, error)

Load loads a compose project with full interpolation and validation.

func (*Project) Resources

func (p *Project) Resources(c *client.Client, opts ...ResourcesOption) (map[string][]client.Resource, error)

Resources converts the compose project services to client resources.

func (*Project) ServiceOrder

func (p *Project) ServiceOrder(reverse bool) ([]string, error)

ServiceOrder returns the services in dependency order.

type ResourcesOption

type ResourcesOption func(o *ResourcesOptions)

ResourcesOption is a functional option for ToStack.

func ResourcesFull

func ResourcesFull() ResourcesOption

ResourcesFull fetches complete instance state including image alias and full instance details.

func ResourcesScale

func ResourcesScale(scale map[string]int) ResourcesOption

ResourcesScale sets replica count overrides for services.

type ResourcesOptions

type ResourcesOptions struct {
	Full  bool
	Scale map[string]int // service name -> replica count override
	// contains filtered or unexported fields
}

ResourcesOptions configures how services are converted to stack operations.

type XICHealthd added in v1.2.0

type XICHealthd struct {
	Incus    string
	Network  string
	External bool

	// Scope is HealthScopeProject or HealthScopeGlobal; empty means unset.
	Scope string

	// Workers and RestartWorkers size the daemon's pools; 0 means unset.
	Workers        int
	RestartWorkers int

	// XIncus is Incus instance config for the sidecar, e.g. limits.*.
	XIncus map[string]string
}

XICHealthd is the x-incus-compose.healthd block.

type XICProject added in v1.1.0

type XICProject struct {
	Healthd XICHealthd
	XIncus  map[string]string
}

XICProject is the typed view of the top-level x-incus-compose extension.

Jump to

Keyboard shortcuts

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