confluentinc / confluent-kafka-go

Confluent's Apache Kafka Golang client
Apache License 2.0
4.66k stars 658 forks source link

Trying to static compile using alpine docker #595

Open pavankumar-go opened 3 years ago

pavankumar-go commented 3 years ago

Description

I'm trying statically compile using golang:1.15-alpine image

WORKDIR /src
COPY . .
RUN apk update && apk add --no-cache librdkafka librdkafka-dev build-base git ca-certificates pkgconf
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags '-extldflags "-static"' -o my-program

Getting below error

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lrdkafka
collect2: error: ld returned 1 exit status

Checklist

Please provide the following information:

pavankumar-go commented 3 years ago

Looks like prebuilt alpine librdkafka binaries didn't work with -ldflags '-extldflags "-static"' during static compile. instead added RUN git clone https://github.com/edenhill/librdkafka.git && cd librdkafka && ./configure --prefix /usr && make && make install - this worked! - was able to successfully static compile