config

package
v1.12.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddProjectWorker added in v1.12.6

func AddProjectWorker(dir, name string) error

AddProjectWorker appends name to the workers list if not already present. No-op if .lerd.yaml does not exist.

func AddSite

func AddSite(site Site) error

AddSite appends or updates a site in the registry.

func BackupBinaryFile added in v1.5.0

func BackupBinaryFile() string

BackupBinaryFile returns the path to the backup lerd binary used for rollback.

func BackupTrayFile added in v1.5.0

func BackupTrayFile() string

BackupTrayFile returns the path to the backup lerd-tray binary used for rollback.

func BackupVersionFile added in v1.5.0

func BackupVersionFile() string

BackupVersionFile returns the path to the file storing the pre-update version string.

func BinDir

func BinDir() string

BinDir returns the lerd bin directory.

func BrowserHostsFile added in v1.10.0

func BrowserHostsFile() string

BrowserHostsFile returns the path to the hosts file for browser testing containers (e.g. Selenium). It maps .test domains to the nginx container's IP so that Chromium inside the container can reach lerd sites directly over the Podman network instead of going through the host gateway.

func CertsDir

func CertsDir() string

CertsDir returns the certs directory.

func ComposerHasPackage added in v1.10.0

func ComposerHasPackage(dir, pkg string, extraSections ...string) bool

ComposerHasPackage reports whether the composer.json in dir lists pkg in require or require-dev. ComposerHasPackage reports whether the composer.json in dir lists pkg in require, require-dev, or any of the extra sections specified.

func ConfigDir

func ConfigDir() string

ConfigDir returns ~/.config/lerd/ (or $XDG_CONFIG_HOME/lerd/).

func ContainerHostsFile added in v1.2.4

func ContainerHostsFile() string

ContainerHostsFile returns the path to the shared hosts file mounted into PHP containers.

func CountSitesUsingPHP added in v1.4.0

func CountSitesUsingPHP(version string) int

CountSitesUsingPHP returns how many non-ignored, non-paused sites are registered with the given PHP version.

func CountSitesUsingService added in v1.0.0

func CountSitesUsingService(name string) int

CountSitesUsingService returns how many active (non-ignored, non-paused) site .env files reference lerd-{name}, i.e. are configured to use the service.

func CustomServicesDependingOn added in v1.0.0

func CustomServicesDependingOn(name string) []string

CustomServicesDependingOn returns the names of all custom services that declare name in their depends_on list.

func CustomServicesDir added in v0.5.4

func CustomServicesDir() string

CustomServicesDir returns the directory for custom service YAML files.

func DataDir

func DataDir() string

DataDir returns ~/.local/share/lerd/ (or $XDG_DATA_HOME/lerd/).

func DataSubDir

func DataSubDir(name string) string

DataSubDir returns a named subdirectory under data.

func DetectFramework added in v1.0.0

func DetectFramework(dir string) (string, bool)

DetectFramework inspects dir and returns the detected framework name. It checks user-defined and store-installed frameworks first so that more specific frameworks (e.g. Statamic, which also contains an artisan file) are detected before the broad built-in Laravel detection. Returns ("", false) if no framework matches.

func DetectFrameworkForDir added in v1.11.0

func DetectFrameworkForDir(dir string) (string, bool)

DetectFrameworkForDir is the primary entry point for framework detection. It checks .lerd.yaml first (committed source of truth), restoring embedded definitions if needed, then falls back to file/composer-based detection. Does NOT prompt or fetch from the remote store — callers that need store interaction should fall back to store.DetectFrameworkWithStore.

func DetectMajorVersion added in v1.11.0

func DetectMajorVersion(projectDir, frameworkName string) string

DetectMajorVersion detects the major version of a framework from the project directory. It tries composer.json constraints first, then falls back to version_file regex matching.

func DetectPublicDir added in v1.0.0

func DetectPublicDir(dir string) string

DetectPublicDir inspects dir for a well-known PHP public directory and returns it. It checks directories used by common PHP frameworks in priority order. A candidate is accepted only if it contains an index.php file, ensuring the directory is actually the document root and not an empty placeholder. Returns "." if no valid candidate is found (serve from project root).

func DnsmasqDir

func DnsmasqDir() string

DnsmasqDir returns the dnsmasq config directory.

func ErrorPagesDir added in v1.5.0

func ErrorPagesDir() string

ErrorPagesDir returns the directory where nginx error page HTML files are stored.

func FrameworksDir added in v1.0.0

func FrameworksDir() string

FrameworksDir returns the directory for user-defined framework YAML files.

func GetConsoleCommand added in v1.2.0

func GetConsoleCommand(projectDir string) (string, error)

GetConsoleCommand returns the console binary (without the "php" prefix) for the framework detected in projectDir. It checks the site registry first, then falls back to auto-detection. For Laravel the default is "artisan".

func GlobalConfigFile

func GlobalConfigFile() string

GlobalConfigFile returns the path to config.yaml.

func IgnoreSite added in v0.3.0

func IgnoreSite(name string) error

IgnoreSite marks a site as ignored (used for parked sites that have been unlinked).

func InferFamily added in v1.9.0

func InferFamily(name string) string

InferFamily returns the family for a custom service whose name follows the versioned-alternate template <family>-<digit...>, or the bare family name when the service is the canonical preset (e.g. "mongo"). Returns empty when neither pattern matches a known family.

func IsKnownFamily added in v1.9.0

func IsKnownFamily(name string) bool

IsKnownFamily reports whether name is a recognised service family.

func MatchesRule added in v1.6.0

func MatchesRule(dir string, rule FrameworkRule) bool

