package cmd import ( "context" "fmt" "github.com/spf13/cobra" "github.com/manalejandro/buque/internal/proxy" ) var proxyCmd = &cobra.Command{ Use: "proxy", Short: "Manage nginx-proxy", Long: `Deploy, remove, and manage the nginx-proxy reverse proxy.`, } var proxyDeployCmd = &cobra.Command{ Use: "deploy", Short: "Deploy nginx-proxy", Long: `Deploy nginx-proxy with SSL support using Let's Encrypt.`, RunE: func(cmd *cobra.Command, args []string) error { cfg := configMgr.GetConfig() if cfg == nil { return fmt.Errorf("configuration not loaded") } manager, err := proxy.NewNginxManager(cfg.NginxProxy) if err != nil { return err } defer manager.Close() ctx := context.Background() return manager.Deploy(ctx) }, } var proxyRemoveCmd = &cobra.Command{ Use: "remove", Short: "Remove nginx-proxy", Long: `Stop and remove the nginx-proxy deployment.`, RunE: func(cmd *cobra.Command, args []string) error { cfg := configMgr.GetConfig() if cfg == nil { return fmt.Errorf("configuration not loaded") } manager, err := proxy.NewNginxManager(cfg.NginxProxy) if err != nil { return err } defer manager.Close() ctx := context.Background() return manager.Remove(ctx) }, } var proxyStatusCmd = &cobra.Command{ Use: "status", Short: "Show nginx-proxy status", Long: `Display the status of nginx-proxy containers.`, RunE: func(cmd *cobra.Command, args []string) error { cfg := configMgr.GetConfig() if cfg == nil { return fmt.Errorf("configuration not loaded") } manager, err := proxy.NewNginxManager(cfg.NginxProxy) if err != nil { return err } defer manager.Close() ctx := context.Background() status, err := manager.Status(ctx) if err != nil { return err } fmt.Println(status) return nil }, } var proxyExampleCmd = &cobra.Command{ Use: "example ", Short: "Generate example docker-compose.yml", Long: `Generate an example docker-compose.yml for a service behind nginx-proxy.`, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { cfg := configMgr.GetConfig() if cfg == nil { return fmt.Errorf("configuration not loaded") } serviceName := args[0] virtualHost := args[1] manager, err := proxy.NewNginxManager(cfg.NginxProxy) if err != nil { return err } defer manager.Close() example := manager.GetExampleServiceCompose(serviceName, virtualHost) fmt.Println(example) return nil }, } func init() { proxyCmd.AddCommand(proxyDeployCmd) proxyCmd.AddCommand(proxyRemoveCmd) proxyCmd.AddCommand(proxyStatusCmd) proxyCmd.AddCommand(proxyExampleCmd) }