mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
220 lines
5.3 KiB
Go
220 lines
5.3 KiB
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type InstallStatus int
|
|
|
|
const (
|
|
InstallPending InstallStatus = iota
|
|
InstallRunning
|
|
InstallSuccess
|
|
InstallFailed
|
|
InstallSkipped
|
|
)
|
|
|
|
type InstallResult struct {
|
|
Err error
|
|
Detail string
|
|
}
|
|
|
|
type InstallConfig struct {
|
|
IsUpgrade bool
|
|
Version string
|
|
Domain string
|
|
}
|
|
|
|
type InstallStep struct {
|
|
Name string
|
|
Run func(cfg InstallConfig) InstallResult
|
|
Skip func(cfg InstallConfig) (bool, string)
|
|
Hidden bool
|
|
}
|
|
|
|
func GetInstallSteps() []InstallStep {
|
|
return []InstallStep{
|
|
{
|
|
Name: "Send telemetry",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
SendInstallStartEvent(cfg.Domain)
|
|
return InstallResult{Detail: "sent"}
|
|
},
|
|
Hidden: true,
|
|
},
|
|
{
|
|
Name: "Setup git",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
_ = AptUpdate()
|
|
if err := SetupGit(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "git ready"}
|
|
},
|
|
},
|
|
{
|
|
Name: "Clone/update Insights repository",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
if DirExists("insights") {
|
|
if err := UpdateInsights(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "updated"}
|
|
}
|
|
if err := CloneInsights(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "cloned"}
|
|
},
|
|
},
|
|
{
|
|
Name: "Checkout version",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
if err := CheckoutVersion(cfg.Version); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
commit, _ := GetCurrentCommit()
|
|
return InstallResult{Detail: fmt.Sprintf("at %s", commit)}
|
|
},
|
|
},
|
|
{
|
|
Name: "Generate configuration",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
if FileExists(".env") {
|
|
if err := FixEnvQuoting(); err != nil {
|
|
GetLogger().WriteString(fmt.Sprintf("Warning: could not fix .env quoting: %v\n", err))
|
|
}
|
|
if err := UpdateEnvForUpgrade(cfg.Version); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "updated"}
|
|
}
|
|
config, err := NewEnvConfig(cfg.Domain, cfg.Version)
|
|
if err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
if err := config.WriteEnvFile(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "created .env"}
|
|
},
|
|
},
|
|
{
|
|
Name: "Download GeoIP database",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
if GeoIPExists() {
|
|
return InstallResult{Detail: "already exists"}
|
|
}
|
|
if err := DownloadGeoIP(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "downloaded"}
|
|
},
|
|
},
|
|
{
|
|
Name: "Create startup scripts",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
if err := CreateComposeScripts(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "created"}
|
|
},
|
|
},
|
|
{
|
|
Name: "Copy Docker Compose files",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
if err := CopyComposeFiles(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "copied"}
|
|
},
|
|
},
|
|
{
|
|
Name: "Setup Docker",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
if IsDockerInstalled() && IsDockerRunning() {
|
|
return InstallResult{Detail: "Docker ready"}
|
|
}
|
|
|
|
if !IsDockerInstalled() {
|
|
if err := InstallDocker(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
if err := InstallDockerCompose(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "installed"}
|
|
}
|
|
|
|
if !IsDockerRunning() {
|
|
// Docker installed but not running - try to start it
|
|
if err := StartDockerDaemon(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
|
|
return InstallResult{Detail: "daemon started"}
|
|
}
|
|
|
|
return InstallResult{Detail: "Docker ready"}
|
|
},
|
|
},
|
|
{
|
|
Name: "Pull Docker images",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
if err := DockerComposePull(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "images pulled"}
|
|
},
|
|
},
|
|
{
|
|
Name: "Check async migrations",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
hasPostgres, hasDatastore := CheckDockerVolumes()
|
|
if hasPostgres || hasDatastore {
|
|
if err := RunAsyncMigrationsCheck(); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "checked"}
|
|
}
|
|
return InstallResult{Detail: "skipped (new install)"}
|
|
},
|
|
Skip: func(cfg InstallConfig) (bool, string) {
|
|
hasPostgres, hasDatastore := CheckDockerVolumes()
|
|
if !hasPostgres && !hasDatastore {
|
|
return true, "new install"
|
|
}
|
|
return false, ""
|
|
},
|
|
},
|
|
{
|
|
Name: "Start Insights stack",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
_ = DockerComposeStop()
|
|
if err := DockerComposeUpWithRetry(3); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "started"}
|
|
},
|
|
},
|
|
{
|
|
Name: "Wait for Insights to be ready",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
if err := WaitForHealth(45 * time.Minute); err != nil {
|
|
return InstallResult{Err: err}
|
|
}
|
|
return InstallResult{Detail: "Insights is up!"}
|
|
},
|
|
},
|
|
{
|
|
Name: "Send completion telemetry",
|
|
Run: func(cfg InstallConfig) InstallResult {
|
|
SendInstallCompleteEvent(cfg.Domain)
|
|
return InstallResult{Detail: "sent"}
|
|
},
|
|
Hidden: true,
|
|
},
|
|
}
|
|
}
|