Skip to content

Commit

Permalink
Merge pull request #131 from grepplabs/arm
Browse files Browse the repository at this point in the history
Multi-arch build: arm64 + amd64
  • Loading branch information
everesio authored Mar 30, 2023
2 parents 4689a38 + 77de4bc commit 2431b71
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/')
Expand Down
6 changes: 6 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
Expand Down
24 changes: 18 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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" \
Expand All @@ -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" \
Expand Down

0 comments on commit 2431b71

Please sign in to comment.