Files
sam 5356745968
Quality / check (push) Successful in 3m39s
deploy / gate (push) Successful in 4m28s
deploy / archied-image (push) Successful in 3m11s
deploy / agent-image (push) Successful in 11s
deploy / dist-zip (push) Skipped
fix(releaseupdate): address review findings on the #1725 canary change
- one shared UpdateStateDir() resolver for daemon and dashboard, instead of
  two copies that could drift
- the recovery path for a committed/rolled-back journal writes
  installed.json too, so a crash after the outcome phase cannot lose the
  install record
- JudgeCanaryNow is the explicit signals-only entry point for promoting
  without the window, replacing the zero-install-time sentinel
- canary version comparisons use IssuedAt, matching Promote's replay rule,
  so semver/issued-at divergence cannot wedge check red; queuedBehind
  reuses the judgeable predicate instead of a looser check
- promote prints the channel/pin; promote.yml cancels superseded runs
- canary card: no duplicated elapsed rendering, channel row waits for the
  settings resource instead of showing a default, agent fallback '?'
- rehearsal script bounds its docker build/push/run calls

task check passes on this tree.
2026-11-02 02:45:26 +11:00

65 lines
2.0 KiB
Go

package configuration
import (
"fmt"
"os"
"path/filepath"
"regexp"
)
// DefaultInstance is the instance name when ARCHIE_INSTANCE is unset. Every
// host-global name derived from it is unchanged from a single-instance host.
const DefaultInstance = "archie"
// instancePattern keeps every instance under the archie namespace: the name is
// used bare as XDG directory, compose project and container prefix, so
// "archie-dev" cannot collide with another program's "dev".
var instancePattern = regexp.MustCompile(`^archie(-[a-z0-9][a-z0-9-]{0,23})?$`)
// InstanceName returns the instance this process belongs to, from
// ARCHIE_INSTANCE. It names the config, data, state and cache directories, so
// it cannot live in the config file it selects. Loading rejects an invalid
// name, so callers past startup can use it as a path segment.
func InstanceName() string {
if name := os.Getenv("ARCHIE_INSTANCE"); name != "" {
return name
}
return DefaultInstance
}
func validateInstanceName(name string) error {
if !instancePattern.MatchString(name) {
return fmt.Errorf("ARCHIE_INSTANCE %q: must match %s", name, instancePattern)
}
return nil
}
// DefaultCacheDir returns the instance's user cache directory.
func DefaultCacheDir() (string, error) {
cache, err := os.UserCacheDir()
if err != nil {
return "", err
}
return filepath.Join(cache, InstanceName()), nil
}
// DefaultUpdateStateDir returns $XDG_STATE_HOME/<instance>/update.
func DefaultUpdateStateDir() string {
dir := os.Getenv("XDG_STATE_HOME")
if dir == "" {
home, _ := os.UserHomeDir()
dir = filepath.Join(home, ".local", "state")
}
return filepath.Join(dir, InstanceName(), "update")
}
// UpdateStateDir is the one resolution of the host's update state directory:
// ARCHIE_UPDATE_STATE_DIR when set, else the default. The daemon's
// transactions and the dashboard's update snapshot must read the same one.
func UpdateStateDir() string {
if dir := os.Getenv("ARCHIE_UPDATE_STATE_DIR"); dir != "" {
return dir
}
return DefaultUpdateStateDir()
}