Skip to content

Commit 5c58d7c

Browse files
authored
Remove CGO Dependency from PostgreSQL FDW (#2860)
1 parent d4b1b63 commit 5c58d7c

File tree

13 files changed

+32
-72
lines changed

13 files changed

+32
-72
lines changed

Dockerfile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# use `docker buildx imagetools inspect <image>` to get the multi-platform sha256
2-
# Note: Using Debian-based golang image (not alpine) to build with glibc for postgres-fdw support
3-
FROM golang:1.25.6@sha256:ce63a16e0f7063787ebb4eb28e72d477b00b4726f79874b3205a965ffd797ab2 AS spicedb-builder
2+
FROM golang:1.25.6-alpine@sha256:660f0b83cf50091e3777e4730ccc0e63e83fea2c420c872af5c60cb357dcafb2 AS spicedb-builder
43
WORKDIR /go/src/app
5-
RUN apt-get update && apt-get install -y --no-install-recommends git gcc libc6-dev && rm -rf /var/lib/apt/lists/*
4+
RUN apk update && apk add --no-cache git
65
COPY . .
76
# https://github.com/odigos-io/go-rtml#about-ldflags-checklinkname0
8-
# Build with CGO enabled for postgres-fdw support
9-
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg/mod CGO_ENABLED=1 go build -tags memoryprotection -v -ldflags=-checklinkname=0 -o spicedb ./cmd/spicedb
7+
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg/mod CGO_ENABLED=0 go build -tags memoryprotection -v -ldflags=-checklinkname=0 -o spicedb ./cmd/spicedb
108

119
# use `docker buildx imagetools inspect <image>` to get the multi-platform sha256
1210
FROM golang:1.25.6-alpine@sha256:660f0b83cf50091e3777e4730ccc0e63e83fea2c420c872af5c60cb357dcafb2 AS health-probe-builder
@@ -18,8 +16,7 @@ RUN git checkout main
1816
RUN CGO_ENABLED=0 go install -a -tags netgo -ldflags=-w
1917

2018
# use `docker buildx imagetools inspect <image>` to get the multi-platform sha256
21-
# Note: Using glibc-dynamic base instead of static because the postgres-fdw command requires libc
22-
FROM cgr.dev/chainguard/glibc-dynamic@sha256:3f5dc064fa077619b186d21a426c07fb3868668ffe104db8ba3e46347a80a1d3
19+
FROM cgr.dev/chainguard/static@sha256:99a5f826e71115aef9f63368120a6aa518323e052297718e9bf084fb84def93c
2320
COPY --from=health-probe-builder /go/bin/grpc-health-probe /bin/grpc_health_probe
2421
COPY --from=spicedb-builder /go/src/app/spicedb /usr/local/bin/spicedb
2522
ENV PATH="$PATH:/usr/local/bin"

Dockerfile.release

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# vim: syntax=dockerfile
22
# use `docker buildx imagetools inspect <image>` to get the multi-platform sha256
3-
# Note: Using glibc-dynamic base instead of static because the postgres-fdw command requires libc
4-
ARG BASE=cgr.dev/chainguard/glibc-dynamic@sha256:3f5dc064fa077619b186d21a426c07fb3868668ffe104db8ba3e46347a80a1d3
3+
ARG BASE=cgr.dev/chainguard/static@sha256:99a5f826e71115aef9f63368120a6aa518323e052297718e9bf084fb84def93c
54
FROM golang:1.25.6-alpine@sha256:660f0b83cf50091e3777e4730ccc0e63e83fea2c420c872af5c60cb357dcafb2 AS health-probe-builder
65
WORKDIR /go/src/app
76
RUN apk update && apk add --no-cache git

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ require (
101101
github.com/spf13/cobra v1.10.2
102102
github.com/spf13/pflag v1.0.10
103103
github.com/stretchr/testify v1.11.1
104+
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07
104105
go.opencensus.io v0.24.0
105106
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.63.0
106107
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0
@@ -399,6 +400,7 @@ require (
399400
github.com/stretchr/objx v0.5.2 // indirect
400401
github.com/subosito/gotenv v1.6.0 // indirect
401402
github.com/tetafro/godot v1.5.4 // indirect
403+
github.com/tetratelabs/wazero v1.9.0 // indirect
402404
github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67 // indirect
403405
github.com/timonwong/loggercheck v0.11.0 // indirect
404406
github.com/tomarrell/wrapcheck/v2 v2.11.0 // indirect
@@ -407,6 +409,7 @@ require (
407409
github.com/ultraware/whitespace v0.2.0 // indirect
408410
github.com/uudashr/gocognit v1.2.0 // indirect
409411
github.com/uudashr/iface v1.4.1 // indirect
412+
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect
410413
github.com/x448/float16 v0.8.4 // indirect
411414
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
412415
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,8 @@ github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpR
16891689
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY=
16901690
github.com/tetafro/godot v1.5.4 h1:u1ww+gqpRLiIA16yF2PV1CV1n/X3zhyezbNXC3E14Sg=
16911691
github.com/tetafro/godot v1.5.4/go.mod h1:eOkMrVQurDui411nBY2FA05EYH01r14LuWY/NrVDVcU=
1692+
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
1693+
github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM=
16921694
github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67 h1:9LPGD+jzxMlnk5r6+hJnar67cgpDIz/iyD+rfl5r2Vk=
16931695
github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67/go.mod h1:mkjARE7Yr8qU23YcGMSALbIxTQ9r9QBVahQOBRfU460=
16941696
github.com/timonwong/loggercheck v0.11.0 h1:jdaMpYBl+Uq9mWPXv1r8jc5fC3gyXx4/WGwTnnNKn4M=
@@ -1707,6 +1709,10 @@ github.com/uudashr/gocognit v1.2.0 h1:3BU9aMr1xbhPlvJLSydKwdLN3tEUUrzPSSM8S4hDYR
17071709
github.com/uudashr/gocognit v1.2.0/go.mod h1:k/DdKPI6XBZO1q7HgoV2juESI2/Ofj9AcHPZhBBdrTU=
17081710
github.com/uudashr/iface v1.4.1 h1:J16Xl1wyNX9ofhpHmQ9h9gk5rnv2A6lX/2+APLTo0zU=
17091711
github.com/uudashr/iface v1.4.1/go.mod h1:pbeBPlbuU2qkNDn0mmfrxP2X+wjPMIQAy+r1MBXSXtg=
1712+
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 h1:mJdDDPblDfPe7z7go8Dvv1AJQDI3eQ/5xith3q2mFlo=
1713+
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07/go.mod h1:Ak17IJ037caFp4jpCw/iQQ7/W74Sqpb1YuKJU6HTKfM=
1714+
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4=
1715+
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY=
17101716
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
17111717
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
17121718
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=

internal/fdw/pgserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"sync"
88

99
wire "github.com/jeroenrinzema/psql-wire"
10-
pg_query "github.com/pganalyze/pg_query_go/v6"
10+
pgquery "github.com/wasilibs/go-pgquery"
1111

1212
"github.com/authzed/authzed-go/v1"
1313

@@ -113,7 +113,7 @@ func (p *PgBackend) Close() error {
113113
}
114114

115115
func (p *PgBackend) handler(ctx context.Context, query string) (wire.PreparedStatements, error) {
116-
parsed, err := pg_query.Parse(query)
116+
parsed, err := pgquery.Parse(query)
117117
if err != nil {
118118
return nil, fmt.Errorf("failed to parse query: %w", err)
119119
}

internal/fdw/tables/delete_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"context"
55
"testing"
66

7-
pg_query "github.com/pganalyze/pg_query_go/v6"
87
"github.com/stretchr/testify/require"
8+
pgquery "github.com/wasilibs/go-pgquery"
99
)
1010

1111
func TestParseDeleteStatement(t *testing.T) {
@@ -95,7 +95,7 @@ func TestParseDeleteStatement(t *testing.T) {
9595
t.Run(tc.name, func(t *testing.T) {
9696
t.Parallel()
9797

98-
parsed, err := pg_query.Parse(tc.query)
98+
parsed, err := pgquery.Parse(tc.query)
9999
require.NoError(t, err)
100100

101101
ctx := context.Background()
@@ -149,7 +149,7 @@ func TestDeleteStatementReturningColumns(t *testing.T) {
149149
t.Run(tc.name, func(t *testing.T) {
150150
t.Parallel()
151151

152-
parsed, err := pg_query.Parse(tc.query)
152+
parsed, err := pgquery.Parse(tc.query)
153153
require.NoError(t, err)
154154

155155
ctx := context.Background()

internal/fdw/tables/insert_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"context"
55
"testing"
66

7-
pg_query "github.com/pganalyze/pg_query_go/v6"
87
"github.com/stretchr/testify/require"
8+
pgquery "github.com/wasilibs/go-pgquery"
99
)
1010

1111
func TestParseInsertStatement(t *testing.T) {
@@ -103,7 +103,7 @@ func TestParseInsertStatement(t *testing.T) {
103103
t.Run(tc.name, func(t *testing.T) {
104104
t.Parallel()
105105

106-
parsed, err := pg_query.Parse(tc.query)
106+
parsed, err := pgquery.Parse(tc.query)
107107
require.NoError(t, err)
108108

109109
ctx := context.Background()
@@ -146,7 +146,7 @@ func TestInsertStatementReturningColumns(t *testing.T) {
146146
t.Run(tc.name, func(t *testing.T) {
147147
t.Parallel()
148148

149-
parsed, err := pg_query.Parse(tc.query)
149+
parsed, err := pgquery.Parse(tc.query)
150150
require.NoError(t, err)
151151

152152
ctx := context.Background()

internal/fdw/tables/matcher_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package tables
33
import (
44
"testing"
55

6-
pg_query "github.com/pganalyze/pg_query_go/v6"
76
"github.com/stretchr/testify/require"
7+
pgquery "github.com/wasilibs/go-pgquery"
88
)
99

1010
func TestPatternMatcher(t *testing.T) {
@@ -66,7 +66,7 @@ func TestPatternMatcher(t *testing.T) {
6666
t.Run(tc.name, func(t *testing.T) {
6767
t.Parallel()
6868

69-
parsed, err := pg_query.Parse(tc.query)
69+
parsed, err := pgquery.Parse(tc.query)
7070
require.NoError(t, err)
7171

7272
selectStmt := parsed.Stmts[0].Stmt.GetSelectStmt()
@@ -134,7 +134,7 @@ func TestEqualityPattern(t *testing.T) {
134134
t.Run(tc.name, func(t *testing.T) {
135135
t.Parallel()
136136

137-
parsed, err := pg_query.Parse(tc.query)
137+
parsed, err := pgquery.Parse(tc.query)
138138
require.NoError(t, err)
139139

140140
selectStmt := parsed.Stmts[0].Stmt.GetSelectStmt()
@@ -187,7 +187,7 @@ func TestSubQueryPlaceholderPattern(t *testing.T) {
187187
t.Run(tc.name, func(t *testing.T) {
188188
t.Parallel()
189189

190-
parsed, err := pg_query.Parse(tc.query)
190+
parsed, err := pgquery.Parse(tc.query)
191191
require.NoError(t, err)
192192

193193
selectStmt := parsed.Stmts[0].Stmt.GetSelectStmt()
@@ -240,7 +240,7 @@ func TestColumnRefPattern(t *testing.T) {
240240
t.Run(tc.name, func(t *testing.T) {
241241
t.Parallel()
242242

243-
parsed, err := pg_query.Parse(tc.query)
243+
parsed, err := pgquery.Parse(tc.query)
244244
require.NoError(t, err)
245245

246246
selectStmt := parsed.Stmts[0].Stmt.GetSelectStmt()
@@ -266,7 +266,7 @@ func TestColumnRefPattern(t *testing.T) {
266266
// BenchmarkPatternMatcher compares the performance of pattern matching vs old approach
267267
func BenchmarkPatternMatcher(b *testing.B) {
268268
query := "SELECT * FROM relationships WHERE resource_type = 'document' AND resource_id = 'doc1' AND relation = 'viewer'"
269-
parsed, err := pg_query.Parse(query)
269+
parsed, err := pgquery.Parse(query)
270270
require.NoError(b, err)
271271

272272
selectStmt := parsed.Stmts[0].Stmt.GetSelectStmt()

internal/fdw/tables/select_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package tables
33
import (
44
"testing"
55

6-
pg_query "github.com/pganalyze/pg_query_go/v6"
76
"github.com/stretchr/testify/require"
7+
pgquery "github.com/wasilibs/go-pgquery"
88
)
99

1010
func TestParseSelectStatement(t *testing.T) {
@@ -175,7 +175,7 @@ func TestParseSelectStatement(t *testing.T) {
175175
t.Run(tc.name, func(t *testing.T) {
176176
t.Parallel()
177177

178-
parsed, err := pg_query.Parse(tc.query)
178+
parsed, err := pgquery.Parse(tc.query)
179179
require.NoError(t, err)
180180

181181
slc, err := ParseSelectStatement(parsed.Stmts[0].Stmt.GetSelectStmt(), false)

internal/fdw/tables/util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"testing"
55

66
wire "github.com/jeroenrinzema/psql-wire"
7-
pg_query "github.com/pganalyze/pg_query_go/v6"
87
"github.com/stretchr/testify/require"
8+
pgquery "github.com/wasilibs/go-pgquery"
99
)
1010

1111
func TestStringValue(t *testing.T) {
@@ -162,7 +162,7 @@ func TestReturningColumnsFromQuery(t *testing.T) {
162162
t.Run(tc.name, func(t *testing.T) {
163163
t.Parallel()
164164

165-
parsed, err := pg_query.Parse(tc.query)
165+
parsed, err := pgquery.Parse(tc.query)
166166
require.NoError(t, err)
167167
require.NotEmpty(t, parsed.Stmts)
168168

0 commit comments

Comments
 (0)