diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 643fd26..610fe5f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -14,14 +14,17 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + - name: Get git describe + id: get-version + run: | + describe=$(git describe --tags --always --dirty) + echo "GIT_COMMIT_REF_NAME=$describe" >> $GITHUB_ENV - name: Setup go uses: actions/setup-go@v4 with: go-version: '1.20' check-latest: true - run: go version - - name: Run build and test - run: make clean build test - name: Docker meta id: meta uses: docker/metadata-action@v4 @@ -64,19 +67,19 @@ jobs: with: context: . push: true - build-args: | - MAKE_TARGET=test build + platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: VERSION=${{ env.GIT_COMMIT_REF_NAME }} - name: Docker build and push - all uses: docker/build-push-action@v4 with: context: . push: true - build-args: | - MAKE_TARGET=all + platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta-all.outputs.tags }} labels: ${{ steps.meta-all.outputs.labels }} + build-args: VERSION=${{ env.GIT_COMMIT_REF_NAME }} - name: Run GoReleaser uses: goreleaser/goreleaser-action@v4 if: startsWith(github.ref, 'refs/tags/') diff --git a/.goreleaser.yml b/.goreleaser.yml index 6575e47..7ad1696 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,11 +1,17 @@ builds: - binary: kafka-proxy + env: + - CGO_ENABLED=0 goos: - windows - darwin - linux goarch: - amd64 + - arm64 + ignore: + - goos: windows + goarch: arm64 ldflags: -s -w -X github.com/grepplabs/kafka-proxy/config.Version={{.Version}} archives: - name_template: "{{ .ProjectName }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}" diff --git a/Dockerfile b/Dockerfile index b234ada..2a943d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,27 @@ -FROM golang:1.20-alpine3.17 as builder +FROM --platform=$BUILDPLATFORM golang:1.20-alpine3.17 as builder RUN apk add alpine-sdk ca-certificates +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT +ARG VERSION + +ENV CGO_ENABLED=0 \ + GO111MODULE=on \ + GOOS=${TARGETOS} \ + GOARCH=${TARGETARCH} \ + GOARM=${TARGETVARIANT} \ + LDFLAGS="-X github.com/grepplabs/kafka-proxy/config.Version=${VERSION} -w -s" + WORKDIR /go/src/github.com/grepplabs/kafka-proxy COPY . . -ARG MAKE_TARGET=build -ARG GOOS=linux -ARG GOARCH=amd64 -RUN make -e GOARCH=${GOARCH} -e GOOS=${GOOS} clean ${MAKE_TARGET} +RUN mkdir -p build && \ + export GOARM=$( echo "${GOARM}" | cut -c2-) && \ + go build -mod=vendor -o build/kafka-proxy \ + -ldflags "${LDFLAGS}" . -FROM alpine:3.17 +FROM --platform=$BUILDPLATFORM alpine:3.17 RUN apk add --no-cache ca-certificates RUN adduser \ --disabled-password \ diff --git a/Makefile b/Makefile index 9423d9a..b8fb144 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,11 @@ VERSION ?= $(shell git describe --tags --always --dirty) GOPKGS = $(shell go list ./... | grep -v /vendor/) BUILD_FLAGS ?= LDFLAGS ?= -X github.com/grepplabs/kafka-proxy/config.Version=$(VERSION) -w -s -TAG ?= "v0.3.5" -GOARCH ?= amd64 -GOOS ?= linux - +TAG ?= "v0.3.6" +GOOS ?= $(if $(TARGETOS),$(TARGETOS),linux) +GOARCH ?= $(if $(TARGETARCH),$(TARGETARCH),amd64) +GOARM ?= $(TARGETVARIANT) +BUILDPLATFORM ?= $(GOOS)/$(GOARCH) PROTOC_GO_VERSION ?= v1.30 PROTOC_GRPC_VERSION ?= v1.2 @@ -41,15 +42,16 @@ build: build/$(BINARY) .PHONY: build/$(BINARY) build/$(BINARY): $(SOURCES) - GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -mod=vendor -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" . + GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) CGO_ENABLED=0 go build -mod=vendor -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" . + +docker.build: + docker buildx build --build-arg BUILDPLATFORM=$(BUILDPLATFORM) --build-arg TARGETARCH=$(GOARCH) -t local/kafka-proxy . tag: git tag $(TAG) release: clean git push origin $(TAG) - rm -rf $(ROOT_DIR)/dist - curl -sL https://git.io/goreleaser | bash protoc.plugin.install: go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GO_VERSION) diff --git a/README.md b/README.md index be7b42c..5f2fb49 100644 --- a/README.md +++ b/README.md @@ -47,11 +47,11 @@ As not every Kafka release adds new messages/versions which are relevant to the Linux - curl -Ls https://github.com/grepplabs/kafka-proxy/releases/download/v0.3.5/kafka-proxy-v0.3.5-linux-amd64.tar.gz | tar xz + curl -Ls https://github.com/grepplabs/kafka-proxy/releases/download/v0.3.6/kafka-proxy-v0.3.6-linux-amd64.tar.gz | tar xz macOS - curl -Ls https://github.com/grepplabs/kafka-proxy/releases/download/v0.3.5/kafka-proxy-v0.3.5-darwin-amd64.tar.gz | tar xz + curl -Ls https://github.com/grepplabs/kafka-proxy/releases/download/v0.3.6/kafka-proxy-v0.3.6-darwin-amd64.tar.gz | tar xz 2. Move the binary in to your PATH. @@ -69,7 +69,7 @@ Docker images are available on [Docker Hub](https://hub.docker.com/r/grepplabs/k You can launch a kafka-proxy container for trying it out with - docker run --rm -p 30001-30003:30001-30003 grepplabs/kafka-proxy:v0.3.5 \ + docker run --rm -p 30001-30003:30001-30003 grepplabs/kafka-proxy:v0.3.6 \ server \ --bootstrap-server-mapping "localhost:19092,0.0.0.0:30001" \ --bootstrap-server-mapping "localhost:29092,0.0.0.0:30002" \ @@ -88,7 +88,7 @@ Docker images with precompiled plugins located in `/opt/kafka-proxy/bin/` are ta You can launch a kafka-proxy container with auth-ldap plugin for trying it out with - docker run --rm -p 30001-30003:30001-30003 grepplabs/kafka-proxy:v0.3.5-all \ + docker run --rm -p 30001-30003:30001-30003 grepplabs/kafka-proxy:v0.3.6-all \ server \ --bootstrap-server-mapping "localhost:19092,0.0.0.0:30001" \ --bootstrap-server-mapping "localhost:29092,0.0.0.0:30002" \