From 6b2c04728cd914f27ae62c1df0bf5df24ac9a628 Mon Sep 17 00:00:00 2001 From: Clawd Date: Tue, 17 Feb 2026 07:54:26 -0800 Subject: Remove v1 code, simplify state to just base_domain - Delete all v1 commands (deploy, init, list, status, remove, etc.) - Delete v1 env/ and host/ subcommand directories - Simplify state.go: remove NextPort, Apps, AllocatePort, etc. - Local state now only tracks default_host + base_domain per host - Ports and deploys are tracked on the server (/etc/ship/ports/) - host init now creates minimal state.json --- internal/state/state.go | 83 ++++--------------------------------------------- 1 file changed, 6 insertions(+), 77 deletions(-) (limited to 'internal/state') diff --git a/internal/state/state.go b/internal/state/state.go index c9aa21d..9b06179 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -8,38 +8,18 @@ import ( "regexp" ) -// State represents the entire local deployment state +// State represents the local ship configuration type State struct { DefaultHost string `json:"default_host,omitempty"` Hosts map[string]*Host `json:"hosts"` } -// Host represents deployment state for a single VPS +// Host represents configuration for a single VPS type Host struct { - NextPort int `json:"next_port"` - BaseDomain string `json:"base_domain,omitempty"` - GitSetup bool `json:"git_setup,omitempty"` - Apps map[string]*App `json:"apps"` + BaseDomain string `json:"base_domain,omitempty"` + GitSetup bool `json:"git_setup,omitempty"` } -// App represents a deployed application or static site -type App struct { - Type string `json:"type"` // "app", "static", "git-app", or "git-static" - Domain string `json:"domain"` - Port int `json:"port,omitempty"` // only for type="app" or "git-app" - Repo string `json:"repo,omitempty"` // only for git types, e.g. "/srv/git/foo.git" - Public bool `json:"public,omitempty"` // only for git types, enables HTTP clone access - Env map[string]string `json:"env,omitempty"` // only for type="app" or "git-app" - Args string `json:"args,omitempty"` // only for type="app" - Files []string `json:"files,omitempty"` // only for type="app" - Memory string `json:"memory,omitempty"` // only for type="app" - CPU string `json:"cpu,omitempty"` // only for type="app" -} - -const ( - startPort = 8001 -) - var validName = regexp.MustCompile(`^[a-z][a-z0-9-]{0,62}$`) // ValidateName checks that a name is safe for use in shell commands, @@ -55,7 +35,6 @@ func ValidateName(name string) error { func Load() (*State, error) { path := statePath() - // If file doesn't exist, return empty state if _, err := os.Stat(path); os.IsNotExist(err) { return &State{ Hosts: make(map[string]*Host), @@ -72,7 +51,6 @@ func Load() (*State, error) { return nil, fmt.Errorf("failed to parse state file: %w", err) } - // Initialize maps if nil if state.Hosts == nil { state.Hosts = make(map[string]*Host) } @@ -84,7 +62,6 @@ func Load() (*State, error) { func (s *State) Save() error { path := statePath() - // Ensure directory exists dir := filepath.Dir(path) if err := os.MkdirAll(dir, 0755); err != nil { return fmt.Errorf("failed to create config directory: %w", err) @@ -102,60 +79,14 @@ func (s *State) Save() error { return nil } -// GetHost returns the host state, creating it if it doesn't exist +// GetHost returns the host config, creating it if it doesn't exist func (s *State) GetHost(host string) *Host { if s.Hosts[host] == nil { - s.Hosts[host] = &Host{ - NextPort: startPort, - Apps: make(map[string]*App), - } - } - if s.Hosts[host].Apps == nil { - s.Hosts[host].Apps = make(map[string]*App) + s.Hosts[host] = &Host{} } return s.Hosts[host] } -// AllocatePort returns the next available port for a host -func (s *State) AllocatePort(host string) int { - h := s.GetHost(host) - port := h.NextPort - h.NextPort++ - return port -} - -// AddApp adds or updates an app in the state -func (s *State) AddApp(host, name string, app *App) { - h := s.GetHost(host) - h.Apps[name] = app -} - -// RemoveApp removes an app from the state -func (s *State) RemoveApp(host, name string) error { - h := s.GetHost(host) - if _, exists := h.Apps[name]; !exists { - return fmt.Errorf("app %s not found", name) - } - delete(h.Apps, name) - return nil -} - -// GetApp returns an app from the state -func (s *State) GetApp(host, name string) (*App, error) { - h := s.GetHost(host) - app, exists := h.Apps[name] - if !exists { - return nil, fmt.Errorf("app %s not found", name) - } - return app, nil -} - -// ListApps returns all apps for a host -func (s *State) ListApps(host string) map[string]*App { - h := s.GetHost(host) - return h.Apps -} - // GetDefaultHost returns the default host, or empty string if not set func (s *State) GetDefaultHost() string { return s.DefaultHost @@ -166,11 +97,9 @@ func (s *State) SetDefaultHost(host string) { s.DefaultHost = host } -// statePath returns the path to the state file func statePath() string { home, err := os.UserHomeDir() if err != nil { - // Fallback to current directory (should rarely happen) return ".ship-state.json" } return filepath.Join(home, ".config", "ship", "state.json") -- cgit v1.2.3