Skip to content

Commit cf67870

Browse files
authored
chore(deps): add linux arm support for postgrest (#268)
* chore(deps): add linux arm support for postgrest * chore: add support for mac os aarm64 in postgrest
1 parent 0e81adf commit cf67870

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

deps/deps.go

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,24 @@ import (
2323
// Dependency is a struct referring to a version and the templated path
2424
// to download the dependency on the different OS platforms
2525
type Dependency struct {
26-
Version string
27-
Linux, Macosx, Windows, Go, Docker string
28-
Template string
29-
BinaryName string
30-
PreInstalled []string
26+
Version string
27+
Linux string
28+
LinuxARM string
29+
Macosx string
30+
MacosxARM string
31+
Windows string
32+
Go string
33+
Docker string
34+
Template string
35+
BinaryName string
36+
PreInstalled []string
3137
}
3238

3339
// BinaryFunc is an interface to executing a binary, downloading it necessary
34-
type BinaryFunc func(msg string, args ...interface{}) error
40+
type BinaryFunc func(msg string, args ...any) error
3541

3642
// BinaryFuncWithEnv is an interface to executing a binary, downloading it necessary
37-
type BinaryFuncWithEnv func(msg string, env map[string]string, args ...interface{}) error
43+
type BinaryFuncWithEnv func(msg string, env map[string]string, args ...any) error
3844

3945
func (dependency *Dependency) GetPath(name string, binDir string) (string, error) {
4046
data := map[string]string{"os": runtime.GOOS, "platform": runtime.GOARCH, "version": dependency.Version}
@@ -62,7 +68,7 @@ func absolutePath(dir string) string {
6268
func BinaryWithEnv(name, ver string, binDir string, env map[string]string) BinaryFunc {
6369
name = strings.ToLower(name)
6470
binDir = absolutePath(binDir)
65-
return func(msg string, args ...interface{}) error {
71+
return func(msg string, args ...any) error {
6672
bin := fmt.Sprintf("%s/%s", binDir, name)
6773
if !files.Exists(binDir) {
6874
if err := os.MkdirAll(binDir, 0755); err != nil {
@@ -202,10 +208,12 @@ var dependencies = map[string]Dependency{
202208
Template: "https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-{{.version}}-{{.os}}-{{.platform}}.tar.gz",
203209
},
204210
"postgrest": {
205-
Version: "v12.2.0",
211+
Version: "v12.2.12",
206212
Linux: "https://github.com/PostgREST/postgrest/releases/download/{{.version}}/postgrest-{{.version}}-linux-static-x64.tar.xz",
213+
LinuxARM: "https://github.com/PostgREST/postgrest/releases/download/{{.version}}/postgrest-{{.version}}-ubuntu-aarch64.tar.xz ",
207214
Windows: "https://github.com/PostgREST/postgrest/releases/download/{{.version}}/postgrest-{{.version}}-windows-x64.zip",
208215
Macosx: "https://github.com/PostgREST/postgrest/releases/download/{{.version}}/postgrest-{{.version}}-macos-x64.tar.xz",
216+
MacosxARM: "https://github.com/PostgREST/postgrest/releases/download/{{.version}}/postgrest-{{.version}}-macos-aarch64.tar.xz",
209217
BinaryName: "postgrest",
210218
},
211219
"yq": {
@@ -259,8 +267,14 @@ func InstallDependency(name, ver string, binDir string) error {
259267
switch runtime.GOOS {
260268
case "linux":
261269
urlPath = dependency.Linux
270+
if strings.HasPrefix(runtime.GOARCH, "arm") && dependency.LinuxARM != "" {
271+
urlPath = dependency.LinuxARM
272+
}
262273
case "darwin":
263274
urlPath = dependency.Macosx
275+
if strings.HasPrefix(runtime.GOARCH, "arm") && dependency.MacosxARM != "" {
276+
urlPath = dependency.MacosxARM
277+
}
264278
case "windows":
265279
urlPath = dependency.Windows
266280
}
@@ -305,7 +319,7 @@ func Binary(name, ver string, binDir string) BinaryFunc {
305319

306320
dependency, ok := dependencies[name]
307321
if !ok {
308-
return func(msg string, args ...interface{}) error {
322+
return func(msg string, args ...any) error {
309323
if Which(name) {
310324
return exec.Execf(name+" "+msg, args...)
311325
}
@@ -314,15 +328,15 @@ func Binary(name, ver string, binDir string) BinaryFunc {
314328
}
315329

316330
if dependency.Docker != "" {
317-
return func(msg string, args ...interface{}) error {
331+
return func(msg string, args ...any) error {
318332
cwd, _ := os.Getwd()
319333
docker := fmt.Sprintf("docker run --rm -v %s:%s -w %s %s:%s ", cwd, cwd, cwd, dependency.Docker, ver)
320334
return exec.Execf(docker+msg, args...)
321335
}
322336
}
323337

324338
if len(dependency.PreInstalled) > 0 {
325-
return func(msg string, args ...interface{}) error {
339+
return func(msg string, args ...any) error {
326340
for _, bin := range dependency.PreInstalled {
327341
if Which(bin) {
328342
return exec.Execf(bin+" "+msg, args...)
@@ -332,7 +346,7 @@ func Binary(name, ver string, binDir string) BinaryFunc {
332346
}
333347
}
334348

335-
return func(msg string, args ...interface{}) error {
349+
return func(msg string, args ...any) error {
336350
if err := InstallDependency(name, ver, binDir); err != nil {
337351
return err
338352
}

0 commit comments

Comments
 (0)