MatchesRule returns true if the given rule matches the project directory.

func MaterializeServiceFiles added in v1.9.0

func MaterializeServiceFiles(svc *CustomService) error

MaterializeServiceFiles writes each FileMount in svc to its host path, creating the parent directory and applying the requested mode.

func NginxConfD

func NginxConfD() string

NginxConfD returns the nginx conf.d directory.

func NginxDir

func NginxDir() string

NginxDir returns the nginx data directory.

func PHPConfFile added in v0.4.0

func PHPConfFile(version string) string

PHPConfFile returns the host path for the per-version xdebug ini file.

func PHPImageHashFile added in v0.1.25

func PHPImageHashFile() string

PHPImageHashFile returns the path to the stored PHP-FPM Containerfile hash.

func PHPUserIniFile added in v0.5.5

func PHPUserIniFile(version string) string

PHPUserIniFile returns the host path for the per-version user php.ini file.

func PausedDir added in v1.0.0

func PausedDir() string

PausedDir returns the directory where paused-site landing page HTML files are stored.

func PresetExists added in v1.9.0

func PresetExists(name string) bool

PresetExists reports whether a bundled preset with the given name exists.

func QuadletDir

func QuadletDir() string

QuadletDir returns the Podman quadlet directory.

func RegisterFrameworkFetchHook added in v1.10.0

func RegisterFrameworkFetchHook(fn FrameworkFetchFunc)

RegisterFrameworkFetchHook sets the callback used to auto-fetch missing framework definitions from the store.

func RemoveCustomService added in v0.5.4

func RemoveCustomService(name string) error

RemoveCustomService deletes a custom service config file.

func RemoveFramework added in v1.0.0

func RemoveFramework(name string) error

RemoveFramework deletes all framework definition files (user and store) for the given name.

func RemoveFrameworkFile added in v1.10.0

func RemoveFrameworkFile(path string) error

RemoveFrameworkFile removes a single framework definition file.

func RemoveProjectCustomWorker added in v1.11.0

func RemoveProjectCustomWorker(dir string, name string) error

RemoveProjectCustomWorker deletes a custom worker by name. No-op if .lerd.yaml does not exist. Returns an error if the worker is not found.

func RemoveProjectDomain added in v1.11.0

func RemoveProjectDomain(dir string, domain string) error

RemoveProjectDomain removes a single domain (case-insensitive match). No-op if .lerd.yaml does not exist.

func RemoveSite

func RemoveSite(name string) error

RemoveSite removes a site by name from the registry.

func RemoveUserFramework added in v1.10.0

func RemoveUserFramework(name string)

RemoveUserFramework silently removes a user-defined framework YAML if it exists. Used when migrating from user-defined to store-installed.

func ReplaceProjectDBService added in v1.11.0

func ReplaceProjectDBService(dir string, choice string) error

ReplaceProjectDBService removes any existing sqlite/mysql/postgres service and adds the given choice. Creates .lerd.yaml entries even if the file doesn't exist yet (database choice is typically part of initial setup).

func ResolveDynamicEnv added in v1.9.0

func ResolveDynamicEnv(svc *CustomService) error

ResolveDynamicEnv applies any dynamic_env directives on svc, writing the computed values into svc.Environment. Called immediately before quadlet generation so the resolved values land in the rendered .container file.

func SanitizeImageTag added in v1.9.0

func SanitizeImageTag(tag string) string

SanitizeImageTag returns a container-name-safe form of an image tag by replacing every character that systemd/podman do not accept in unit names with a hyphen. "5.7" -> "5-7", "8.0.34" -> "8-0-34", "11.4+focal" -> "11-4-focal".

func SaveCustomService added in v0.5.4

func SaveCustomService(svc *CustomService) error

SaveCustomService validates and writes a custom service config to disk.

func SaveFramework added in v1.0.0

func SaveFramework(fw *Framework) error

SaveFramework writes a framework definition to FrameworksDir()/{name}.yaml. For the laravel built-in, only the Workers field is persisted (other fields come from the built-in definition and are always merged in by GetFramework).

func SaveGlobal

func SaveGlobal(cfg *GlobalConfig) error

SaveGlobal writes the configuration to config.yaml.

func SaveProjectConfig added in v1.2.0

func SaveProjectConfig(dir string, cfg *ProjectConfig) error

SaveProjectConfig writes cfg to .lerd.yaml in dir.

func SaveSites

func SaveSites(reg *SiteRegistry) error

SaveSites writes the registry to sites.yaml.

func SaveStoreFramework added in v1.10.0

func SaveStoreFramework(fw *Framework) error

SaveStoreFramework writes a store-installed framework definition to StoreFrameworksDir(). If the framework has a Version field, the file is named <name>@<version>.yaml. Otherwise it is named <name>.yaml (backwards compatible).

func ServiceFilePath added in v1.9.0

func ServiceFilePath(svcName string, target string) string

ServiceFilePath returns the deterministic host path for a single FileMount belonging to the named service. Both the materialiser and the quadlet generator use this so they agree on layout without explicit plumbing.

func ServiceFilesDir added in v1.9.0

func ServiceFilesDir(name string) string

ServiceFilesDir returns the directory holding rendered FileMount content for the named custom service. Each file is bind-mounted into the container at its declared target path.

func ServiceIsManuallyStarted added in v1.0.0

func ServiceIsManuallyStarted(name string) bool

ServiceIsManuallyStarted returns true if the service was explicitly started by the user (via `lerd service start` or the dashboard), making it exempt from auto-stop when no sites reference it.

func ServiceIsPaused added in v0.6.0

func ServiceIsPaused(name string) bool

