-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuller.go
More file actions
88 lines (76 loc) · 2.64 KB
/
puller.go
File metadata and controls
88 lines (76 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Package deploy implements a lightweight continuous deployment agent.
// It supports three modes:
// - cloudflare: uploads build artifacts to Cloudflare Pages via API.
// - webhook: an HTTP daemon on the server that GitHub Actions triggers via POST.
// - ssh: generates a shell script that GitHub Actions runs via SSH on the server.
//
// Usage:
//
// d := &deploy.Deploy{Store: db, Process: mgr, Downloader: dl, Checker: checker}
// d.Run()
package deploy
import (
"fmt"
"os"
)
// Puller is the main orchestrator for all deployment modes.
// Store must be injected — kvdb.KVStore satisfies the Store interface directly.
type Puller struct {
Store Store
Process ProcessManager
Downloader Downloader
Checker HealthChecker
ConfigPath string
Provider Provider // replaces: Goflare *goflare.Goflare
log func(...any)
}
// SetLog injects a logger (called by tinywasm/app after registration with TUI).
func (p *Puller) SetLog(f func(...any)) { p.log = f }
func (p *Puller) logger(msgs ...any) {
if p.log != nil {
p.log(msgs...)
}
}
// Name returns the TUI tab label for the orchestrator.
func (p *Puller) Name() string { return "DEPLOY/DAEMON" }
// IsConfigured returns true if a deploy method has been stored.
func (p *Puller) IsConfigured() bool {
method, err := p.Store.Get("DEPLOY_METHOD")
return err == nil && method != ""
}
// Run executes the deployment based on the stored DEPLOY_METHOD.
// Called from cmd/deploy/main.go for standalone daemon mode.
func (p *Puller) Run() error {
method, err := p.Store.Get("DEPLOY_METHOD")
if err != nil || method == "" {
return fmt.Errorf("deploy: not configured — run wizard first (DEPLOY_METHOD not set)")
}
// DEPRECATED: Internal naming consistency. Strategy name is now "cloudflarePages" or "cloudflareWorker".
// The store might still hold "cloudflare" or "edgeworker" from older app configs.
// Kept for seamless backward compatibility; do not remove unless breaking changes are allowed.
if method == "cloudflare" || method == "edgeworker" {
method = "cloudflarePages"
}
// Use provider for supported deployment methods
if p.Provider != nil && p.Provider.Supports(method) {
return p.Provider.Deploy(p.Store)
}
strat, err := GetPusher(method)
if err != nil {
return err
}
cfg, err := Load(p.ConfigPath)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("deploy: load config: %w", err)
}
if cfg == nil {
if err := CreateDefaultConfig(p.ConfigPath); err != nil {
return fmt.Errorf("deploy: create default config: %w", err)
}
cfg, err = Load(p.ConfigPath)
if err != nil {
return fmt.Errorf("deploy: reload config: %w", err)
}
}
return strat.Run(cfg, p)
}