Files
pipelines/internal/installation/installation.go
T
alan a70e3aef4b Install Pipelines natively by default on macOS and Linux
Add scripts/setup-native.py and make ./install (and --native) build the server, the CLI
and ntfy from source into ~/.local/share/pipelines, detect an existing host OpenCode
and Pi instead of installing them, install the packaged authoring skill, migrate an
existing Docker database and ntfy auth store, save the host client default and start
both services. ./install --docker keeps the previous Docker server + ntfy
installation unchanged.

ntfy is compiled from its pinned Go module on every host because upstream publishes
no macOS server binary (its darwin asset is built with -tags noserver); its cgo
SQLite driver is why a C compiler is now required natively. The ntfy credential
bootstrap and the client default writer are shared by both installers,
installation.Load resolves symlinked prefixes, the Docker migration copies the
SQLite write-ahead log so the newest definitions and runs are not lost, and the
account subcommands read the generated configuration through NTFY_CONFIG_FILE.

Verified on macOS: 115 Python tests, go build/vet/test, and scratch installs that
migrate 9 pipelines and 31 runs, build ntfy v2.30.0 and start both services healthy
on spare ports before stopping them.
2026-10-13 17:20:14 +01:00

82 lines
2.2 KiB
Go

// Package installation binds the compiled CLI to its per-user managed services.
package installation
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strconv"
)
type Config struct {
Format int `json:"format"`
Prefix string `json:"prefix"`
Python string `json:"python"`
ServerPort int `json:"server_port"`
OpenCode string `json:"opencode"`
OpenCodeEnv map[string]string `json:"opencode_env"`
Path string `json:"path"`
}
// Load selects a legacy managed installation only via an explicit PIPELINES_PREFIX.
func Load(executable string) (*Config, error) {
prefix := os.Getenv("PIPELINES_PREFIX")
if prefix == "" {
return nil, nil
}
prefix, err := filepath.Abs(prefix)
if err != nil {
return nil, err
}
// The native installer and scripts/manage.py record the symlink-resolved
// prefix, so resolve the same way here instead of rejecting a symlinked
// HOME or prefix as "invalid".
if resolved, err := filepath.EvalSymlinks(prefix); err == nil {
prefix = resolved
}
data, err := os.ReadFile(filepath.Join(prefix, "pipelines-install.json"))
if os.IsNotExist(err) {
return nil, nil
}
if err != nil {
return nil, err
}
var config Config
if err = json.Unmarshal(data, &config); err != nil {
return nil, err
}
if config.Format != 1 || config.Prefix != prefix || config.ServerPort < 1024 || config.ServerPort > 65535 {
return nil, fmt.Errorf("invalid managed installation manifest")
}
return &config, nil
}
func (c Config) Environment() error {
for key, value := range c.OpenCodeEnv {
switch key {
case "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME", "OPENCODE_SERVER", "OPENCODE_DB":
if err := os.Setenv(key, value); err != nil {
return err
}
}
}
for key, value := range map[string]string{"PIPELINES_URL": "ws://127.0.0.1:" + strconv.Itoa(c.ServerPort) + "/connect", "PIPELINES_OPENCODE": c.OpenCode} {
if os.Getenv(key) != "" {
continue
}
if err := os.Setenv(key, value); err != nil {
return err
}
}
return nil
}
func Service(action string) bool {
switch action {
case "start", "stop", "restart", "doctor", "logs", "uninstall":
return true
}
return false
}