ServiceIsPaused returns true if the service was manually stopped by the user.

func ServiceIsPinned added in v1.0.0

func ServiceIsPinned(name string) bool

ServiceIsPinned returns true if the service has been pinned by the user, meaning it will never be auto-stopped even when no sites reference it.

func ServicesInFamily added in v1.9.0

func ServicesInFamily(family string) []string

ServicesInFamily returns the container hostnames (lerd-<name>) of every installed service that belongs to the named family. Built-ins match against builtinFamilies; custom services match by their Family field, with a fallback that infers family from the name prefix (e.g. mysql-5-7 -> mysql) so services installed before the explicit field existed still discover. Names are returned in deterministic order so the resulting env var stays stable across regenerations.

func SetProjectCustomWorker added in v1.11.0

func SetProjectCustomWorker(dir string, name string, w FrameworkWorker) error

SetProjectCustomWorker adds or replaces a custom worker entry. No-op if .lerd.yaml does not exist.

func SetProjectDomains added in v1.11.0

func SetProjectDomains(dir string, domains []string) error

SetProjectDomains replaces the domains list. No-op if .lerd.yaml does not exist.

func SetProjectFrameworkDef added in v1.11.0

func SetProjectFrameworkDef(dir string, def *Framework) error

SetProjectFrameworkDef replaces the embedded framework definition. No-op if .lerd.yaml does not exist.

func SetProjectFrameworkVersion added in v1.11.0

func SetProjectFrameworkVersion(dir string, version string) error

SetProjectFrameworkVersion updates framework_version. No-op if .lerd.yaml does not exist or the version hasn't changed.

func SetProjectPHPVersion added in v1.11.0

func SetProjectPHPVersion(dir string, version string) error

SetProjectPHPVersion updates php_version. No-op if .lerd.yaml does not exist.

func SetProjectSecured added in v1.11.0

func SetProjectSecured(dir string, secured bool) error

SetProjectSecured updates the secured field. No-op if .lerd.yaml does not exist.

func SetProjectWorkers added in v1.11.0

func SetProjectWorkers(dir string, workers []string) error

SetProjectWorkers replaces the workers list. No-op if .lerd.yaml does not exist.

func SetServiceManuallyStarted added in v1.0.0

func SetServiceManuallyStarted(name string, v bool) error

SetServiceManuallyStarted marks or clears the manually-started flag for the named service.

func SetServicePaused added in v0.6.0

func SetServicePaused(name string, paused bool) error

SetServicePaused marks or clears the manual-stop flag for the named service.

func SetServicePinned added in v1.0.0

func SetServicePinned(name string, v bool) error

SetServicePinned marks or clears the pinned flag for the named service.

func SitesFile

func SitesFile() string

SitesFile returns the path to sites.yaml.

func StoreFrameworksDir added in v1.10.0

func StoreFrameworksDir() string

StoreFrameworksDir returns the directory for store-installed framework YAML files.

func SyncProjectDomains added in v1.11.0

func SyncProjectDomains(dir string, fullDomains []string, tld string) error

SyncProjectDomains merges fullDomains (stripping the TLD suffix) with any existing .lerd.yaml domains, deduplicating case-insensitively. Registered domains come first; pre-existing entries not in the registered list are appended (conflict-filtered domains preserved for self-healing). No-op if .lerd.yaml does not exist.

func SystemdUserDir

func SystemdUserDir() string

SystemdUserDir returns the systemd user unit directory.

func UpdateCheckFile added in v0.9.0

func UpdateCheckFile() string

UpdateCheckFile returns the path to the cached update-check state file.

Types

type CustomService added in v0.5.4

type CustomService struct {
	Name          string            `yaml:"name"`
	Image         string            `yaml:"image"`
	Ports         []string          `yaml:"ports,omitempty"`
	Environment   map[string]string `yaml:"environment,omitempty"`
	DataDir       string            `yaml:"data_dir,omitempty"`
	Exec          string            `yaml:"exec,omitempty"`
	EnvVars       []string          `yaml:"env_vars,omitempty"`
	EnvDetect     *EnvDetect        `yaml:"env_detect,omitempty"`
	SiteInit      *SiteInit         `yaml:"site_init,omitempty"`
	Dashboard     string            `yaml:"dashboard,omitempty"`
	ConnectionURL string            `yaml:"connection_url,omitempty"`
	Description   string            `yaml:"description,omitempty"`
	DependsOn     []string          `yaml:"depends_on,omitempty"`
	Files         []FileMount       `yaml:"files,omitempty"`
	// Family groups related services so admin UIs can auto-discover every
	// member. e.g. the mysql preset declares family: mysql, and phpMyAdmin
	// uses dynamic_env to read all family members at quadlet generation time.
	Family string `yaml:"family,omitempty"`
	// Preset is the bundled preset name this service was installed from.
	// Set by InstallPresetByName. Used so the init wizard can store a
	// preset reference in .lerd.yaml instead of an inlined definition.
	Preset string `yaml:"preset,omitempty"`
	// PresetVersion is the picked version tag for multi-version presets.
	// Empty for single-version presets.
	PresetVersion string `yaml:"preset_version,omitempty"`
	// ShareHosts mounts the browser-testing hosts file
	// (~/.local/share/lerd/browser-hosts) into the container at /etc/hosts,
	// so the container can resolve .test domains to the nginx container's IP
	// on the Podman network. Used by browser testing services like Selenium
	// that need to reach lerd sites by domain name.
	ShareHosts bool `yaml:"share_hosts,omitempty" json:"share_hosts,omitempty"`
	// DynamicEnv declares container env vars whose value is computed at
	// quadlet generation time. Currently supported directive:
	//   discover_family:<name>  -> comma-joined hostnames of every installed
	//   service in the named family (built-in or custom).
	DynamicEnv map[string]string `yaml:"dynamic_env,omitempty"`
}

