Last active
November 7, 2023 23:25
-
-
Save lajosbencz/c82c9e1537cd9b132dacdbd80fd7cf4e to your computer and use it in GitHub Desktop.
Go - Minimal Docker image with librdkafka dependency
This file contains hidden or 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
ARG USER=nobody | |
# build image | |
FROM golang:1.21-alpine AS builder | |
ENV PATH="/go/bin:${PATH}" | |
ENV CGO_ENABLED=1 | |
ENV GOOS=linux | |
ENV GOARCH=amd64 | |
RUN apk --no-cache add ca-certificates bash sudo pkgconf git build-base | |
WORKDIR /go/src | |
COPY . . | |
RUN git clone https://github.com/confluentinc/librdkafka.git && \ | |
cd librdkafka && \ | |
./configure --prefix /usr && \ | |
make && \ | |
make install | |
RUN go build -tags musl --ldflags "-s -w -extldflags -static" -o app . | |
# final image | |
FROM scratch | |
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | |
COPY --from=builder /go/src/app / | |
USER $USER | |
ENTRYPOINT ["/app"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment