This is an automated email from the ASF dual-hosted git repository.
caigy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-operator.git
The following commit(s) were added to refs/heads/master by this push:
new fe156ff [ISSUE #154] Support deployment on multi platform. (#155)
fe156ff is described below
commit fe156ff60192e813a461e7be2e1eb3a762291dc7
Author: Jin Shang <[email protected]>
AuthorDate: Fri Aug 11 09:57:49 2023 +0800
[ISSUE #154] Support deployment on multi platform. (#155)
* fix #154: Support deployment on multi platform.
Support to build product on multi platform by using docker buildx, like arm.
* fix #154: Support deployment on multi platform.
Support to build product on multi platform by using docker buildx, like arm.
---------
Co-authored-by: jim.sj <[email protected]>
---
Dockerfile | 7 ++++---
Makefile | 12 ++++++++++--
images/broker/alpine/Dockerfile | 2 +-
images/broker/alpine/build-broker-image.sh | 5 +++--
images/controller/alpine/Dockerfile | 2 +-
images/controller/alpine/build-controller-image.sh | 3 ++-
images/namesrv/alpine/Dockerfile | 2 +-
images/namesrv/alpine/build-namesrv-image.sh | 3 ++-
8 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/Dockerfile b/Dockerfile
index d1500cd..e99b665 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,5 @@
# Build the manager binary
-FROM golang:1.16 as builder
+FROM --platform=$BUILDPLATFORM golang:1.16 as builder
WORKDIR /workspace
# Copy the Go Modules manifests
@@ -14,12 +14,13 @@ COPY main.go main.go
COPY pkg/ pkg/
# Build
-RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
+ARG TARGETOS TARGETARCH
+RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -o manager
main.go
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
#FROM gcr.io/distroless/static:nonroot
-FROM openjdk:8-alpine
+FROM --platform=$TARGETPLATFORM openjdk:8-alpine
# Install rocketmq release into image
RUN apk add --no-cache bash gettext nmap-ncat openssl busybox-extras
diff --git a/Makefile b/Makefile
index c727305..1b7bd3a 100644
--- a/Makefile
+++ b/Makefile
@@ -108,14 +108,22 @@ build: generate fmt vet ## Build manager binary.
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go
+.PHONY: docker-buildx
+docker-buildx: ## Create a new docker builder to support --platform
+ docker buildx create --name multiarch --driver docker-container --use
+
.PHONY: docker-build
-docker-build: test ## Build docker image with the manager.
- docker build -t ${IMG} .
+docker-build: test docker-buildx ## Build docker image with the manager.
+ docker buildx build --platform linux/amd64 --load -t ${IMG} .
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
+.PHONY: docker-image-release
+docker-build: test docker-buildx ## Build docker image with the manager.
+ docker buildx build --platform linux/amd64,linux/arm64 --push -t ${IMG}
.
+
##@ Deployment
ifndef ignore-not-found
diff --git a/images/broker/alpine/Dockerfile b/images/broker/alpine/Dockerfile
index 64c786b..33179e6 100644
--- a/images/broker/alpine/Dockerfile
+++ b/images/broker/alpine/Dockerfile
@@ -15,7 +15,7 @@
# limitations under the License.
#
-FROM openjdk:8-alpine
+FROM --platform=$TARGETPLATFORM openjdk:8-alpine
RUN apk add --no-cache bash gettext nmap-ncat openssl busybox-extras
diff --git a/images/broker/alpine/build-broker-image.sh
b/images/broker/alpine/build-broker-image.sh
index 7a20063..454b353 100755
--- a/images/broker/alpine/build-broker-image.sh
+++ b/images/broker/alpine/build-broker-image.sh
@@ -38,6 +38,7 @@
IMAGE_NAME=${DOCKERHUB_REPO}:${ROCKETMQ_VERSION}-alpine-operator-0.4.0
checkVersion $ROCKETMQ_VERSION
-docker build -t $IMAGE_NAME --build-arg version=${ROCKETMQ_VERSION} .
+docker buildx build --platform linux/amd64 --load -t ${IMAGE_NAME} --build-arg
version=${ROCKETMQ_VERSION} .
+#docker buildx build --platform linux/amd64,linux/arm64 --push -t
${IMAGE_NAME} --build-arg version=${ROCKETMQ_VERSION} .
-#docker push $IMAGE_NAME
+#docker push $IMAGE_NAME
\ No newline at end of file
diff --git a/images/controller/alpine/Dockerfile
b/images/controller/alpine/Dockerfile
index dadae8d..c5ad273 100644
--- a/images/controller/alpine/Dockerfile
+++ b/images/controller/alpine/Dockerfile
@@ -15,7 +15,7 @@
# limitations under the License.
#
-FROM openjdk:8-alpine
+FROM --platform=$TARGETPLATFORM openjdk:8-alpine
RUN apk add --no-cache bash gettext nmap-ncat openssl busybox-extras
diff --git a/images/controller/alpine/build-controller-image.sh
b/images/controller/alpine/build-controller-image.sh
index e843e2f..afec583 100755
--- a/images/controller/alpine/build-controller-image.sh
+++ b/images/controller/alpine/build-controller-image.sh
@@ -38,6 +38,7 @@
IMAGE_NAME=${DOCKERHUB_REPO}:${ROCKETMQ_VERSION}-alpine-operator-0.4.0
checkVersion $ROCKETMQ_VERSION
-docker build -t $IMAGE_NAME --build-arg version=${ROCKETMQ_VERSION} .
+docker buildx build --platform linux/amd64 --load -t ${IMAGE_NAME} --build-arg
version=${ROCKETMQ_VERSION} .
+#docker buildx build --platform linux/amd64,linux/arm64 --push -t
${IMAGE_NAME} --build-arg version=${ROCKETMQ_VERSION} .
#docker push $IMAGE_NAME
\ No newline at end of file
diff --git a/images/namesrv/alpine/Dockerfile b/images/namesrv/alpine/Dockerfile
index 64538bf..fc9974e 100644
--- a/images/namesrv/alpine/Dockerfile
+++ b/images/namesrv/alpine/Dockerfile
@@ -15,7 +15,7 @@
# limitations under the License.
#
-FROM openjdk:8-alpine
+FROM --platform=$TARGETPLATFORM openjdk:8-alpine
RUN apk add --no-cache bash gettext nmap-ncat openssl busybox-extras
diff --git a/images/namesrv/alpine/build-namesrv-image.sh
b/images/namesrv/alpine/build-namesrv-image.sh
index 9cc58cf..031a599 100755
--- a/images/namesrv/alpine/build-namesrv-image.sh
+++ b/images/namesrv/alpine/build-namesrv-image.sh
@@ -38,6 +38,7 @@
IMAGE_NAME=${DOCKERHUB_REPO}:${ROCKETMQ_VERSION}-alpine-operator-0.4.0
checkVersion $ROCKETMQ_VERSION
-docker build -t $IMAGE_NAME --build-arg version=${ROCKETMQ_VERSION} .
+docker buildx build --platform linux/amd64 --load -t ${IMAGE_NAME} --build-arg
version=${ROCKETMQ_VERSION} .
+#docker buildx build --platform linux/amd64,linux/arm64 --push -t
${IMAGE_NAME} --build-arg version=${ROCKETMQ_VERSION} .
#docker push $IMAGE_NAME
\ No newline at end of file