CustomService represents a user-defined OCI-based service.

func ListCustomServices added in v0.5.4

func ListCustomServices() ([]*CustomService, error)

ListCustomServices returns all custom services defined in the services directory.

func LoadCustomService added in v0.5.4

func LoadCustomService(name string) (*CustomService, error)

LoadCustomService loads a custom service by name from the services directory.

func LoadCustomServiceFromFile added in v0.5.4

func LoadCustomServiceFromFile(path string) (*CustomService, error)

LoadCustomServiceFromFile parses a CustomService from any YAML file path.

type EnvDetect added in v0.5.4

type EnvDetect struct {
	Key         string `yaml:"key,omitempty"`
	ValuePrefix string `yaml:"value_prefix,omitempty"`
	// Composer triggers detection when the named package is present in the
	// project's composer.json (require or require-dev). Used instead of Key
	// when the service should be auto-detected by a dependency rather than
	// an existing .env variable (e.g. selenium detected via laravel/dusk).
	Composer string `yaml:"composer,omitempty"`
}

EnvDetect defines auto-detection rules for `lerd env`.

type EnvKeyGeneration added in v1.10.0

type EnvKeyGeneration struct {
	EnvKey         string `yaml:"env_key"`                   // env var to check/set (e.g. "APP_KEY")
	Command        string `yaml:"command,omitempty"`         // artisan command to run if vendor/ exists (e.g. "key:generate")
	FallbackPrefix string `yaml:"fallback_prefix,omitempty"` // prefix for random key fallback (e.g. "base64:")
}

EnvKeyGeneration describes how to generate an application encryption key.

type FileMount added in v1.9.0

type FileMount struct {
	// Target is the absolute path inside the container where the file appears.
	Target string `yaml:"target"`
	// Content is the literal file body, written verbatim.
	Content string `yaml:"content"`
	// Mode is the octal permission bits, e.g. "0600". Defaults to "0644".
	Mode string `yaml:"mode,omitempty"`
	// Chown adds the :U flag to the volume mount so podman re-chowns the file
	// to match the container's expected UID. Required when the in-container
	// process runs as a non-root user (e.g. pgAdmin runs as uid 5050) and the
	// file mode would otherwise hide it from that user (e.g. 0600).
	Chown bool `yaml:"chown,omitempty"`
}

