fix arch detection
This commit is contained in:
47
deploy.go
47
deploy.go
@@ -17,7 +17,7 @@ import (
|
||||
const (
|
||||
defaultServiceDirTemplate = "/root/pb/{service}"
|
||||
defaultEnvFileTemplate = "/root/pb/{service}/.env"
|
||||
totalDeploySteps = 7
|
||||
totalDeploySteps = 6
|
||||
)
|
||||
|
||||
type pbToml struct {
|
||||
@@ -81,9 +81,7 @@ func runDeploy() error {
|
||||
|
||||
step := 1
|
||||
printStep(step, totalDeploySteps, "validating configuration")
|
||||
step++
|
||||
printStep(step, totalDeploySteps, "probing remote host")
|
||||
remoteOS, err := runSSHOutput(serverIP, "/bin/uname -s")
|
||||
remoteOS, err := runSSHOutput(serverIP, "uname -s")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to determine remote OS: %w", err)
|
||||
}
|
||||
@@ -91,15 +89,13 @@ func runDeploy() error {
|
||||
return fmt.Errorf("unsupported remote OS %q", remoteOS)
|
||||
}
|
||||
|
||||
machineArch, err := runSSHOutput(serverIP, "/bin/uname -m")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to determine remote architecture: %w", err)
|
||||
}
|
||||
arch, err := translateMachineArch(machineArch)
|
||||
arch, err := detectRemoteArch(serverIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("arch; %s", arch)
|
||||
|
||||
assetName := pocketbaseAsset(version, "linux", arch)
|
||||
assetURL := fmt.Sprintf("https://github.com/pocketbase/pocketbase/releases/download/v%s/%s", version, assetName)
|
||||
|
||||
@@ -151,7 +147,7 @@ func loadPBConfig(path string) (*pbToml, error) {
|
||||
}
|
||||
|
||||
func printStep(idx, total int, message string) {
|
||||
fmt.Printf("\nStep %d/%d: %s\n", idx, total, message)
|
||||
fmt.Printf("Step %d/%d: %s\n", idx, total, message)
|
||||
}
|
||||
|
||||
func renderServiceTemplate(tpl, serviceName string) string {
|
||||
@@ -160,6 +156,7 @@ func renderServiceTemplate(tpl, serviceName string) string {
|
||||
|
||||
func translateMachineArch(value string) (string, error) {
|
||||
machine := strings.TrimSpace(strings.ToLower(value))
|
||||
|
||||
switch machine {
|
||||
case "x86_64", "amd64":
|
||||
return "amd64", nil
|
||||
@@ -175,6 +172,32 @@ func translateMachineArch(value string) (string, error) {
|
||||
return "", fmt.Errorf("unsupported remote architecture %q", value)
|
||||
}
|
||||
|
||||
func detectRemoteArch(server string) (string, error) {
|
||||
probes := []string{
|
||||
"uname -m",
|
||||
"arch",
|
||||
}
|
||||
var lastErr error
|
||||
for _, probe := range probes {
|
||||
output, err := runSSHOutput(server, probe)
|
||||
if err != nil {
|
||||
lastErr = fmt.Errorf("%s failed: %w", probe, err)
|
||||
continue
|
||||
}
|
||||
|
||||
arch, err := translateMachineArch(output)
|
||||
if err != nil {
|
||||
lastErr = fmt.Errorf("%s -> %w", probe, err)
|
||||
continue
|
||||
}
|
||||
return arch, nil
|
||||
}
|
||||
if lastErr != nil {
|
||||
return "", fmt.Errorf("failed to determine remote architecture: %w", lastErr)
|
||||
}
|
||||
return "", fmt.Errorf("failed to determine remote architecture")
|
||||
}
|
||||
|
||||
func pocketbaseAsset(version, osName, arch string) string {
|
||||
return fmt.Sprintf("pocketbase_%s_%s_%s.zip", version, osName, arch)
|
||||
}
|
||||
@@ -279,14 +302,14 @@ systemctl restart pb@%s
|
||||
}
|
||||
|
||||
func runSSHCommand(server, script string) error {
|
||||
cmd := exec.Command("ssh", append(sshArgs(server), "bash", "-lc", script)...)
|
||||
cmd := exec.Command("ssh", append(sshArgs(server), "bash", "--noprofile", "--norc", "-c", script)...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func runSSHOutput(server, script string) (string, error) {
|
||||
cmd := exec.Command("ssh", append(sshArgs(server), "bash", "-lc", script)...)
|
||||
cmd := exec.Command("ssh", append(sshArgs(server), "bash", "--noprofile", "--norc", "-c", script)...)
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
Reference in New Issue
Block a user