fix deploy
This commit is contained in:
16
deploy.go
16
deploy.go
@@ -25,6 +25,7 @@ const (
|
|||||||
remoteWindowSize = 10
|
remoteWindowSize = 10
|
||||||
remoteIndent = " "
|
remoteIndent = " "
|
||||||
remoteLineColor = "\033[96m"
|
remoteLineColor = "\033[96m"
|
||||||
|
localTimeColor = "\033[92m"
|
||||||
remoteColorReset = "\033[0m"
|
remoteColorReset = "\033[0m"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -194,16 +195,17 @@ func runDeploy() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := syncLocalDirectories(ctx.serverIP, ctx.serviceDir, []string{"pb_migrations", "pb_hooks", "pb_public"}); err != nil {
|
dirs := []string{"pb_public", "pb_migrations", "pb_hooks"}
|
||||||
return fmt.Errorf("asset sync failed: %w", err)
|
if err := syncLocalDirectories(ctx.serverIP, ctx.serviceDir, dirs); err != nil {
|
||||||
|
return fmt.Errorf("failed to sync local directories: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := runSSHCommand(ctx.serverIP, systemdScript(ctx.unitServiceDir, ctx.unitEnvFile, ctx.serviceName)); err != nil {
|
if err := runSSHCommand(ctx.serverIP, systemdRestartScript(ctx.serviceName)); err != nil {
|
||||||
return fmt.Errorf("systemd restart failed: %w", err)
|
return fmt.Errorf("systemd restart failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\nDeployment complete; PocketBase should be reachable at https://%s\n", ctx.domain)
|
fmt.Printf("\nDeployment complete; PocketBase should be reachable at https://%s\n", ctx.domain)
|
||||||
fmt.Printf("Total deployment time: %s\n", time.Since(start).Round(time.Millisecond))
|
fmt.Printf("Total deployment time: %s%s%s\n", localTimeColor, time.Since(start).Round(time.Millisecond), remoteColorReset)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,6 +389,12 @@ EOF
|
|||||||
`, serviceDir, serviceDir, serviceDir, envFile, serviceDir, serviceName, serviceName)
|
`, serviceDir, serviceDir, serviceDir, envFile, serviceDir, serviceName, serviceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func systemdRestartScript(serviceName string) string {
|
||||||
|
return fmt.Sprintf(`set -euo pipefail
|
||||||
|
systemctl --no-block restart pb@%s
|
||||||
|
`, serviceName)
|
||||||
|
}
|
||||||
|
|
||||||
func runSSHCommand(server, script string) error {
|
func runSSHCommand(server, script string) error {
|
||||||
remoteCmd := fmt.Sprintf("bash --noprofile --norc -c %s", shellQuote(script))
|
remoteCmd := fmt.Sprintf("bash --noprofile --norc -c %s", shellQuote(script))
|
||||||
cmd := exec.Command("ssh", append(sshArgs(server), remoteCmd)...)
|
cmd := exec.Command("ssh", append(sshArgs(server), remoteCmd)...)
|
||||||
|
|||||||
Reference in New Issue
Block a user