state

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package state manages persistent devrig project state in .devrig/state.json.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Remove

func Remove(stateDir string) error

Remove deletes state.json and attempts to remove the state directory if empty.

func StateDir

func StateDir(configPath string) string

StateDir returns the .devrig directory for a project (next to devrig.toml).

func UpdateServiceExit

func UpdateServiceExit(stateDir, service string, code int)

UpdateServiceExit writes the exit code for a service.

func UpdateServicePID

func UpdateServicePID(stateDir, service string, pid uint32)

UpdateServicePID writes just the PID field for a service into state.json using an exclusive file lock.

func UpdateServicePhase

func UpdateServicePhase(stateDir, service, phase string)

UpdateServicePhase writes the phase field for a service.

Types

type AddonState

type AddonState struct {
	AddonType   string    `json:"addon_type"`
	Namespace   string    `json:"namespace"`
	InstalledAt time.Time `json:"installed_at"`
}

type ClusterDeployState

type ClusterDeployState struct {
	ImageTag     string    `json:"image_tag"`
	LastDeployed time.Time `json:"last_deployed"`
}

type ClusterState

type ClusterState struct {
	ClusterName      string                        `json:"cluster_name"`
	KubeconfigPath   string                        `json:"kubeconfig_path"`
	RegistryName     *string                       `json:"registry_name,omitempty"`
	RegistryPort     *uint16                       `json:"registry_port,omitempty"`
	DeployedServices map[string]ClusterDeployState `json:"deployed_services"`
	InstalledAddons  map[string]AddonState         `json:"installed_addons"`
}

type ComposeServiceState

type ComposeServiceState struct {
	ContainerID   string  `json:"container_id"`
	ContainerName string  `json:"container_name"`
	Port          *uint16 `json:"port,omitempty"`
}

type DashboardState

type DashboardState struct {
	DashboardPort uint16 `json:"dashboard_port"`
	GRPCPort      uint16 `json:"grpc_port"`
	HTTPPort      uint16 `json:"http_port"`
}

type DockerState

type DockerState struct {
	ContainerID     string            `json:"container_id"`
	ContainerName   string            `json:"container_name"`
	Port            *uint16           `json:"port,omitempty"`
	PortAuto        bool              `json:"port_auto"`
	Protocol        *string           `json:"protocol,omitempty"`
	NamedPorts      map[string]uint16 `json:"named_ports"`
	InitCompleted   bool              `json:"init_completed"`
	InitCompletedAt *time.Time        `json:"init_completed_at,omitempty"`
}

type ProjectState

type ProjectState struct {
	Slug            string                         `json:"slug"`
	ConfigPath      string                         `json:"config_path"`
	StartedAt       time.Time                      `json:"started_at"`
	Services        map[string]ServiceState        `json:"services"`
	Docker          map[string]DockerState         `json:"docker"`
	ComposeServices map[string]ComposeServiceState `json:"compose_services"`
	NetworkName     *string                        `json:"network_name,omitempty"`
	Cluster         *ClusterState                  `json:"cluster,omitempty"`
	Dashboard       *DashboardState                `json:"dashboard,omitempty"`
	// PID of the main devrig process (written so `devrig stop` can signal it).
	PID int `json:"pid,omitempty"`
}

ProjectState is serialised to .devrig/state.json.

func Load

func Load(stateDir string) *ProjectState

Load reads state.json from stateDir. Returns nil if it doesn't exist or can't be parsed.

func (*ProjectState) Save

func (s *ProjectState) Save(stateDir string) error

Save writes state to state.json atomically (tmp → rename).

type ServiceState

type ServiceState struct {
	PID      uint32  `json:"pid"`
	Port     *uint16 `json:"port,omitempty"`
	PortAuto bool    `json:"port_auto"`
	Protocol *string `json:"protocol,omitempty"`
	Phase    *string `json:"phase,omitempty"`
	ExitCode *int    `json:"exit_code,omitempty"`
}

Jump to

Keyboard shortcuts

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