diff options
| author | bndw <ben@bdw.to> | 2026-02-14 08:16:41 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-14 08:16:41 -0800 |
| commit | 702cb02831be836eeda91cd58504aeca45b1a260 (patch) | |
| tree | c566aacfebec86b342d2d971cc296784c92563e3 /cmd/ship | |
| parent | b9120489c454877ff623e65db48ec97f402bf8ed (diff) | |
Add backwards compatibility for existing binary deployments
Check if .ship files exist before reading them. If they don't exist,
generate them even on updates. This provides automatic migration for
deployments created before the .ship/ directory change.
Diffstat (limited to 'cmd/ship')
| -rw-r--r-- | cmd/ship/deploy.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/cmd/ship/deploy.go b/cmd/ship/deploy.go index 6894e21..90dc846 100644 --- a/cmd/ship/deploy.go +++ b/cmd/ship/deploy.go | |||
| @@ -337,8 +337,9 @@ func deployApp(st *state.State, opts DeployOptions) error { | |||
| 337 | return fmt.Errorf("error setting env file ownership: %w", err) | 337 | return fmt.Errorf("error setting env file ownership: %w", err) |
| 338 | } | 338 | } |
| 339 | 339 | ||
| 340 | // Create local .ship directory for deployment configs | 340 | // Create local .ship directory for deployment configs if they don't exist |
| 341 | if !opts.IsUpdate { | 341 | // (handles both initial deployment and migration of existing deployments) |
| 342 | if _, err := os.Stat(".ship/service"); os.IsNotExist(err) { | ||
| 342 | fmt.Println("-> Creating local .ship directory...") | 343 | fmt.Println("-> Creating local .ship directory...") |
| 343 | if err := os.MkdirAll(".ship", 0755); err != nil { | 344 | if err := os.MkdirAll(".ship", 0755); err != nil { |
| 344 | return fmt.Errorf("error creating .ship directory: %w", err) | 345 | return fmt.Errorf("error creating .ship directory: %w", err) |
| @@ -362,7 +363,9 @@ func deployApp(st *state.State, opts DeployOptions) error { | |||
| 362 | if err := os.WriteFile(".ship/service", []byte(serviceContent), 0644); err != nil { | 363 | if err := os.WriteFile(".ship/service", []byte(serviceContent), 0644); err != nil { |
| 363 | return fmt.Errorf("error writing .ship/service: %w", err) | 364 | return fmt.Errorf("error writing .ship/service: %w", err) |
| 364 | } | 365 | } |
| 366 | } | ||
| 365 | 367 | ||
| 368 | if _, err := os.Stat(".ship/Caddyfile"); os.IsNotExist(err) { | ||
| 366 | fmt.Println("-> Generating Caddyfile...") | 369 | fmt.Println("-> Generating Caddyfile...") |
| 367 | caddyContent, err := templates.AppCaddy(map[string]string{ | 370 | caddyContent, err := templates.AppCaddy(map[string]string{ |
| 368 | "Domain": opts.Domain, | 371 | "Domain": opts.Domain, |
| @@ -380,7 +383,7 @@ func deployApp(st *state.State, opts DeployOptions) error { | |||
| 380 | fmt.Println("-> Installing systemd service...") | 383 | fmt.Println("-> Installing systemd service...") |
| 381 | serviceContent, err := os.ReadFile(".ship/service") | 384 | serviceContent, err := os.ReadFile(".ship/service") |
| 382 | if err != nil { | 385 | if err != nil { |
| 383 | return fmt.Errorf("error reading .ship/service: %w (run initial deployment first)", err) | 386 | return fmt.Errorf("error reading .ship/service: %w", err) |
| 384 | } | 387 | } |
| 385 | servicePath := fmt.Sprintf("/etc/systemd/system/%s.service", opts.Name) | 388 | servicePath := fmt.Sprintf("/etc/systemd/system/%s.service", opts.Name) |
| 386 | if err := client.WriteSudoFile(servicePath, string(serviceContent)); err != nil { | 389 | if err := client.WriteSudoFile(servicePath, string(serviceContent)); err != nil { |
| @@ -391,7 +394,7 @@ func deployApp(st *state.State, opts DeployOptions) error { | |||
| 391 | fmt.Println("-> Installing Caddy config...") | 394 | fmt.Println("-> Installing Caddy config...") |
| 392 | caddyContent, err := os.ReadFile(".ship/Caddyfile") | 395 | caddyContent, err := os.ReadFile(".ship/Caddyfile") |
| 393 | if err != nil { | 396 | if err != nil { |
| 394 | return fmt.Errorf("error reading .ship/Caddyfile: %w (run initial deployment first)", err) | 397 | return fmt.Errorf("error reading .ship/Caddyfile: %w", err) |
| 395 | } | 398 | } |
| 396 | caddyPath := fmt.Sprintf("/etc/caddy/sites-enabled/%s.caddy", opts.Name) | 399 | caddyPath := fmt.Sprintf("/etc/caddy/sites-enabled/%s.caddy", opts.Name) |
| 397 | if err := client.WriteSudoFile(caddyPath, string(caddyContent)); err != nil { | 400 | if err := client.WriteSudoFile(caddyPath, string(caddyContent)); err != nil { |
| @@ -581,8 +584,9 @@ func deployStatic(st *state.State, opts DeployOptions) error { | |||
| 581 | return fmt.Errorf("error setting file permissions: %w", err) | 584 | return fmt.Errorf("error setting file permissions: %w", err) |
| 582 | } | 585 | } |
| 583 | 586 | ||
| 584 | // Create local .ship directory and Caddyfile for static sites | 587 | // Create local .ship directory and Caddyfile for static sites if it doesn't exist |
| 585 | if !opts.IsUpdate { | 588 | // (handles both initial deployment and migration of existing deployments) |
| 589 | if _, err := os.Stat(".ship/Caddyfile"); os.IsNotExist(err) { | ||
| 586 | fmt.Println("-> Creating local .ship directory...") | 590 | fmt.Println("-> Creating local .ship directory...") |
| 587 | if err := os.MkdirAll(".ship", 0755); err != nil { | 591 | if err := os.MkdirAll(".ship", 0755); err != nil { |
| 588 | return fmt.Errorf("error creating .ship directory: %w", err) | 592 | return fmt.Errorf("error creating .ship directory: %w", err) |
| @@ -605,7 +609,7 @@ func deployStatic(st *state.State, opts DeployOptions) error { | |||
| 605 | fmt.Println("-> Installing Caddy config...") | 609 | fmt.Println("-> Installing Caddy config...") |
| 606 | caddyContent, err := os.ReadFile(".ship/Caddyfile") | 610 | caddyContent, err := os.ReadFile(".ship/Caddyfile") |
| 607 | if err != nil { | 611 | if err != nil { |
| 608 | return fmt.Errorf("error reading .ship/Caddyfile: %w (run initial deployment first)", err) | 612 | return fmt.Errorf("error reading .ship/Caddyfile: %w", err) |
| 609 | } | 613 | } |
| 610 | caddyPath := fmt.Sprintf("/etc/caddy/sites-enabled/%s.caddy", opts.Name) | 614 | caddyPath := fmt.Sprintf("/etc/caddy/sites-enabled/%s.caddy", opts.Name) |
| 611 | if err := client.WriteSudoFile(caddyPath, string(caddyContent)); err != nil { | 615 | if err := client.WriteSudoFile(caddyPath, string(caddyContent)); err != nil { |
