-
Notifications
You must be signed in to change notification settings - Fork 661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go build -tags static #59
Comments
Will try to reproduce |
To help you reproduce, I'm builduing in a docker container : https://github.com/docker-library/golang/blob/master/1.8/Dockerfile, and the
|
@nicbaz Thanks! 💯 |
@edenhill I know you're busy with librdkafka itself but is there anything I can do to help you make progress on this issue? |
Sorry for the long delay @nicbaz, I've been very busy with librdkafka and now final release work so hadn't had time to look at this. I'll take a look early next week. My guess, after reading a bit more about pkg-config --static, is that we should remove the explicit LDFLAGS from build_static*.go |
No worries, thanks for the update ! |
@edenhill I was having a similar issue with building a "from scratch" docker image. I'm trying to understand the requirements here in order to static build a project using this library. What I'm running in my build stage of my Dockerfile Here is the error I receive:
EDIT My build stage is using the golang:latest docker image. Which include the pkg-config. |
confluent-kafka-go uses cgo to interact with the underlying kafka client implementation in librdkafka (which is a C library), so you must not disable CGO (CGO_ENABLED=0). |
Ok, I guess what I'm not sure about is what dependencies I need in the building stage of the program.
Here is my complete Dockerfile build stage
|
static_all is highly experimental, it is not likely to work with hand-holding. If you're making a docker image there isn't much need for a completely static client anyway, right? You can simple include the librdkafka dependencies (libssl, libsasl2, etc). |
Sure, and I've done so already. I'm just not happy with the effort. I read the README and it says it supports static builds. That doesn't seem to be the case or at least not very well documented. I'd be happy to document and create an example implementation. I'm not going to be only developer using kafka that will be looking for a "from scratch" approach to their go microservice consumer or producer. Thank you for your time regardless. |
@jdgiotta This works for me: FROM golang:1.10.1-alpine3.7
RUN apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/community/ \
bash \
gcc \
git \
librdkafka-dev \
libressl-dev \
musl-dev \
zlib-dev \
wget && \
#
# Install dep
wget -nv -O /usr/local/bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 && \
chmod a+rx /usr/local/bin/dep docker build -f Dockerfile -t elevy/golang:1.10.1-alpine3.7-librdkafka .
docker run -it -v `pwd`:/go/src/app elevy/golang:1.10.1-alpine3.7-librdkafka bash -c 'cd /go/src/app; rm app; dep ensure; go test -coverprofile cover.out -v; go tool cover -html=cover.out -o coverage.html; go build -tags static_all .' |
@eliaslevy awesome! That worked like a charm. |
Note for posterity that the above method has been broken for a bit since alpine edge moved to 3.8 and 3.7 had old librdkafka version 0.11.1. At the current moment there is no I came here with identical micro-service requirement as folks above, getting this working got my service docker image from ~400MB to ~12MB which has a big impact on boot time :) This raises the question, any interest here to host an alpine image somewhere with golang and librdkafka installed to base static builds on? If not, I'll probably make one on our hub for quicker builds once the golang alpine 3.8 image is out and post back here if that's helpful. |
If Alpine doesn't have the version of librdkafka you'd like, it is easy to build it within the container. You can find the build file here. Also, as the output is a static binary, you can always build in 3.7 and deploy in 3.8, or vice versa. But, yes, it would be nice to have a prepackaged image in Docker Hub. |
Hi, has anyone managed to produce a neat docker build image based on golang image ? |
Hi,
I'm having trouble building a binary with librdkafka as a static library.
As you can see
librdkafka
appears twice when linking.I tried playing with
pkg-config
but could not get the correctLDFLAGS
without-lrdfafka
.The only fix I could think of is manually setting
LDFLAGS
inkafka/build_static.go
:As I've never built with
cgo
before I might be doing something wrong, is this expected ?The text was updated successfully, but these errors were encountered: