Skip to content

Commit 489ebd0

Browse files
author
Qizhong Mao
committed
Link to system-installed zmq without building
Signed-off-by: Qizhong Mao <[email protected]>
1 parent 5460339 commit 489ebd0

File tree

5 files changed

+27
-45
lines changed

5 files changed

+27
-45
lines changed

.github/workflows/installation-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ jobs:
9797
with:
9898
go-version: '1.22'
9999

100+
- name: Install ZMQ dependencies
101+
run: sudo apt-get update && sudo apt-get install -y libkrb5-dev libzmq3-dev
102+
100103
- name: Download all image artifacts
101104
uses: actions/download-artifact@v4
102105

.github/workflows/lint-and-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
with:
6969
go-version: '1.22'
7070
- name: Install ZMQ dependencies
71-
run: sudo apt-get update && sudo apt-get install -y libzmq3-dev
71+
run: sudo apt-get update && sudo apt-get install -y libkrb5-dev libzmq3-dev
7272

7373
# github action has errors, requires debugging
7474
# - name: Cache Go modules

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ build-controller-manager: manifests generate fmt vet ## Build controller-manager
148148

149149
.PHONY: build-gateway-plugins
150150
build-gateway-plugins: manifests generate fmt vet ## Build gateway-plugins binary with ZMQ.
151-
CGO_ENABLED=1 go build -tags="zmq" -o bin/gateway-plugins cmd/plugins/main.go
151+
CGO_ENABLED=1 \
152+
CGO_LDFLAGS='-Wl,-Bstatic -l:libzmq.a -l:libsodium.a -l:libnorm.a -l:libprotokit.a -l:libpgm.a -Wl,-Bdynamic -lbsd -lkrb5 -lgssapi_krb5 -lk5crypto -lpthread -lm -lstdc++' \
153+
go build -tags="zmq" \
154+
-ldflags='-extldflags "$(CGO_LDFLAGS)"' \
155+
-o bin/gateway-plugins cmd/plugins/main.go
152156

153157
.PHONY: build-metadata-service
154158
build-metadata-service: manifests generate fmt vet ## Build metadata-service binary without ZMQ.

build/container/Dockerfile.gateway

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@ ARG TARGETARCH
55

66
WORKDIR /workspace
77

8-
# Install build dependencies for static ZMQ
98
RUN apt-get update && apt-get install -y \
10-
build-essential cmake git wget pkg-config \
11-
libtool autoconf automake
12-
13-
# Build static libzmq
14-
COPY scripts/build-static-zmq.sh /tmp/
15-
RUN chmod +x /tmp/build-static-zmq.sh && /tmp/build-static-zmq.sh
9+
libkrb5-dev libnorm-dev libpgm-dev libzmq3-dev
1610

1711
# Copy the Go Modules manifests
1812
COPY go.mod go.mod
@@ -26,14 +20,27 @@ COPY cmd/ cmd/
2620
COPY api/ api/
2721
COPY pkg/ pkg/
2822

29-
# Build with static linking
3023
ENV CGO_ENABLED=1
31-
ENV CGO_LDFLAGS="-L/usr/local/lib -lzmq -lsodium -lstdc++ -lpthread -lm -static"
32-
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
24+
# - zmq links to sodium, norm, pgm and bsd and krb5
25+
# - norm links to protokit
26+
# - krb4 links to gssapi_krb5 and k5crypto
27+
ENV CGO_LDFLAGS="\
28+
-Wl,-Bstatic \
29+
-l:libzmq.a \
30+
-l:libsodium.a \
31+
-l:libnorm.a \
32+
-l:libprotokit.a \
33+
-l:libpgm.a \
34+
-Wl,-Bdynamic \
35+
-lbsd \
36+
-lkrb5 \
37+
-lgssapi_krb5 \
38+
-lk5crypto \
39+
-lpthread -lm -lstdc++"
3340

3441
RUN GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} \
3542
go build -tags zmq \
36-
-ldflags '-extldflags "-static"' \
43+
-ldflags "-extldflags '${CGO_LDFLAGS}'" \
3744
-a -o gateway-plugins cmd/plugins/main.go
3845

3946
# Use distroless as minimal base image to package the manager binary

scripts/build-static-zmq.sh

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)