Skip to content
This repository was archived by the owner on Aug 30, 2025. It is now read-only.

Commit 3177ff7

Browse files
authored
Revert "NEOS-1360: enables cgo for worker to enable postgres query pa… (#2527)
1 parent a83e43b commit 3177ff7

File tree

9 files changed

+40
-90
lines changed

9 files changed

+40
-90
lines changed

compose.dev.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ services:
113113
container_name: neosync-worker
114114
image: neosync-worker
115115
build:
116-
context: ./
117-
dockerfile: ./worker/dev/build/Dockerfile.dev
116+
context: ./worker
117+
dockerfile: ./dev/build/Dockerfile.dev
118118
environment:
119119
- NUCLEUS_ENV=dev
120120
- TEMPORAL_URL=temporal:7233
@@ -127,16 +127,11 @@ services:
127127
networks:
128128
- neosync-network
129129
- temporal-network
130-
volumes:
131-
- neosync_worker_build_cache:/root/.cache/go-build
132130
develop:
133131
watch:
134-
- action: rebuild
135-
path: internal/
136-
target: /workspacse
137-
- action: rebuild
138-
path: worker/
139-
target: /workspace
132+
- path: worker/bin
133+
action: rebuild
134+
target: /app
140135
restart: on-failure
141136

142137
redis:
@@ -153,7 +148,6 @@ services:
153148
volumes:
154149
neosync_redis_cache:
155150
neosync_pg_data:
156-
neosync_worker_build_cache:
157151

158152
networks:
159153
neosync-network:

docker/Dockerfile.backend

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ WORKDIR /workspace
1212
COPY worker/ worker/
1313
COPY internal/ internal/
1414

15+
# COPY tools.go tools.go
16+
# COPY Makefile Makefile
17+
# RUN make install-go-tools
18+
19+
# ENV PATH="$PATH:$(go env GOPATH)/bin"
20+
# ENV GOBIN="$PWD/bin"
21+
# ENV PATH="$PATH:$GOBIN"
22+
1523
# Define build arguments
1624
ARG buildDate="1970-01-01T00:00:00Z"
1725
ARG gitCommit=""

docker/Dockerfile.worker

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.22-bookworm AS builder
3-
4-
RUN apt-get update \
5-
&& DEBIAN_FRONTEND=noninteractive \
6-
apt-get install --no-install-recommends -y \
7-
build-essential
2+
FROM golang:1.22 as builder
83

94
WORKDIR /workspace
105
# Copy the Go Modules manifests
@@ -27,24 +22,12 @@ COPY worker/pkg/ pkg/
2722
# Build
2823
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o bin/worker cmd/worker/*.go
2924

30-
# Use debian:bullseye-slim as the base image to include necessary C libraries
31-
FROM debian:bookworm-slim
25+
# Use distroless as minimal base image to package the manager binary
26+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
27+
FROM gcr.io/distroless/static:nonroot
3228
WORKDIR /
33-
34-
# Install CA certificates for HTTPS connections
35-
RUN apt-get update \
36-
&& DEBIAN_FRONTEND=noninteractive \
37-
apt-get install --no-install-recommends -y ca-certificates \
38-
&& rm -rf /var/lib/apt/lists/*
39-
4029
COPY --from=builder /workspace/worker/bin/worker .
41-
42-
# Install any runtime dependencies if needed
43-
# RUN apt-get update && apt-get install -y <your-dependencies> && rm -rf /var/lib/apt/lists/*
44-
45-
# Create a non-root user
46-
RUN useradd -u 65532 -r nonroot
47-
USER nonroot
30+
USER 65532:65532
4831

4932
ENTRYPOINT ["/worker"]
5033

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ require (
5757
github.com/testcontainers/testcontainers-go/modules/redis v0.32.0
5858
github.com/toqueteos/webbrowser v1.2.0
5959
github.com/warpstreamlabs/bento v1.1.0
60+
github.com/wasilibs/go-pgquery v0.0.0-20240606042535-c0843d6592cc
6061
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
6162
github.com/zeebo/assert v1.3.1
6263
go.mongodb.org/mongo-driver v1.16.1
@@ -177,7 +178,6 @@ require (
177178
github.com/clbanning/mxj/v2 v2.7.0 // indirect
178179
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 // indirect
179180
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b // indirect
180-
github.com/cockroachdb/apd v1.1.1-0.20181017181144-bced77f817b4 // indirect
181181
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
182182
github.com/cockroachdb/cockroach-go/v2 v2.1.1 // indirect
183183
github.com/containerd/containerd v1.7.18 // indirect
@@ -387,6 +387,7 @@ require (
387387
github.com/urfave/cli/v2 v2.27.1 // indirect
388388
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
389389
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
390+
github.com/wasilibs/wazero-helpers v0.0.0-20240604052452-61d7981e9a38 // indirect
390391
github.com/x448/float16 v0.8.4 // indirect
391392
github.com/xanzy/go-gitlab v0.15.0 // indirect
392393
github.com/xdg-go/pbkdf2 v1.0.0 // indirect

go.sum

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,9 +974,8 @@ github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWH
974974
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
975975
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b h1:ga8SEFjZ60pxLcmhnThWgvH2wg8376yUJmPhEH4H3kw=
976976
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
977+
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
977978
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
978-
github.com/cockroachdb/apd v1.1.1-0.20181017181144-bced77f817b4 h1:XWEdfNxDkZI3DXXlpo0hZJ1xdaH/f3CKuZpk93pS/Y0=
979-
github.com/cockroachdb/apd v1.1.1-0.20181017181144-bced77f817b4/go.mod h1:mdGz2CnkJrefFtlLevmE7JpL2zB9tKofya/6w7wWzNA=
980979
github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg=
981980
github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc=
982981
github.com/cockroachdb/cockroach-go/v2 v2.1.1 h1:3XzfSMuUT0wBe1a3o5C0eOTcArhmmFAg2Jzh/7hhKqo=
@@ -1745,7 +1744,6 @@ github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef
17451744
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
17461745
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
17471746
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
1748-
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
17491747
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
17501748
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
17511749
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -1941,6 +1939,10 @@ github.com/wI2L/jsondiff v0.4.0 h1:iP56F9tK83eiLttg3YdmEENtZnwlYd3ezEpNNnfZVyM=
19411939
github.com/wI2L/jsondiff v0.4.0/go.mod h1:nR/vyy1efuDeAtMwc3AF6nZf/2LD1ID8GTyyJ+K8YB0=
19421940
github.com/warpstreamlabs/bento v1.1.0 h1:7kc4sdtWjpv9glKG9WI1zM7ywP1LI+LIkL4rTk6PGJQ=
19431941
github.com/warpstreamlabs/bento v1.1.0/go.mod h1:rWbBdeYUJ3aKawP6J99fGZAUrTndseKt39AwMFoh/vg=
1942+
github.com/wasilibs/go-pgquery v0.0.0-20240606042535-c0843d6592cc h1:Hgim1Xgk1+viV7p0aZh9OOrMRfG+E4mGA+JsI2uB0+k=
1943+
github.com/wasilibs/go-pgquery v0.0.0-20240606042535-c0843d6592cc/go.mod h1:ah6UfXIl/oA0K3SbourB/UHggVJOBXwPZ2XudDmmFac=
1944+
github.com/wasilibs/wazero-helpers v0.0.0-20240604052452-61d7981e9a38 h1:RBu75fhabyxyGJ2zhkoNuRyObBMhVeMoXqmeaPTg2CQ=
1945+
github.com/wasilibs/wazero-helpers v0.0.0-20240604052452-61d7981e9a38/go.mod h1:Z80JvMwvze8KUlVQIdw9L7OSskZJ1yxlpi4AQhoQe4s=
19441946
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
19451947
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
19461948
github.com/xanzy/go-gitlab v0.15.0 h1:rWtwKTgEnXyNUGrOArN7yyc3THRkpYcKXIXia9abywQ=

worker/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ vet: ## Runs go vet
1717
build: gen vet ## Generates code, runs go vet and builds the project
1818
scripts/build.sh
1919

20-
dbuild: build
20+
dbuild: gen vet ## Generates code, runs go vet, and builds the project specifically for Linux
21+
GOOS=linux scripts/build.sh
2122

2223
run: ## Runs the project
2324
./bin/sync serve

worker/dev/build/Dockerfile.dev

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,12 @@
1-
# Build the manager binary
2-
FROM golang:1.22-bookworm as builder
1+
FROM alpine:3.18
32

4-
RUN apt-get update \
5-
&& DEBIAN_FRONTEND=noninteractive \
6-
apt-get install --no-install-recommends -y \
7-
build-essential
3+
RUN mkdir -p .config/helm/registry
4+
RUN mkdir /app
85

9-
WORKDIR /workspace
10-
# Copy the Go Modules manifests
11-
COPY go.mod go.mod
12-
COPY go.sum go.sum
6+
WORKDIR /app
137

14-
RUN go mod download
8+
RUN echo 'NUCLEUS_ENV=dev' > /app/.env
159

16-
WORKDIR /workspace
17-
COPY backend/ backend/
18-
COPY internal/ internal/
10+
COPY /bin/worker /app
1911

20-
WORKDIR /workspace/worker
21-
22-
# Copy the go source
23-
COPY worker/cmd/ cmd/
24-
COPY worker/internal/ internal/
25-
COPY worker/pkg/ pkg/
26-
27-
# Build
28-
RUN --mount=type=cache,target=/root/.cache/go-build \
29-
go build -ldflags="-s -w" -o bin/worker cmd/worker/*.go
30-
31-
# Use debian:bullseye-slim as the base image to include necessary C libraries
32-
FROM debian:bookworm-slim
33-
WORKDIR /
34-
35-
# Install CA certificates for HTTPS connections
36-
RUN apt-get update \
37-
&& DEBIAN_FRONTEND=noninteractive \
38-
apt-get install --no-install-recommends -y ca-certificates \
39-
&& rm -rf /var/lib/apt/lists/*
40-
41-
COPY --from=builder /workspace/worker/bin/worker .
42-
43-
# Install any runtime dependencies if needed
44-
# RUN apt-get update && apt-get install -y <your-dependencies> && rm -rf /var/lib/apt/lists/*
45-
46-
# Create a non-root user
47-
RUN useradd -u 65532 -r nonroot
48-
USER nonroot
49-
50-
ENTRYPOINT ["/worker"]
51-
52-
CMD ["serve"]
12+
ENTRYPOINT ["/app/worker", "serve"]

worker/pkg/query-builder2/querybuilder.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/doug-martin/goqu/v9/sqlgen"
1010
sqlmanager_shared "github.com/nucleuscloud/neosync/backend/pkg/sqlmanager/shared"
1111
pg_query "github.com/pganalyze/pg_query_go/v5"
12+
pgquery "github.com/wasilibs/go-pgquery"
1213
"github.com/xwb1989/sqlparser"
1314
)
1415

@@ -260,7 +261,7 @@ func (qb *QueryBuilder) qualifyWhereCondition(schema *string, table, condition s
260261
}
261262

262263
func qualifyPostgresWhereColumnNames(sql string, schema *string, table string) (string, error) {
263-
tree, err := pg_query.Parse(sql)
264+
tree, err := pgquery.Parse(sql)
264265
if err != nil {
265266
return "", err
266267
}
@@ -272,7 +273,7 @@ func qualifyPostgresWhereColumnNames(sql string, schema *string, table string) (
272273
updatePostgresExpr(schema, table, selectStmt.WhereClause)
273274
}
274275
}
275-
updatedSql, err := pg_query.Deparse(tree)
276+
updatedSql, err := pgquery.Deparse(tree)
276277
if err != nil {
277278
return "", err
278279
}

worker/scripts/build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
if [ ! -z "${TILT_HOST}" ]; then
44
# when invoked by tilt set the OS so that binary will run on linux container
5-
GOOS=linux go build -ldflags="-s -w" -o bin/worker cmd/worker/*.go
5+
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o bin/worker cmd/worker/*.go
66
elif [ ! -z "${GOOS}" ]; then
7-
GOOS="${GOOS}" go build -ldflags="-s -w" -o bin/worker cmd/worker/*.go
7+
CGO_ENABLED=0 GOOS="${GOOS}" go build -ldflags="-s -w" -o bin/worker cmd/worker/*.go
88
else
9-
go build -ldflags="-s -w" -o bin/worker cmd/worker/*.go
9+
CGO_ENABLED=0 go build -ldflags="-s -w" -o bin/worker cmd/worker/*.go
1010
fi

0 commit comments

Comments
 (0)