This is an automated email from the ASF dual-hosted git repository.
zike pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git
The following commit(s) were added to refs/heads/master by this push:
new c3e94e24 [fix][build] Build test container image using current
hardware platform (#1205)
c3e94e24 is described below
commit c3e94e243a730ae22d59bf9d330c4539733b7eef
Author: Dragos Misca <[email protected]>
AuthorDate: Tue Apr 16 19:29:08 2024 -0700
[fix][build] Build test container image using current hardware platform
(#1205)
### Motivation
Test container image is built for `amd64` platforms only. This makes it
difficult to test and run on others, notably Apple Silicon chips running
`arm64`.
### Modifications
The source of the problem is using the hardcoded `amd64` Go binary
distribution during the image build. On Apple Silicon, running `make test`
yields the following error:
```
...
docker run -i pulsar-client-go-test:latest bash -c "cd
/pulsar/pulsar-client-go && ./scripts/run-ci.sh"
+ export GOPATH=/pulsar/go
+ GOPATH=/pulsar/go
+ export GOCACHE=/tmp/go-cache
+ GOCACHE=/tmp/go-cache
+ go mod download
rosetta error: failed to open elf at /lib64/ld-linux-x86-64.so.2
./scripts/run-ci.sh: line 26: 7 Trace/breakpoint trap go mod download
make: *** [test] Error 133
```
Sourcing the local platform name from `uname -m` and using it to download
the corresponding Go distribution solves the issue:
```
...
docker run -i pulsar-client-go-test:latest bash -c "cd
/pulsar/pulsar-client-go && ./scripts/run-ci.sh"
+ export GOPATH=/pulsar/go
+ GOPATH=/pulsar/go
+ export GOCACHE=/tmp/go-cache
+ GOCACHE=/tmp/go-cache
+ go mod download
+ go build ./pulsar
+ go build -o bin/pulsar-perf ./perf
+ scripts/pulsar-test-service-start.sh
...
```
---
Dockerfile | 3 ++-
Makefile | 7 +++++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/Dockerfile b/Dockerfile
index 62d22bf0..818a106a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -21,8 +21,9 @@ ARG PULSAR_IMAGE=apachepulsar/pulsar:latest
FROM $PULSAR_IMAGE
USER root
ARG GO_VERSION=1.18
+ARG ARCH=amd64
-RUN curl -L https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz -o
golang.tar.gz && \
+RUN curl -L https://dl.google.com/go/go${GO_VERSION}.linux-${ARCH}.tar.gz -o
golang.tar.gz && \
mkdir -p /pulsar/go && tar -C /pulsar -xzf golang.tar.gz
ENV PATH /pulsar/go/bin:$PATH
diff --git a/Makefile b/Makefile
index 527d53ac..62e44166 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,7 @@ IMAGE_NAME = pulsar-client-go-test:latest
PULSAR_VERSION ?= 3.2.0
PULSAR_IMAGE = apachepulsar/pulsar:$(PULSAR_VERSION)
GO_VERSION ?= 1.18
+CONTAINER_ARCH ?= $(shell uname -m | sed s/x86_64/amd64/)
# Golang standard bin directory.
GOPATH ?= $(shell go env GOPATH)
@@ -38,8 +39,10 @@ bin/golangci-lint:
GOBIN=$(shell pwd)/bin go install
github.com/golangci/golangci-lint/cmd/[email protected]
container:
- docker build -t ${IMAGE_NAME} --build-arg GO_VERSION="${GO_VERSION}" \
- --build-arg PULSAR_IMAGE="${PULSAR_IMAGE}" .
+ docker build -t ${IMAGE_NAME} \
+ --build-arg GO_VERSION="${GO_VERSION}" \
+ --build-arg PULSAR_IMAGE="${PULSAR_IMAGE}" \
+ --build-arg ARCH="${CONTAINER_ARCH}" .
test: container
docker run -i ${IMAGE_NAME} bash -c "cd /pulsar/pulsar-client-go &&
./scripts/run-ci.sh"