Skip to content

Commit c9aefcb

Browse files
committed
feat(api): add configurable postgrest architecture override
Allow PGRST_ARCH environment variable to override the default runtime architecture when installing postgrest binary, enabling custom architecture targets.
1 parent c2aff69 commit c9aefcb

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

api/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var DefaultConfig = Config{
1414
Postgrest: PostgrestConfig{
1515
Version: "v14.6",
1616
DBRole: "postgrest_api",
17+
Arch: runtime.GOARCH,
1718
AnonDBRole: "",
1819
Port: 3000,
1920
AdminPort: 3001,
@@ -22,7 +23,9 @@ var DefaultConfig = Config{
2223
}
2324

2425
func init() {
26+
DefaultConfig.Postgrest = DefaultConfig.Postgrest.ReadEnv()
2527
v := DefaultConfig.Postgrest.Version
28+
2629
if strings.HasPrefix(v, "v14") && v != "v14.1" && v != "v14.0" &&
2730
runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" {
2831
logger.Warnf("PostgREST v14.2+ does not have a darwin/arm64 binary, defaulting to v14.1 for darwin/amd64")
@@ -124,6 +127,7 @@ type PostgrestConfig struct {
124127
LogLevel string
125128
URL string
126129
Version string
130+
Arch string
127131
JWTSecret string
128132
DBRole string
129133
AnonDBRole string
@@ -146,6 +150,9 @@ func (p PostgrestConfig) ReadEnv() PostgrestConfig {
146150
if v := os.Getenv("PGRST_VERSION"); v != "" {
147151
clone.Version = v
148152
}
153+
if v := os.Getenv("PGRST_ARCH"); v != "" {
154+
clone.Arch = v
155+
}
149156
return clone
150157
}
151158

postgrest/postgrest.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"path/filepath"
7+
"runtime"
78
"strconv"
89

910
"github.com/flanksource/commons/exec"
@@ -17,7 +18,10 @@ func GoOffline() error {
1718
}
1819

1920
func runBinary(config api.Config, msg string, args ...any) error {
20-
result, err := deps.InstallWithContext(context.Background(), "postgrest", config.Postgrest.Version, deps.WithBinDir(".bin"))
21+
result, err := deps.InstallWithContext(context.Background(), "postgrest",
22+
config.Postgrest.Version,
23+
deps.WithBinDir(".bin"),
24+
deps.WithOS(runtime.GOOS, config.Postgrest.Arch))
2125
if err != nil {
2226
return fmt.Errorf("failed to install postgREST: %w", err)
2327
}

0 commit comments

Comments
 (0)