Last active
November 10, 2018 15:05
-
-
Save briansorahan/7b299aec4fd09fd77b2be63244bab641 to your computer and use it in GitHub Desktop.
Smallest possible debian image with librdkafka Go bindings?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.11.2-stretch | |
RUN apt-get update -qq -y | |
RUN apt-get install -qq -y build-essential ca-certificates file make gcc | |
ENV RDKAFKA_VERSION=0.11.6 | |
ENV ZSTD_VERSION=1.3.5 | |
# Install zstd from source (debian package is a bit old, doesn't have support for dictionary compression). | |
RUN cd /root && \ | |
wget https://github.com/facebook/zstd/archive/v${ZSTD_VERSION}.tar.gz && \ | |
tar xzf v${ZSTD_VERSION}.tar.gz | |
WORKDIR /root/zstd-${ZSTD_VERSION} | |
RUN cd /root/zstd-${ZSTD_VERSION} && \ | |
make && \ | |
make install | |
# Install librdkafka from source and Go bindings. | |
RUN cd /root && \ | |
wget https://github.com/edenhill/librdkafka/archive/v${RDKAFKA_VERSION}.tar.gz && \ | |
tar xzf v${RDKAFKA_VERSION}.tar.gz | |
WORKDIR /root/librdkafka-${RDKAFKA_VERSION} | |
RUN STATIC_LIB_zstd=/root/zstd-1.3.5/lib/libzstd.a ./configure --enable-static --disable-sasl --disable-ssl | |
RUN make | |
RUN make install | |
RUN rm -rf /root/librdkafka-${RDKAFKA_VERSION} /root/v${RDKAFKA_VERSION}.tar.gz | |
RUN go get -ldflags '-linkmode external -extldflags "-static"' -tags 'static_all' github.com/confluentinc/confluent-kafka-go/kafka | |
WORKDIR /go/src/app | |
COPY . . | |
RUN go get -ldflags '-linkmode external -extldflags "-static"' -tags 'static_all' -v | |
RUN go build -ldflags '-linkmode external -extldflags "-static"' -tags 'static_all' -o /app | |
RUN ldd /app | |
FROM debian:stretch-slim | |
COPY --from=0 /etc/ssl /etc/ssl | |
COPY --from=0 /app /app | |
CMD ["/app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/confluentinc/confluent-kafka-go/kafka" | |
) | |
func main() { | |
_, _ = kafka.NewConsumer(&kafka.ConfigMap{}) | |
fmt.Println("hello world!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: .image | |
.image: Dockerfile $(wildcard *.go) | |
@docker build -t bsorahan/static-linking . | |
@touch $@ | |
clean: | |
@rm -rf .image | |
.PHONY: clean image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment