-
Notifications
You must be signed in to change notification settings - Fork 89
/
version_strategy.go
68 lines (57 loc) · 1.76 KB
/
version_strategy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package embeddedpostgres
import (
"fmt"
"os"
"os/exec"
"strings"
)
// VersionStrategy provides a strategy that can be used to determine which version of Postgres should be used based on
// the operating system, architecture and desired Postgres version.
type VersionStrategy func() (operatingSystem string, architecture string, postgresVersion PostgresVersion)
func defaultVersionStrategy(config Config, goos, arch string, linuxMachineName func() string, shouldUseAlpineLinuxBuild func() bool) VersionStrategy {
return func() (string, string, PostgresVersion) {
goos := goos
arch := arch
if goos == "linux" {
// the zonkyio/embedded-postgres-binaries project produces
// arm binaries with the following name schema:
// 32bit: arm32v6 / arm32v7
// 64bit (aarch64): arm64v8
if arch == "arm64" {
arch += "v8"
} else if arch == "arm" {
machineName := linuxMachineName()
if strings.HasPrefix(machineName, "armv7") {
arch += "32v7"
} else if strings.HasPrefix(machineName, "armv6") {
arch += "32v6"
}
}
if shouldUseAlpineLinuxBuild() {
arch += "-alpine"
}
}
// postgres below version 14.2 is not available for macos on arm
if goos == "darwin" && arch == "arm64" {
var majorVer, minorVer int
if _, err := fmt.Sscanf(string(config.version), "%d.%d", &majorVer, &minorVer); err == nil &&
(majorVer < 14 || (majorVer == 14 && minorVer < 2)) {
arch = "amd64"
} else {
arch += "v8"
}
}
return goos, arch, config.version
}
}
func linuxMachineName() string {
var uname string
if output, err := exec.Command("uname", "-m").Output(); err == nil {
uname = string(output)
}
return uname
}
func shouldUseAlpineLinuxBuild() bool {
_, err := os.Stat("/etc/alpine-release")
return err == nil
}