fix setup remote stoof

This commit is contained in:
2026-01-14 13:33:34 +00:00
parent 63b0bbd165
commit b942757ade
2 changed files with 32 additions and 27 deletions

4
go.mod
View File

@@ -4,7 +4,9 @@ go 1.23.1
require (
github.com/charmbracelet/bubbletea v0.26.1
github.com/mattn/go-runewidth v0.0.15
github.com/pelletier/go-toml/v2 v2.2.4
golang.org/x/term v0.19.0
)
require (
@@ -13,7 +15,6 @@ require (
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
@@ -21,6 +22,5 @@ require (
github.com/rivo/uniseg v0.4.6 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.3.8 // indirect
)

55
main.go
View File

@@ -326,9 +326,9 @@ func init() {
func writePBConfig(path, serviceName string) error {
const tmpl = `[server]
ip = "127.0.0.1"
port = 8090
domain = "example.com"
# ip = "127.0.0.1"
# domain = "example.com"
[pocketbase]
version = "%s"
@@ -369,12 +369,16 @@ func resolveServiceName(defaultName string) (string, error) {
}
func shouldConfirmServerConfig(ctx *deploymentContext) (bool, error) {
exists, err := remoteDirExists(ctx.serverIP, ctx.serviceDir)
if err != nil {
fmt.Fprintf(os.Stderr, "warning: unable to verify remote service at %s: %v\n", ctx.serviceDir, err)
if strings.TrimSpace(ctx.serverIP) == "" {
return true, nil
}
return !exists, nil
if strings.TrimSpace(ctx.domain) == "" {
return true, nil
}
if ctx.port <= 0 {
return true, nil
}
return false, nil
}
func ensureServerConfigConfirmed(ctx *deploymentContext) (*deploymentContext, bool, error) {
@@ -389,7 +393,7 @@ func ensureServerConfigConfirmed(ctx *deploymentContext) (*deploymentContext, bo
if err := confirmServerConfig(ctx.configPath); err != nil {
return nil, false, err
}
newCtx, err := buildDeploymentContext()
newCtx, err := buildDeploymentContext(true)
if err != nil {
return nil, false, err
}
@@ -928,7 +932,7 @@ const (
totalSetupSteps = 5
remoteWindowSize = 10
remoteIndent = " "
remoteLineColor = "\033[94m"
remoteLineColor = ""
headerColor = "\033[1;37m"
localTimeColor = "\033[0;32m"
statusActiveColor = "\033[92m"
@@ -969,7 +973,7 @@ type deploymentContext struct {
configPath string
}
func buildDeploymentContext() (*deploymentContext, error) {
func buildDeploymentContext(requireServer bool) (*deploymentContext, error) {
cwd, err := os.Getwd()
if err != nil {
return nil, err
@@ -987,17 +991,17 @@ func buildDeploymentContext() (*deploymentContext, error) {
}
serverIP := cfg.Server.IP
if serverIP == "" {
if requireServer && serverIP == "" {
return nil, fmt.Errorf("pb.toml missing [server].ip")
}
domain := cfg.Server.Domain
if domain == "" {
if requireServer && domain == "" {
return nil, fmt.Errorf("pb.toml missing [server].domain")
}
port := cfg.Server.Port
if port <= 0 {
if requireServer && port <= 0 {
return nil, fmt.Errorf("pb.toml server.port must be greater than zero")
}
@@ -1034,7 +1038,7 @@ func buildDeploymentContext() (*deploymentContext, error) {
}
func runSetup() error {
ctx, err := buildDeploymentContext()
ctx, err := buildDeploymentContext(false)
if err != nil {
return err
}
@@ -1113,14 +1117,22 @@ func performSetup(ctx *deploymentContext, restart bool) error {
}
func runDeploy() error {
ctx, err := buildDeploymentContext()
ctx, err := buildDeploymentContext(false)
if err != nil {
return err
}
start := time.Now()
ctx, prompted, err := ensureServerConfigConfirmed(ctx)
if err != nil {
return err
}
if prompted {
start = time.Now()
}
defer func() {
closeSSHControlMaster(ctx.serverIP)
}()
start := time.Now()
binaryPath := filepath.Join(ctx.serviceDir, "pocketbase")
exists, err := remoteBinaryExists(ctx.serverIP, binaryPath)
@@ -1130,13 +1142,6 @@ func runDeploy() error {
if err != nil || !exists {
fmt.Println("PocketBase binary missing on remote; running setup")
ctx, prompted, err := ensureServerConfigConfirmed(ctx)
if err != nil {
return err
}
if prompted {
start = time.Now()
}
if err := performSetup(ctx, false); err != nil {
return err
}
@@ -1161,7 +1166,7 @@ func runDeploy() error {
}
func runStatus() error {
ctx, err := buildDeploymentContext()
ctx, err := buildDeploymentContext(true)
if err != nil {
return err
}
@@ -1326,7 +1331,7 @@ func formatDuration(d time.Duration) string {
}
func runLogs() error {
ctx, err := buildDeploymentContext()
ctx, err := buildDeploymentContext(true)
if err != nil {
return err
}
@@ -1349,7 +1354,7 @@ func runSecrets() error {
return fmt.Errorf("usage: pb secrets <list|set|delete> [arguments]")
}
ctx, err := buildDeploymentContext()
ctx, err := buildDeploymentContext(true)
if err != nil {
return err
}