Skip to content

Instantly share code, notes, and snippets.

@lajosbencz
Last active November 7, 2023 23:25
Show Gist options
  • Save lajosbencz/c82c9e1537cd9b132dacdbd80fd7cf4e to your computer and use it in GitHub Desktop.
Save lajosbencz/c82c9e1537cd9b132dacdbd80fd7cf4e to your computer and use it in GitHub Desktop.
Go - Minimal Docker image with librdkafka dependency
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