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 --- cmd/ship/env/env.go | 17 ------- cmd/ship/env/list.go | 72 --------------------------- cmd/ship/env/set.go | 135 -------------------------------------------------- cmd/ship/env/unset.go | 95 ----------------------------------- 4 files changed, 319 deletions(-) delete mode 100644 cmd/ship/env/env.go delete mode 100644 cmd/ship/env/list.go delete mode 100644 cmd/ship/env/set.go delete mode 100644 cmd/ship/env/unset.go (limited to 'cmd/ship/env') diff --git a/cmd/ship/env/env.go b/cmd/ship/env/env.go deleted file mode 100644 index 489353a..0000000 --- a/cmd/ship/env/env.go +++ /dev/null @@ -1,17 +0,0 @@ -package env - -import ( - "github.com/spf13/cobra" -) - -var Cmd = &cobra.Command{ - Use: "env", - Short: "Manage environment variables", - Long: "Manage environment variables for deployed applications", -} - -func init() { - Cmd.AddCommand(listCmd) - Cmd.AddCommand(setCmd) - Cmd.AddCommand(unsetCmd) -} diff --git a/cmd/ship/env/list.go b/cmd/ship/env/list.go deleted file mode 100644 index e94b83a..0000000 --- a/cmd/ship/env/list.go +++ /dev/null @@ -1,72 +0,0 @@ -package env - -import ( - "fmt" - "strings" - - "github.com/bdw/ship/internal/state" - "github.com/spf13/cobra" -) - -var listCmd = &cobra.Command{ - Use: "list ", - Short: "List environment variables for an app", - Args: cobra.ExactArgs(1), - RunE: runList, -} - -func runList(cmd *cobra.Command, args []string) error { - name := args[0] - if err := state.ValidateName(name); err != nil { - return err - } - - st, err := state.Load() - if err != nil { - return fmt.Errorf("error loading state: %w", err) - } - - host, _ := cmd.Flags().GetString("host") - if host == "" { - host = st.GetDefaultHost() - } - - if host == "" { - return fmt.Errorf("--host is required") - } - - app, err := st.GetApp(host, name) - if err != nil { - return err - } - - if app.Type != "app" { - return fmt.Errorf("env is only available for apps, not static sites") - } - - fmt.Printf("Environment variables for %s:\n\n", name) - if len(app.Env) == 0 { - fmt.Println(" (none)") - } else { - for k, v := range app.Env { - display := v - if isSensitive(k) { - display = "***" - } - fmt.Printf(" %s=%s\n", k, display) - } - } - - return nil -} - -func isSensitive(key string) bool { - key = strings.ToLower(key) - sensitiveWords := []string{"key", "secret", "password", "token", "api"} - for _, word := range sensitiveWords { - if strings.Contains(key, word) { - return true - } - } - return false -} diff --git a/cmd/ship/env/set.go b/cmd/ship/env/set.go deleted file mode 100644 index d4292f3..0000000 --- a/cmd/ship/env/set.go +++ /dev/null @@ -1,135 +0,0 @@ -package env - -import ( - "bufio" - "fmt" - "os" - "strings" - - "github.com/bdw/ship/internal/ssh" - "github.com/bdw/ship/internal/state" - "github.com/spf13/cobra" -) - -var setCmd = &cobra.Command{ - Use: "set KEY=VALUE...", - Short: "Set environment variable(s)", - Long: "Set one or more environment variables for an app. Variables are specified as KEY=VALUE pairs.", - Args: cobra.MinimumNArgs(2), - RunE: runSet, -} - -func init() { - setCmd.Flags().StringP("file", "f", "", "Load environment from file") -} - -func runSet(cmd *cobra.Command, args []string) error { - name := args[0] - if err := state.ValidateName(name); err != nil { - return err - } - envVars := args[1:] - - st, err := state.Load() - if err != nil { - return fmt.Errorf("error loading state: %w", err) - } - - host, _ := cmd.Flags().GetString("host") - if host == "" { - host = st.GetDefaultHost() - } - - if host == "" { - return fmt.Errorf("--host is required") - } - - app, err := st.GetApp(host, name) - if err != nil { - return err - } - - if app.Type != "app" { - return fmt.Errorf("env is only available for apps, not static sites") - } - - if app.Env == nil { - app.Env = make(map[string]string) - } - - // Set variables from args - for _, e := range envVars { - parts := strings.SplitN(e, "=", 2) - if len(parts) == 2 { - app.Env[parts[0]] = parts[1] - fmt.Printf("Set %s\n", parts[0]) - } else { - return fmt.Errorf("invalid format: %s (expected KEY=VALUE)", e) - } - } - - // Set variables from file if provided - envFile, _ := cmd.Flags().GetString("file") - if envFile != "" { - fileEnv, err := parseEnvFile(envFile) - if err != nil { - return fmt.Errorf("error reading env file: %w", err) - } - for k, v := range fileEnv { - app.Env[k] = v - fmt.Printf("Set %s\n", k) - } - } - - if err := st.Save(); err != nil { - return fmt.Errorf("error saving state: %w", err) - } - - client, err := ssh.Connect(host) - if err != nil { - return fmt.Errorf("error connecting to VPS: %w", err) - } - defer client.Close() - - fmt.Println("-> Updating environment file on VPS...") - envFilePath := fmt.Sprintf("/etc/ship/env/%s.env", name) - envContent := "" - for k, v := range app.Env { - envContent += fmt.Sprintf("%s=%s\n", k, v) - } - if err := client.WriteSudoFile(envFilePath, envContent); err != nil { - return fmt.Errorf("error updating env file: %w", err) - } - - fmt.Println("-> Restarting service...") - if _, err := client.RunSudo(fmt.Sprintf("systemctl restart %s", name)); err != nil { - return fmt.Errorf("error restarting service: %w", err) - } - - fmt.Println("Environment variables updated successfully") - return nil -} - -func parseEnvFile(path string) (map[string]string, error) { - file, err := os.Open(path) - if err != nil { - return nil, err - } - defer file.Close() - - env := make(map[string]string) - scanner := bufio.NewScanner(file) - for scanner.Scan() { - line := strings.TrimSpace(scanner.Text()) - if line == "" || strings.HasPrefix(line, "#") { - continue - } - - parts := strings.SplitN(line, "=", 2) - if len(parts) == 2 { - env[parts[0]] = parts[1] - } - } - - return env, scanner.Err() -} diff --git a/cmd/ship/env/unset.go b/cmd/ship/env/unset.go deleted file mode 100644 index 8292f42..0000000 --- a/cmd/ship/env/unset.go +++ /dev/null @@ -1,95 +0,0 @@ -package env - -import ( - "fmt" - - "github.com/bdw/ship/internal/ssh" - "github.com/bdw/ship/internal/state" - "github.com/spf13/cobra" -) - -var unsetCmd = &cobra.Command{ - Use: "unset KEY...", - Short: "Unset environment variable(s)", - Long: "Remove one or more environment variables from an app.", - Args: cobra.MinimumNArgs(2), - RunE: runUnset, -} - -func runUnset(cmd *cobra.Command, args []string) error { - name := args[0] - if err := state.ValidateName(name); err != nil { - return err - } - keys := args[1:] - - st, err := state.Load() - if err != nil { - return fmt.Errorf("error loading state: %w", err) - } - - host, _ := cmd.Flags().GetString("host") - if host == "" { - host = st.GetDefaultHost() - } - - if host == "" { - return fmt.Errorf("--host is required") - } - - app, err := st.GetApp(host, name) - if err != nil { - return err - } - - if app.Type != "app" { - return fmt.Errorf("env is only available for apps, not static sites") - } - - if app.Env == nil { - return fmt.Errorf("no environment variables set") - } - - changed := false - for _, key := range keys { - if _, exists := app.Env[key]; exists { - delete(app.Env, key) - changed = true - fmt.Printf("Unset %s\n", key) - } else { - fmt.Printf("Warning: %s not found\n", key) - } - } - - if !changed { - return nil - } - - if err := st.Save(); err != nil { - return fmt.Errorf("error saving state: %w", err) - } - - client, err := ssh.Connect(host) - if err != nil { - return fmt.Errorf("error connecting to VPS: %w", err) - } - defer client.Close() - - fmt.Println("-> Updating environment file on VPS...") - envFilePath := fmt.Sprintf("/etc/ship/env/%s.env", name) - envContent := "" - for k, v := range app.Env { - envContent += fmt.Sprintf("%s=%s\n", k, v) - } - if err := client.WriteSudoFile(envFilePath, envContent); err != nil { - return fmt.Errorf("error updating env file: %w", err) - } - - fmt.Println("-> Restarting service...") - if _, err := client.RunSudo(fmt.Sprintf("systemctl restart %s", name)); err != nil { - return fmt.Errorf("error restarting service: %w", err) - } - - fmt.Println("Environment variables updated successfully") - return nil -} -- cgit v1.2.3