Skip to content

Commit

Permalink
[docker] \tendermint#9073 enable cross platform build using docker bu…
Browse files Browse the repository at this point in the history
…ildx
  • Loading branch information
highercomve committed Jul 22, 2022
1 parent 023c21f commit a4787dc
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
4 changes: 2 additions & 2 deletions DOCKER/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# stage 1 Generate Tendermint Binary
FROM golang:1.17-alpine as builder
FROM --platform=$BUILDPLATFORM golang:1.17-alpine as builder
RUN apk update && \
apk upgrade && \
apk --no-cache add make git
COPY / /tendermint
WORKDIR /tendermint
RUN make build-linux
RUN TARGETPLATFORM=$TARGETPLATFORM make build-linux

# stage 2
FROM golang:1.17-alpine
Expand Down
64 changes: 63 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,68 @@ LD_FLAGS = -X github.com/tendermint/tendermint/version.TMVersion=$(VERSION)
BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
CGO_ENABLED ?= 0

# Process Docker environment varible TARGETPLATFORM
# in order to build binary with correspondent ARCH
# by default will always build for linux/amd64
# eg: docker buildx build --platform linux/arm64,linux/amd64 -f DOCKER/Dockerfile -t tendermint/tendermint:v0.35.4 --push --progress plain .
TARGETPLATFORM ?=
GOOS ?= linux
GOARCH ?= amd64
GOARM ?=

ifeq (linux/arm,$(findstring linux/arm,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=arm
GOARM=7
endif

ifeq (linux/arm/v6,$(findstring linux/arm/v6,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=arm
GOARM=6
endif

ifeq (linux/arm64,$(findstring linux/arm64,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=arm64
GOARM=7
endif

ifeq (linux/386,$(findstring linux/386,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=386
endif

ifeq (linux/amd64,$(findstring linux/amd64,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=amd64
endif

ifeq (linux/mips,$(findstring linux/mips,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=mips
endif

ifeq (linux/mipsle,$(findstring linux/mipsle,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=mipsle
endif

ifeq (linux/mips64,$(findstring linux/mips64,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=mips64
endif

ifeq (linux/mips64le,$(findstring linux/mips64le,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=mips64le
endif

ifeq (linux/riscv64,$(findstring linux/riscv64,$(TARGETPLATFORM)))
GOOS=linux
GOARCH=riscv64
endif

# handle nostrip
ifeq (,$(findstring nostrip,$(TENDERMINT_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
Expand Down Expand Up @@ -269,7 +331,7 @@ testdata-metrics:

# Build linux binary on other platforms
build-linux:
GOOS=linux GOARCH=amd64 $(MAKE) build
GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) $(MAKE) build
.PHONY: build-linux

build-docker-localnode:
Expand Down

0 comments on commit a4787dc

Please sign in to comment.