summaryrefslogtreecommitdiffstats
path: root/cmd/deploy/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/deploy/main.go')
-rw-r--r--cmd/deploy/main.go130
1 files changed, 51 insertions, 79 deletions
diff --git a/cmd/deploy/main.go b/cmd/deploy/main.go
index 51439dd..ad61523 100644
--- a/cmd/deploy/main.go
+++ b/cmd/deploy/main.go
@@ -1,93 +1,65 @@
1package main 1package main
2 2
3import ( 3import (
4 "fmt"
5 "os" 4 "os"
6)
7
8func main() {
9 if len(os.Args) < 2 {
10 printUsage()
11 os.Exit(1)
12 }
13
14 command := os.Args[1]
15
16 switch command {
17 case "init":
18 runInit(os.Args[2:])
19 case "list":
20 runList(os.Args[2:])
21 case "rm", "remove":
22 runRemove(os.Args[2:])
23 case "logs":
24 runLogs(os.Args[2:])
25 case "status":
26 runStatus(os.Args[2:])
27 case "restart":
28 runRestart(os.Args[2:])
29 case "env":
30 runEnv(os.Args[2:])
31 case "webui":
32 runWebUI(os.Args[2:])
33 case "vps":
34 runVPS(os.Args[2:])
35 case "vps-update":
36 runUpdate(os.Args[2:])
37 case "vps-ssh":
38 runSSH(os.Args[2:])
39 case "help", "--help", "-h":
40 printUsage()
41 default:
42 // Default action is deploy - pass all args including the first one
43 runDeploy(os.Args[1:])
44 }
45}
46 5
47func printUsage() { 6 "github.com/bdw/deploy/cmd/deploy/env"
48 usage := `deploy - Deploy Go apps and static sites to a VPS with automatic HTTPS 7 "github.com/bdw/deploy/cmd/deploy/host"
49 8 "github.com/spf13/cobra"
50USAGE: 9)
51 deploy [flags] Deploy an app or static site
52 deploy <command> [flags] Run a subcommand
53
54COMMANDS:
55 init Initialize a fresh VPS (one-time setup)
56 list List all deployed apps and sites
57 rm Remove a deployment
58 logs View logs for a deployment
59 status Check status of a deployment
60 restart Restart a deployment
61 env Manage environment variables
62 vps Show VPS health (uptime, disk, memory, load)
63 vps-update Update VPS packages (apt update && upgrade)
64 vps-ssh Open an interactive SSH session
65 webui Launch web UI to manage deployments
66 10
67FLAGS: 11var (
68 Run 'deploy -h' or 'deploy <command> -h' for flags 12 // Persistent flags
13 hostFlag string
69 14
70EXAMPLES: 15 // Version info (set via ldflags)
71 # Initialize VPS (sets it as default host) 16 version = "dev"
72 deploy init --host user@vps-ip 17 commit = "none"
18 date = "unknown"
19)
73 20
74 # Deploy Go app 21var rootCmd = &cobra.Command{
75 deploy --binary ./myapp --domain api.example.com 22 Use: "deploy",
23 Short: "Deploy Go apps and static sites to a VPS with automatic HTTPS",
24 Long: `deploy - Deploy Go apps and static sites to a VPS with automatic HTTPS
76 25
77 # Deploy static site 26A CLI tool for deploying applications and static sites to a VPS.
78 deploy --static --dir ./dist --domain example.com 27Uses Caddy for automatic HTTPS and systemd for service management.`,
28 RunE: runDeploy,
29 SilenceUsage: true,
30 SilenceErrors: true,
31}
79 32
80 # List deployments 33func init() {
81 deploy list 34 // Persistent flags available to all subcommands
35 rootCmd.PersistentFlags().StringVar(&hostFlag, "host", "", "VPS host (SSH config alias or user@host)")
82 36
83 # View logs 37 // Root command (deploy) flags
84 deploy logs myapp 38 rootCmd.Flags().String("binary", "", "Path to Go binary (for app deployment)")
39 rootCmd.Flags().Bool("static", false, "Deploy as static site")
40 rootCmd.Flags().String("dir", ".", "Directory to deploy (for static sites)")
41 rootCmd.Flags().String("domain", "", "Domain name (required)")
42 rootCmd.Flags().String("name", "", "App name (default: inferred from binary or directory)")
43 rootCmd.Flags().Int("port", 0, "Port override (default: auto-allocate)")
44 rootCmd.Flags().StringArray("env", nil, "Environment variable (KEY=VALUE, can be specified multiple times)")
45 rootCmd.Flags().String("env-file", "", "Path to .env file")
46 rootCmd.Flags().String("args", "", "Arguments to pass to binary")
47 rootCmd.Flags().StringArray("file", nil, "Config file to upload to working directory (can be specified multiple times)")
85 48
86 # Check VPS health 49 // Add subcommands
87 deploy vps 50 rootCmd.AddCommand(listCmd)
51 rootCmd.AddCommand(logsCmd)
52 rootCmd.AddCommand(statusCmd)
53 rootCmd.AddCommand(restartCmd)
54 rootCmd.AddCommand(removeCmd)
55 rootCmd.AddCommand(env.Cmd)
56 rootCmd.AddCommand(host.Cmd)
57 rootCmd.AddCommand(uiCmd)
58 rootCmd.AddCommand(versionCmd)
59}
88 60
89 # Update VPS packages 61func main() {
90 deploy vps-update 62 if err := rootCmd.Execute(); err != nil {
91` 63 os.Exit(1)
92 fmt.Fprint(os.Stderr, usage) 64 }
93} 65}