FileMount is a single file rendered to disk on the host and bind-mounted into a custom service container. It exists so presets can ship config files (e.g. pgAdmin's servers.json, a pgpass) without requiring the user to manage any host paths themselves.

type Framework added in v1.0.0

type Framework struct {
	Name  string `yaml:"name"`
	Label string `yaml:"label"`
	// Version is the framework major version this definition targets (e.g. "11", "7").
	Version string `yaml:"version,omitempty"`
	// PHP defines the supported PHP version range for this framework version.
	PHP       FrameworkPHP               `yaml:"php,omitempty"`
	Detect    []FrameworkRule            `yaml:"detect,omitempty"`
	PublicDir string                     `yaml:"public_dir"`
	Env       FrameworkEnvConf           `yaml:"env,omitempty"`
	Composer  string                     `yaml:"composer,omitempty"` // auto | true | false
	NPM       string                     `yaml:"npm,omitempty"`      // auto | true | false
	Workers   map[string]FrameworkWorker `yaml:"workers,omitempty"`
	Setup     []FrameworkSetupCmd        `yaml:"setup,omitempty"`
	// Console is the console command to run (without 'php' prefix).
	// Example: "artisan", "bin/console"
	Console string `yaml:"console,omitempty"`
	// Create is the scaffold command used by "lerd new". The target directory is appended automatically.
	// Example: "composer create-project --no-install --no-plugins --no-scripts laravel/laravel"
	Create string `yaml:"create,omitempty"`
	// Logs defines where application log files live for this framework.
	Logs []FrameworkLogSource `yaml:"logs,omitempty"`
	// Favicon is the path to the favicon file relative to the public directory.
	// When set, detectFavicon checks this path in addition to the standard candidates.
	// Example: "core/misc/favicon.ico" for Drupal.
	Favicon string `yaml:"favicon,omitempty"`
}

Framework describes a PHP project framework type.

func GetFramework added in v1.0.0

func GetFramework(name string) (*Framework, bool)

GetFramework returns the framework definition for the given name. It loads the base definition from the built-in (laravel), store, or user dir, then merges any user-defined overlay on top. The overlay can add/override workers and setup commands without replacing the entire definition. Returns (nil, false) if the framework is not found.

func GetFrameworkForDir added in v1.10.0

func GetFrameworkForDir(name, projectDir string) (*Framework, bool)

GetFrameworkForDir is like GetFramework but auto-detects the framework version from composer.lock in projectDir. If a version-specific store definition exists it is preferred over an unversioned one. User overlay workers are always merged. When a version is detected but no local definition exists, it attempts to fetch the definition from the store automatically.

func ListFrameworks added in v1.0.0

func ListFrameworks() []*Framework

ListFrameworks returns all available framework definitions: the laravel built-in plus any user-defined YAMLs in FrameworksDir().

func LoadUserFramework added in v1.10.0

func LoadUserFramework(name string) *Framework

LoadUserFramework loads a user-defined framework from FrameworksDir(). Returns nil if not found.

func (*Framework) DetectProxy added in v1.10.0

func (fw *Framework) DetectProxy(dir string) (*WorkerProxy, string)

WorkerProxy returns the proxy configuration for the first worker that has one and whose check rule passes for the project at dir. Returns nil if no proxy is configured.

func (*Framework) HasWorker added in v1.10.0

func (fw *Framework) HasWorker(name, dir string) bool

HasWorker returns true if the framework defines a worker with the given name and (if the worker has a Check rule) the check passes for the project at dir.

type FrameworkEnvConf added in v1.0.0

type FrameworkEnvConf struct {
	File           string `yaml:"file,omitempty"`            // primary env file (relative to project)
	ExampleFile    string `yaml:"example_file,omitempty"`    // example to copy from if File missing
	Format         string `yaml:"format,omitempty"`          // dotenv | php-const (default: dotenv)
	FallbackFile   string `yaml:"fallback_file,omitempty"`   // used when File doesn't exist
	FallbackFormat string `yaml:"fallback_format,omitempty"` // format for FallbackFile

	// URLKey is the env key that holds the application URL (default: APP_URL).
	URLKey string `yaml:"url_key,omitempty"`

	// Services defines per-service detection rules and env vars to apply.
	// Keys match the built-in service names: mysql, postgres, redis, meilisearch, rustfs, mailpit.
	Services map[string]FrameworkServiceDef `yaml:"services,omitempty"`

	// KeyGeneration describes how to generate an application key if missing.
	KeyGeneration *EnvKeyGeneration `yaml:"key_generation,omitempty"`
}

FrameworkEnvConf describes how the framework manages its env file.

func (FrameworkEnvConf) Resolve added in v1.0.0

func (e FrameworkEnvConf) Resolve(projectDir string) (file, format string)

Resolve returns the env file path and format to use for the given project directory. It returns the primary file if it exists, otherwise the fallback. Defaults to ".env" with "dotenv" format if nothing is configured.

type FrameworkFetchFunc added in v1.10.0

type FrameworkFetchFunc func(name, version string) (*Framework, error)

FrameworkFetchFunc is a callback that fetches a framework definition from the store and saves it locally. It is called when GetFrameworkForDir cannot find a local definition for the detected version. The store package registers this at startup to avoid a circular import.

type FrameworkFile added in v1.10.0

type FrameworkFile struct {
	Path    string
	Version string // "" for unversioned
	Source  FrameworkSource
}

FrameworkFile describes a framework definition file on disk.

func ListFrameworkFiles added in v1.10.0

func ListFrameworkFiles(name string) []FrameworkFile

ListFrameworkFiles returns all definition files for a framework across user and store directories.

type FrameworkInfo added in v1.10.0

type FrameworkInfo struct {
	*Framework
	Source FrameworkSource
}

FrameworkInfo holds a framework definition together with its source metadata.

func ListFrameworksDetailed added in v1.10.0

func ListFrameworksDetailed() []FrameworkInfo

ListFrameworksDetailed returns all available framework definitions with source info. Frameworks with a store base + user overlay show as "store" with merged workers.

type FrameworkLogSource added in v1.7.0

type FrameworkLogSource struct {
	Path   string `yaml:"path"`             // glob relative to project root, e.g. "storage/logs/*.log"
	Format string `yaml:"format,omitempty"` // "monolog" | "raw" (default: "raw")
}

FrameworkLogSource describes where application log files live for a framework.

type FrameworkPHP added in v1.10.0

type FrameworkPHP struct {
	Min string `yaml:"min,omitempty"` // minimum PHP version (e.g. "8.2")
	Max string `yaml:"max,omitempty"` // maximum PHP version (e.g. "8.4")
}

FrameworkPHP defines the supported PHP version range for a framework version.

type FrameworkRule added in v1.0.0

type FrameworkRule struct {
	File             string   `yaml:"file,omitempty"`              // file must exist in project root
	Composer         string   `yaml:"composer,omitempty"`          // package must be in composer.json require/require-dev
	ComposerSections []string `yaml:"composer_sections,omitempty"` // extra composer.json keys to search (e.g. flex-require)
	VersionKey       string   `yaml:"version_key,omitempty"`       // dot-path to version in composer.json (e.g. extra.symfony.require)
	VersionFile      string   `yaml:"version_file,omitempty"`      // file to read version from (relative to project root)
	VersionPattern   string   `yaml:"version_pattern,omitempty"`   // regex with capture group for version (e.g. "\\$wp_version = '([^']+)'")
}

FrameworkRule is a single detection rule for a framework. Any matching rule is sufficient to identify the framework.

type FrameworkServiceDef added in v1.0.0

type FrameworkServiceDef struct {
	// Detect lists env key conditions; any match signals the service is in use.
	Detect []FrameworkServiceDetect `yaml:"detect,omitempty"`
	// Vars is the list of KEY=VALUE pairs to apply when the service is detected.
	// Use {{site}} for the per-project database name.
	Vars []string `yaml:"vars,omitempty"`
}

FrameworkServiceDef describes how a service is detected and configured for a framework.

type FrameworkServiceDetect added in v1.0.0

type FrameworkServiceDetect struct {
	Key         string `yaml:"key"`
	ValuePrefix string `yaml:"value_prefix,omitempty"`
}

FrameworkServiceDetect is a single detection condition. The service is considered active when Key exists in the env file and, if ValuePrefix is set, its value starts with that prefix.

type FrameworkSetupCmd added in v1.6.0

type FrameworkSetupCmd struct {
	Label   string         `yaml:"label"`
	Command string         `yaml:"command"`
	Default bool           `yaml:"default,omitempty"`
	Check   *FrameworkRule `yaml:"check,omitempty"` // only show when check passes (file exists or composer package installed)
}

FrameworkSetupCmd describes a one-off bootstrap command run during project setup.

type FrameworkSource added in v1.10.0

type FrameworkSource string

FrameworkSource describes where a framework definition came from.

const (
	SourceBuiltIn FrameworkSource = "built-in"
	SourceUser    FrameworkSource = "user"
	SourceStore   FrameworkSource = "store"
)

func GetFrameworkSource added in v1.10.0

func GetFrameworkSource(name string) FrameworkSource

GetFrameworkSource returns the source of the active framework definition. Returns SourceBuiltIn for "laravel", SourceUser if a user-defined file exists, SourceStore if a store-installed file exists, or "" if not found.

type FrameworkWorker added in v1.0.0

type FrameworkWorker struct {
	Label         string         `yaml:"label,omitempty"`
	Command       string         `yaml:"command"`
	Restart       string         `yaml:"restart,omitempty"`        // always | on-failure (default: always)
	Schedule      string         `yaml:"schedule,omitempty"`       // systemd OnCalendar expression (e.g. "minutely"); when set, the worker is run as a Type=oneshot service triggered by a .timer rather than a long-running daemon. Use this for Laravel <=10 schedule:run, cron-style cleanup tasks, etc.
	Check         *FrameworkRule `yaml:"check,omitempty"`          // only show when check passes (file exists or composer package installed)
	ConflictsWith []string       `yaml:"conflicts_with,omitempty"` // workers to stop before starting this one (e.g. horizon conflicts_with queue)
	Proxy         *WorkerProxy   `yaml:"proxy,omitempty"`          // WebSocket/HTTP proxy config for nginx
}

FrameworkWorker describes a long-running process managed as a systemd service. The Command is executed inside the PHP-FPM container for the site.

type GlobalConfig

type GlobalConfig struct {
	PHP struct {
		DefaultVersion string              `yaml:"default_version" mapstructure:"default_version"`
		XdebugEnabled  map[string]bool     `yaml:"xdebug_enabled"  mapstructure:"xdebug_enabled"`
		Extensions     map[string][]string `yaml:"extensions"      mapstructure:"extensions"`
	} `yaml:"php" mapstructure:"php"`
	Node struct {
		DefaultVersion string `yaml:"default_version" mapstructure:"default_version"`
	} `yaml:"node" mapstructure:"node"`
	Nginx struct {
		HTTPPort  int `yaml:"http_port"  mapstructure:"http_port"`
		HTTPSPort int `yaml:"https_port" mapstructure:"https_port"`
	} `yaml:"nginx" mapstructure:"nginx"`
	DNS struct {
		TLD string `yaml:"tld" mapstructure:"tld"`
	} `yaml:"dns" mapstructure:"dns"`
	LAN struct {
		// Exposed controls whether lerd's services are reachable from
		// other devices on the local network. When false (the default,
		// safe-on-coffee-shop-wifi state) every container PublishPort is
		// rewritten to bind 127.0.0.1, lerd-ui binds 127.0.0.1:7073, and
		// the lerd-dns-forwarder is stopped. When true, container ports
		// bind 0.0.0.0, lerd-ui binds 0.0.0.0:7073, dnsmasq is rewritten
		// to answer .test queries with the host's LAN IP, and the
		// userspace lerd-dns-forwarder runs to bridge LAN-IP:5300 to the
		// loopback-only DNS container.
		//
		// Toggled via `lerd lan:expose on/off`. The previous standalone
		// `dns:expose` flag was folded in here because there is no
		// meaningful state where the DNS resolver answers the LAN but
		// the actual services don't.
		Exposed bool `yaml:"exposed,omitempty" mapstructure:"exposed"`
	} `yaml:"lan,omitempty" mapstructure:"lan"`
	Autostart struct {
		// Disabled controls whether lerd boots itself at login. The
		// zero value (false) means lerd autostarts as it always has:
		// every lerd-* container quadlet ships with its [Install]
		// section, the podman generator wires it into
		// default.target.wants on every daemon-reload, and the
		// lerd-ui / lerd-watcher / per-site worker units are enabled.
		// Setting this to true makes WriteQuadletDiff strip the
		// [Install] section before write (so the generator stops
		// emitting wants symlinks), disables ui/watcher and every
		// per-site worker, and stops them. Toggled via
		// `lerd autostart enable / disable` and the dashboard / tray
		// switches.
		//
		// Inverted form (Disabled rather than Enabled) so the YAML zero
		// value preserves the historical autostart-on behaviour for
		// every existing install — users who never touch the toggle
		// see no change.
		Disabled bool `yaml:"disabled,omitempty" mapstructure:"disabled"`
	} `yaml:"autostart,omitempty" mapstructure:"autostart"`
	UI struct {
		// RemoteControl gates non-loopback access to the lerd dashboard.
		// Empty PasswordHash = disabled = LAN clients get 403. With a hash
		// set, LAN clients must present matching HTTP Basic auth. Loopback
		// (127.0.0.1, ::1) always bypasses both checks.
		Username     string `yaml:"username,omitempty" mapstructure:"username"`
		PasswordHash string `yaml:"password_hash,omitempty" mapstructure:"password_hash"`
	} `yaml:"ui,omitempty" mapstructure:"ui"`
	ParkedDirectories []string                 `yaml:"parked_directories" mapstructure:"parked_directories"`
	Services          map[string]ServiceConfig `yaml:"services"           mapstructure:"services"`
}

GlobalConfig is the top-level lerd configuration.

func LoadGlobal

func LoadGlobal() (*GlobalConfig, error)

LoadGlobal reads config.yaml via viper, returning defaults if the file is absent.

func (*GlobalConfig) AddExtension added in v0.5.5

func (c *GlobalConfig) AddExtension(version, ext string)

AddExtension adds ext to the custom extension list for version (no-op if already present).

func (*GlobalConfig) GetExtensions added in v0.5.5

func (c *GlobalConfig) GetExtensions(version string) []string

GetExtensions returns the custom extensions configured for the given PHP version.

func (*GlobalConfig) IsXdebugEnabled added in v0.4.0

func (c *GlobalConfig) IsXdebugEnabled(version string) bool

IsXdebugEnabled returns true if Xdebug is enabled for the given PHP version.

func (*GlobalConfig) RemoveExtension added in v0.5.5

func (c *GlobalConfig) RemoveExtension(version, ext string)

RemoveExtension removes ext from the custom extension list for version.

func (*GlobalConfig) SetXdebug added in v0.4.0

func (c *GlobalConfig) SetXdebug(version string, enabled bool)

SetXdebug enables or disables Xdebug for the given PHP version.

type Preset added in v1.9.0

type Preset struct {
	CustomService  `yaml:",inline"`
	Versions       []PresetVersion `yaml:"versions,omitempty"`
	DefaultVersion string          `yaml:"default_version,omitempty"`
}

Preset is the parsed YAML for a bundled service preset. It embeds CustomService for the shared fields and adds an optional Versions list + DefaultVersion for families that ship multiple selectable image tags. After the user picks a tag, Resolve() materialises a concrete CustomService whose Name and Image are version-specific while every other field stays shared.

func LoadPreset added in v1.9.0

func LoadPreset(name string) (*Preset, error)

LoadPreset returns the parsed Preset for a bundled file by name.

func (*Preset) Resolve added in v1.9.0

func (p *Preset) Resolve(version string) (*CustomService, error)

Resolve materialises the preset into a concrete CustomService for the picked version. For single-version presets the embedded CustomService is returned as-is and version is ignored. For multi-version presets, version names a tag in Versions; an empty version selects DefaultVersion. The resolved service's Name is "<family>-<sanitized-tag>" and its Image is taken from the version entry. EnvVars and ConnectionURL are scanned for {{tag}} and {{tag_safe}} placeholders so the family-shared template can reference the picked tag.

type PresetMeta added in v1.9.0

type PresetMeta struct {
	Name           string          `json:"name"`
	Description    string          `json:"description"`
	Dashboard      string          `json:"dashboard,omitempty"`
	DependsOn      []string        `json:"depends_on,omitempty"`
	Image          string          `json:"image"`
	Versions       []PresetVersion `json:"versions,omitempty"`
	DefaultVersion string          `json:"default_version,omitempty"`
}

PresetMeta is the lightweight description of a bundled preset, suitable for listing in CLI tables and the web UI without parsing every field.

func ListPresets added in v1.9.0

func ListPresets() ([]PresetMeta, error)

ListPresets returns the metadata for all bundled service presets, sorted by name.

type PresetVersion added in v1.9.0

type PresetVersion struct {
	Tag   string `yaml:"tag" json:"tag"`
	Label string `yaml:"label,omitempty" json:"label,omitempty"`
	Image string `yaml:"image" json:"image"`
	// HostPort is the host-side port published for this specific version.
	// Each version gets its own fixed port so multiple alternates can run
	// side by side without colliding. Substituted into the family's
	// templated ports, env_vars and connection_url via {{host_port}}.
	HostPort int `yaml:"host_port,omitempty" json:"host_port,omitempty"`
}

PresetVersion is a single selectable image tag for a multi-version preset family (e.g. mysql 5.7, mysql 5.6, mariadb 11). Single-version presets like phpmyadmin or pgadmin omit Versions entirely and use the embedded CustomService image directly.

type ProjectConfig added in v1.2.0

type ProjectConfig struct {
	Domains          []string                   `yaml:"domains,omitempty"`
	PHPVersion       string                     `yaml:"php_version,omitempty"`
	NodeVersion      string                     `yaml:"node_version,omitempty"`
	Framework        string                     `yaml:"framework,omitempty"`
	FrameworkVersion string                     `yaml:"framework_version,omitempty"`
	FrameworkDef     *Framework                 `yaml:"framework_def,omitempty"`
	Secured          bool                       `yaml:"secured,omitempty"`
	Services         []ProjectService           `yaml:"services,omitempty"`
	Workers          []string                   `yaml:"workers,omitempty"`
	CustomWorkers    map[string]FrameworkWorker `yaml:"custom_workers,omitempty"`
	// AppURL, when set, is the value lerd writes to the project's APP_URL (or
	// the framework-configured URL key) on every `lerd env` run. Committed to
	// the repo so the choice is shared across machines. Takes precedence over
	// the per-machine override in sites.yaml.
	AppURL string `yaml:"app_url,omitempty"`
}

ProjectConfig holds per-project configuration stored in .lerd.yaml.

func LoadProjectConfig added in v1.2.0

func LoadProjectConfig(dir string) (*ProjectConfig, error)

LoadProjectConfig reads .lerd.yaml from dir, returning an empty config if the file does not exist.

func (*ProjectConfig) IsEmpty added in v1.11.0

func (c *ProjectConfig) IsEmpty() bool

IsEmpty returns true when the config has no meaningful content, which typically means .lerd.yaml did not exist.

func (*ProjectConfig) ServiceNames added in v1.3.0

func (p *ProjectConfig) ServiceNames() []string

ServiceNames returns the name of every service in the config, for callers that only need the list of names (e.g. the init wizard multi-select).

type ProjectService added in v1.3.0

type ProjectService struct {
	Name          string
	Preset        string         // empty unless this is a preset reference
	PresetVersion string         // empty for single-version presets
	Custom        *CustomService // nil unless this is an inline definition
}

ProjectService entries take three YAML shapes:

  • redis # named reference (built-in)
  • mysql: # preset reference, optional version preset: mysql version: "5.6"
  • mongodb: # inline custom definition (legacy / hand-rolled) image: mongo:7 ...

Preset references are the preferred form for services installed via `lerd service preset` because each machine resolves the embedded preset locally — picking up bug fixes, default tweaks, and per-machine port allocations without churn in .lerd.yaml.

func (ProjectService) MarshalYAML added in v1.3.0

func (s ProjectService) MarshalYAML() (interface{}, error)

MarshalYAML serialises back to the compact form: plain string for named references, single-key preset map for preset references, single-key custom map for inline definitions.

func (ProjectService) Resolve added in v1.9.0

func (s ProjectService) Resolve() (*CustomService, error)

Resolve returns the concrete CustomService for this entry. Preset references are resolved against the embedded preset library; inline definitions are returned as-is. Named built-in references return (nil, nil) — callers handle built-ins separately.

func (*ProjectService) UnmarshalYAML added in v1.3.0

func (s *ProjectService) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML accepts the three shapes documented on ProjectService.

type ServiceConfig

type ServiceConfig struct {
	Enabled    bool     `yaml:"enabled"      mapstructure:"enabled"`
	Image      string   `yaml:"image"        mapstructure:"image"`
	Port       int      `yaml:"port"         mapstructure:"port"`
	ExtraPorts []string `yaml:"extra_ports"  mapstructure:"extra_ports"`
}

ServiceConfig holds configuration for an optional service.

type Site

type Site struct {
	Name          string   `yaml:"-"`
	Domains       []string `yaml:"-"`
	Path          string   `yaml:"path"`
	PHPVersion    string   `yaml:"php_version"`
	NodeVersion   string   `yaml:"node_version"`
	Secured       bool     `yaml:"secured"`
	Ignored       bool     `yaml:"ignored,omitempty"`
	Paused        bool     `yaml:"paused,omitempty"`
	PausedWorkers []string `yaml:"paused_workers,omitempty"`
	Framework     string   `yaml:"framework,omitempty"`
	PublicDir     string   `yaml:"public_dir,omitempty"`
	// AppURL, when set, is the per-machine override for APP_URL in the
	// project's env file. Lower priority than ProjectConfig.AppURL (which is
	// committed to the repo) and higher priority than the default generator
	// (`<scheme>://<primary-domain>`). Use this for personal customizations
	// you don't want to share via .lerd.yaml.
	AppURL string `yaml:"app_url,omitempty"`
}

Site represents a single registered Lerd site.

func FindSite

func FindSite(name string) (*Site, error)

FindSite returns the site with the given name, or an error if not found.

func FindSiteByDomain added in v0.1.37

func FindSiteByDomain(domain string) (*Site, error)

FindSiteByDomain returns the site that has the given domain (checks all domains), or an error if not found.

func FindSiteByPath added in v0.3.0

func FindSiteByPath(path string) (*Site, error)

FindSiteByPath returns the site whose path matches, or an error if not found.

func IsDomainUsed added in v1.5.0

func IsDomainUsed(domain string) (*Site, error)

IsDomainUsed checks if any site already uses this domain. Returns the site that uses it, or nil if the domain is free.

The check is strict: a domain may only belong to one site, regardless of TLS scheme. Two sites cannot share the same domain even if one runs on HTTPS and the other on HTTP — DNS and browser caches don't reliably disambiguate by scheme, and the resulting setup is fragile.

func (*Site) HasDomain added in v1.5.0

func (s *Site) HasDomain(domain string) bool

HasDomain returns true if the site has the given domain.

func (*Site) PrimaryDomain added in v1.5.0

func (s *Site) PrimaryDomain() string

PrimaryDomain returns the first (primary) domain for the site.

type SiteInit added in v0.5.4

type SiteInit struct {
	// Container to exec into. Defaults to lerd-<service name>.
	Container string `yaml:"container,omitempty"`
	// Exec is passed to sh -c inside the container.
	Exec string `yaml:"exec"`
}

SiteInit defines an optional command to run inside the service container once per project when `lerd env` detects this service. Use it for any per-site setup: creating a database, a user, indexes, etc. The exec string may contain {{site}} and {{site_testing}} placeholders, which are replaced with the project site handle at runtime.

type SiteRegistry

type SiteRegistry struct {
	Sites []Site
}

SiteRegistry holds all registered sites.

func LoadSites

func LoadSites() (*SiteRegistry, error)

LoadSites reads sites.yaml, returning an empty registry if the file does not exist.

type WorkerNotFoundError added in v1.11.0

type WorkerNotFoundError struct {
	Name string
}

WorkerNotFoundError is returned when a custom worker name is not in .lerd.yaml.

func (*WorkerNotFoundError) Error added in v1.11.0

func (e *WorkerNotFoundError) Error() string

type WorkerProxy added in v1.10.0

type WorkerProxy struct {
	Path        string `yaml:"path"`                   // URL path to proxy (e.g. "/app")
	PortEnvKey  string `yaml:"port_env_key,omitempty"` // env key holding the port (e.g. "REVERB_SERVER_PORT")
	DefaultPort int    `yaml:"default_port,omitempty"` // fallback port if env key is missing (default: 8080)
}

WorkerProxy describes an HTTP/WebSocket proxy that nginx should configure for this worker. When present, nginx adds a location block that proxies requests to the worker inside the PHP-FPM container.

Jump to

Keyboard shortcuts

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