diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a500356..0bca877 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -172,13 +172,13 @@ jobs: with: context: . file: ./Dockerfile.consumer - platforms: linux/arm64 + platforms: linux/amd64 push: true provenance: false tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} -# cache-from: type=gha -# cache-to: type=gha,mode=max + cache-from: type=gha + cache-to: type=gha,mode=max - name: Output container image digest run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..684f9d0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# docker buildx build --build-arg TARGETARCH=arm64 --platform linux/arm64 --file Dockerfile -t kafka-confluent-go-consumer:latest . + +FROM --platform=linux/$TARGETARCH golang:1.21.3-alpine as builder + +ARG TARGETARCH +RUN echo $TARGETARCH + +# librdkafka package for alpine yet +# https://pkgs.alpinelinux.org/packages?name=librdkafka-dev&branch=edge&repo=&arch=&maintainer=John%20Anthony +RUN apk add musl-dev librdkafka-dev ca-certificates git gcc g++ libtool libc-dev pkgconf +RUN apk add build-base coreutils make musl-dev rpm wget curl cyrus-sasl-dev libevent libsasl lz4-dev openssh openssl openssl-dev yajl-dev zlib-dev + +ENV LIBRD_VER=2.3.0 +# Install librdkafka $LIBRD_VER +# https://gist.github.com/jaihind213/e82d41dc79f52cfa64ca32350bdb27df +#RUN apk --no-cache add ca-certificates git gcc g++ libtool libc-dev musl-dev pkgconf +#RUN apk add build-base coreutils make musl-dev rpm wget curl cyrus-sasl-dev libevent libsasl lz4-dev openssh openssl openssl-dev yajl-dev zlib-dev + +#RUN echo " ------> Install librdkafka..." +#RUN apk add --no-cache --virtual .make-deps bash make wget git gcc g++ +#RUN apk add --no-cache musl-dev zlib-dev openssl zstd-dev pkgconfig libc-dev +#RUN wget /~https://github.com/edenhill/librdkafka/archive/v${LIBRD_VER}.tar.gz && tar -xvf v${LIBRD_VER}.tar.gz && cd librdkafka-${LIBRD_VER} && ./configure --prefix /usr && make && make install && make clean && rm -rf librdkafka-${LIBRD_VER} && rm -rf v${LIBRD_VER}.tar.gz && apk del .make-deps + +#RUN apk add --no-cache --virtual .make-deps bash make wget git gcc g++ && apk add --no-cache musl-dev zlib-dev openssl zstd-dev pkgconfig libc-dev +#RUN wget /~https://github.com/edenhill/librdkafka/archive/v${LIBRD_VER}.tar.gz +#RUN tar -xvf v${LIBRD_VER}.tar.gz && cd librdkafka-${LIBRD_VER} && ./configure --prefix /usr && make && make install +#RUN export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig/ +#ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig/ + +WORKDIR /app +COPY go.mod . +COPY go.sum . +RUN go mod download +COPY . . +RUN CGO_ENABLED=1 GOOS=linux GOARCH=$TARGETARCH go build -tags musl --ldflags "-extldflags -static" -a -o consumer consumer/consumer.go + +FROM alpine:3.18.4 as runtime +COPY --from=builder /app/consumer / +EXPOSE 8080 +CMD ["/bin/sh", "-c", "/consumer"] diff --git a/Dockerfile.consumer b/Dockerfile.consumer index 22beeb7..779c3fc 100644 --- a/Dockerfile.consumer +++ b/Dockerfile.consumer @@ -1,36 +1,27 @@ -# docker buildx build --build-arg TARGETARCH=arm64 --file Dockerfile.consumer -t kafka-confluent-go-consumer:latest . +# docker buildx build --platform linux/arm64 --file Dockerfile.consumer -t kafka-confluent-go-consumer:latest . FROM golang:1.21.3-alpine as builder -ENV LIBRD_VER=2.3.0 - # librdkafka package for alpine yet # https://pkgs.alpinelinux.org/packages?name=librdkafka-dev&branch=edge&repo=&arch=&maintainer=John%20Anthony -RUN apk --no-cache add musl-dev librdkafka-dev ca-certificates git gcc g++ libtool libc-dev musl-dev pkgconf +RUN apk add musl-dev librdkafka-dev ca-certificates git gcc g++ libtool libc-dev pkgconf +RUN apk add build-base coreutils make musl-dev rpm wget curl cyrus-sasl-dev libevent libsasl lz4-dev openssh openssl openssl-dev yajl-dev zlib-dev +ENV LIBRD_VER=2.3.0 # Install librdkafka $LIBRD_VER # https://gist.github.com/jaihind213/e82d41dc79f52cfa64ca32350bdb27df -# RUN apk --no-cache add ca-certificates git gcc g++ libtool libc-dev musl-dev pkgconf -# RUN apk add \ -# build-base \ -# coreutils \ -# make \ -# musl-dev \ -# rpm \ -# wget \ -# curl \ -# cyrus-sasl-dev \ -# libevent \ -# libsasl \ -# lz4-dev \ -# openssh \ -# openssl \ -# openssl-dev \ -# yajl-dev \ -# zlib-dev -# RUN echo " ------> Install librdkafka..." -# RUN apk add --no-cache --virtual .make-deps bash make wget git gcc g++ && apk add --no-cache musl-dev zlib-dev openssl zstd-dev pkgconfig libc-dev && wget /~https://github.com/edenhill/librdkafka/archive/v${LIBRD_VER}.tar.gz && tar -xvf v${LIBRD_VER}.tar.gz && cd librdkafka-${LIBRD_VER} && ./configure --prefix /usr && make && make install && make clean && rm -rf librdkafka-${LIBRD_VER} && rm -rf v${LIBRD_VER}.tar.gz && apk del .make-deps -# RUN export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig/ -# ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig/ +#RUN apk --no-cache add ca-certificates git gcc g++ libtool libc-dev musl-dev pkgconf +#RUN apk add build-base coreutils make musl-dev rpm wget curl cyrus-sasl-dev libevent libsasl lz4-dev openssh openssl openssl-dev yajl-dev zlib-dev + +#RUN echo " ------> Install librdkafka..." +#RUN apk add --no-cache --virtual .make-deps bash make wget git gcc g++ +#RUN apk add --no-cache musl-dev zlib-dev openssl zstd-dev pkgconfig libc-dev +#RUN wget /~https://github.com/edenhill/librdkafka/archive/v${LIBRD_VER}.tar.gz && tar -xvf v${LIBRD_VER}.tar.gz && cd librdkafka-${LIBRD_VER} && ./configure --prefix /usr && make && make install && make clean && rm -rf librdkafka-${LIBRD_VER} && rm -rf v${LIBRD_VER}.tar.gz && apk del .make-deps + +#RUN apk add --no-cache --virtual .make-deps bash make wget git gcc g++ && apk add --no-cache musl-dev zlib-dev openssl zstd-dev pkgconfig libc-dev +#RUN wget /~https://github.com/edenhill/librdkafka/archive/v${LIBRD_VER}.tar.gz +#RUN tar -xvf v${LIBRD_VER}.tar.gz && cd librdkafka-${LIBRD_VER} && ./configure --prefix /usr && make && make install +#RUN export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig/ +#ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig/ WORKDIR /app COPY go.mod . diff --git a/README.md b/README.md index 45f8e30..6e3781d 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,13 @@ and deploy it to Kubernetes. ```bash ./scripts/install-osxcross-ubuntu.sh ``` +- [Build ARM Images on x86 Hosts] Optional + ```bash + sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-user-static binfmt-support + update-binfmts --enable qemu-arm + update-binfmts --display qemu-arm + docker buildx build --platform linux/arm64 --file Dockerfile.consumer -t kafka-confluent-go-consumer:latest . + ``` - [Confluent Kafka CLI and tools](https://confluent.cloud/environments/env-pr7kdm/clusters/lkc-v1007n/integrations/cli) ```bash diff --git a/version.txt b/version.txt index 3e08af8..b7e0698 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v0.0.49 +v0.0.50