From e1ead04143e7376325e5c288804a61c2a494f5fd Mon Sep 17 00:00:00 2001 From: odidev Date: Mon, 13 Jun 2022 08:54:43 -0400 Subject: [PATCH] Add docker buildx build to the Makefile to build and push multi-arch docker images Signed-off-by: odidev --- Makefile | 59 ++++++++++++++++++++++++++------ docker/Dockerfile.alluxioruntime | 11 +++--- docker/Dockerfile.application | 11 +++--- docker/Dockerfile.dataset | 11 +++--- docker/Dockerfile.goosefsruntime | 11 +++--- docker/Dockerfile.jindoruntime | 11 +++--- docker/Dockerfile.juicefsruntime | 11 +++--- docker/Dockerfile.webhook | 3 +- docs/en/dev/how_to_develop.md | 4 +++ docs/zh/dev/how_to_develop.md | 2 +- 10 files changed, 92 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index f381e297cc1..db9777d1c02 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ INIT_USERS_IMG ?= ${IMG_REPO}/init-users WEBHOOK_IMG ?= ${IMG_REPO}/fluid-webhook GO_MODULE ?= off GC_FLAGS ?= -gcflags="all=-N -l" +ARCH ?= amd64 LOCAL_FLAGS ?= -gcflags=-l # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) @@ -26,10 +27,10 @@ GOBIN=$(shell go env GOBIN) endif UNAME := $(shell uname -m) -ifeq ($(UNAME), x86_64) - ARCH := amd64 -else +ifeq ($(UNAME), aarch64) ARCH := arm64 +else + ARCH := amd64 endif CURRENT_DIR=$(shell pwd) @@ -73,6 +74,17 @@ DOCKER_PUSH += docker-push-goosefsruntime-controller DOCKER_PUSH += docker-push-juicefsruntime-controller DOCKER_PUSH += docker-push-init-users +# Buildx and push docker images +DOCKER_BUILDX_PUSH := docker-buildx-push-dataset-controller +DOCKER_BUILDX_PUSH += docker-buildx-push-application-controller +DOCKER_BUILDX_PUSH += docker-buildx-push-alluxioruntime-controller +DOCKER_BUILDX_PUSH += docker-buildx-push-jindoruntime-controller +DOCKER_BUILDX_PUSH += docker-buildx-push-goosefsruntime-controller +DOCKER_BUILDX_PUSH += docker-buildx-push-csi +DOCKER_BUILDX_PUSH += docker-buildx-push-webhook +DOCKER_BUILDX_PUSH += docker-buildx-push-juicefsruntime-controller +DOCKER_BUILDX_PUSH += docker-buildx-push-init-users + override LDFLAGS += \ -X ${PACKAGE}.version=${VERSION} \ -X ${PACKAGE}.buildDate=${BUILD_DATE} \ @@ -165,22 +177,22 @@ update-api-doc: # Build the docker image docker-build-dataset-controller: generate gen-openapi fmt vet - docker build --no-cache . -f docker/Dockerfile.dataset -t ${DATASET_CONTROLLER_IMG}:${GIT_VERSION} + docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.dataset -t ${DATASET_CONTROLLER_IMG}:${GIT_VERSION} docker-build-application-controller: generate fmt vet - docker build --no-cache . -f docker/Dockerfile.application -t ${APPLICATION_CONTROLLER_IMG}:${GIT_VERSION} + docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.application -t ${APPLICATION_CONTROLLER_IMG}:${GIT_VERSION} docker-build-alluxioruntime-controller: generate gen-openapi fmt vet - docker build --no-cache . -f docker/Dockerfile.alluxioruntime -t ${ALLUXIORUNTIME_CONTROLLER_IMG}:${GIT_VERSION} + docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.alluxioruntime -t ${ALLUXIORUNTIME_CONTROLLER_IMG}:${GIT_VERSION} docker-build-jindoruntime-controller: generate gen-openapi fmt vet - docker build --no-cache . -f docker/Dockerfile.jindoruntime -t ${JINDORUNTIME_CONTROLLER_IMG}:${GIT_VERSION} + docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.jindoruntime -t ${JINDORUNTIME_CONTROLLER_IMG}:${GIT_VERSION} docker-build-goosefsruntime-controller: generate gen-openapi fmt vet - docker build --no-cache . -f docker/Dockerfile.goosefsruntime -t ${GOOSEFSRUNTIME_CONTROLLER_IMG}:${GIT_VERSION} + docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.goosefsruntime -t ${GOOSEFSRUNTIME_CONTROLLER_IMG}:${GIT_VERSION} docker-build-juicefsruntime-controller: generate gen-openapi fmt vet juicefsruntime-controller-build - docker build --no-cache . -f docker/Dockerfile.juicefsruntime -t ${JUICEFSRUNTIME_CONTROLLER_IMG}:${GIT_VERSION} + docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.juicefsruntime -t ${JUICEFSRUNTIME_CONTROLLER_IMG}:${GIT_VERSION} docker-build-csi: generate fmt vet docker build --no-cache . -f docker/Dockerfile.csi -t ${CSI_IMG}:${GIT_VERSION} @@ -192,7 +204,7 @@ docker-build-init-users: docker build --no-cache charts/alluxio/docker/init-users -t ${INIT_USERS_IMG}:${GIT_VERSION} docker-build-webhook: - docker build --no-cache . -f docker/Dockerfile.webhook -t ${WEBHOOK_IMG}:${GIT_VERSION} + docker build --no-cache --build-arg TARGETARCH=${ARCH} . -f docker/Dockerfile.webhook -t ${WEBHOOK_IMG}:${GIT_VERSION} # Push the docker image docker-push-dataset-controller: docker-build-dataset-controller @@ -225,10 +237,37 @@ docker-push-init-users: docker-build-init-users docker-push-webhook: docker-build-webhook docker push ${WEBHOOK_IMG}:${GIT_VERSION} +# Buildx and push the docker image +docker-buildx-push-dataset-controller: generate gen-openapi fmt vet + docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.dataset -t ${DATASET_CONTROLLER_IMG}:${GIT_VERSION} + +docker-buildx-push-application-controller: generate fmt vet + docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.application -t ${APPLICATION_CONTROLLER_IMG}:${GIT_VERSION} + +docker-buildx-push-alluxioruntime-controller: generate gen-openapi fmt vet + docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.alluxioruntime -t ${ALLUXIORUNTIME_CONTROLLER_IMG}:${GIT_VERSION} + +docker-buildx-push-jindoruntime-controller: generate gen-openapi fmt vet + docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.jindoruntime -t ${JINDORUNTIME_CONTROLLER_IMG}:${GIT_VERSION} + +docker-buildx-push-goosefsruntime-controller: generate gen-openapi fmt vet + docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.goosefsruntime -t ${GOOSEFSRUNTIME_CONTROLLER_IMG}:${GIT_VERSION} + +docker-buildx-push-juicefsruntime-controller: generate gen-openapi fmt vet juicefsruntime-controller-build + docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.juicefsruntime -t ${JUICEFSRUNTIME_CONTROLLER_IMG}:${GIT_VERSION} + +docker-buildx-push-csi: generate fmt vet + docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.csi -t ${CSI_IMG}:${GIT_VERSION} + +docker-buildx-push-init-users: + docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache charts/alluxio/docker/init-users -t ${INIT_USERS_IMG}:${GIT_VERSION} +docker-buildx-push-webhook: + docker buildx build --push --platform linux/amd64,linux/arm64 --no-cache . -f docker/Dockerfile.webhook -t ${WEBHOOK_IMG}:${GIT_VERSION} docker-build-all: ${DOCKER_BUILD} docker-push-all: ${DOCKER_PUSH} +docker-buildx-all-push: ${DOCKER_BUILDX_PUSH} gen-sdk: ./hack/sdk/gen-sdk.sh diff --git a/docker/Dockerfile.alluxioruntime b/docker/Dockerfile.alluxioruntime index 74caa41d2e4..f0c6bdbb732 100644 --- a/docker/Dockerfile.alluxioruntime +++ b/docker/Dockerfile.alluxioruntime @@ -13,14 +13,15 @@ RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone -RUN curl -o helm-v3.0.3-linux-amd64.tar.gz http://aliacs-k8s-cn-hongkong.oss-cn-hongkong.aliyuncs.com/public/pkg/helm/helm-v3.0.3-linux-amd64.tar.gz && \ - tar -xvf helm-v3.0.3-linux-amd64.tar.gz && \ - mv linux-amd64/helm /usr/local/bin/ddc-helm && \ +ARG TARGETARCH +RUN curl -o helm-v3.0.3-linux-${TARGETARCH}.tar.gz https://get.helm.sh/helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + tar -xvf helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + mv linux-${TARGETARCH}/helm /usr/local/bin/ddc-helm && \ chmod u+x /usr/local/bin/ddc-helm && \ - rm -f helm-v3.0.3-linux-amd64.tar.gz + rm -f helm-v3.0.3-linux-${TARGETARCH}.tar.gz ENV K8S_VERSION v1.14.8 -RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl && chmod +x /usr/local/bin/kubectl +RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/${TARGETARCH}/kubectl && chmod +x /usr/local/bin/kubectl ADD charts/ /charts diff --git a/docker/Dockerfile.application b/docker/Dockerfile.application index cc22cdc7e62..4cc44ed6971 100644 --- a/docker/Dockerfile.application +++ b/docker/Dockerfile.application @@ -16,14 +16,15 @@ RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone -RUN curl -o helm-v3.0.3-linux-amd64.tar.gz http://aliacs-k8s-cn-hongkong.oss-cn-hongkong.aliyuncs.com/public/pkg/helm/helm-v3.0.3-linux-amd64.tar.gz && \ - tar -xvf helm-v3.0.3-linux-amd64.tar.gz && \ - mv linux-amd64/helm /usr/local/bin/ddc-helm && \ +ARG TARGETARCH +RUN curl -o helm-v3.0.3-linux-${TARGETARCH}.tar.gz https://get.helm.sh/helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + tar -xvf helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + mv linux-${TARGETARCH}/helm /usr/local/bin/ddc-helm && \ chmod u+x /usr/local/bin/ddc-helm && \ - rm -f helm-v3.0.3-linux-amd64.tar.gz + rm -f helm-v3.0.3-linux-${TARGETARCH}.tar.gz ENV K8S_VERSION v1.14.8 -RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl && chmod +x /usr/local/bin/kubectl +RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/${TARGETARCH}/kubectl && chmod +x /usr/local/bin/kubectl ADD charts/ /charts diff --git a/docker/Dockerfile.dataset b/docker/Dockerfile.dataset index 373bce7275a..77d5b5783d8 100644 --- a/docker/Dockerfile.dataset +++ b/docker/Dockerfile.dataset @@ -16,14 +16,15 @@ RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone -RUN curl -o helm-v3.0.3-linux-amd64.tar.gz http://aliacs-k8s-cn-hongkong.oss-cn-hongkong.aliyuncs.com/public/pkg/helm/helm-v3.0.3-linux-amd64.tar.gz && \ - tar -xvf helm-v3.0.3-linux-amd64.tar.gz && \ - mv linux-amd64/helm /usr/local/bin/ddc-helm && \ +ARG TARGETARCH +RUN curl -o helm-v3.0.3-linux-${TARGETARCH}.tar.gz https://get.helm.sh/helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + tar -xvf helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + mv linux-${TARGETARCH}/helm /usr/local/bin/ddc-helm && \ chmod u+x /usr/local/bin/ddc-helm && \ - rm -f helm-v3.0.3-linux-amd64.tar.gz + rm -f helm-v3.0.3-linux-${TARGETARCH}.tar.gz ENV K8S_VERSION v1.14.8 -RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl && chmod +x /usr/local/bin/kubectl +RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/${TARGETARCH}/kubectl && chmod +x /usr/local/bin/kubectl ADD charts/ /charts diff --git a/docker/Dockerfile.goosefsruntime b/docker/Dockerfile.goosefsruntime index a1a613ab950..13c751ca671 100644 --- a/docker/Dockerfile.goosefsruntime +++ b/docker/Dockerfile.goosefsruntime @@ -16,14 +16,15 @@ RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone -RUN curl -o helm-v3.0.3-linux-amd64.tar.gz http://aliacs-k8s-cn-hongkong.oss-cn-hongkong.aliyuncs.com/public/pkg/helm/helm-v3.0.3-linux-amd64.tar.gz && \ - tar -xvf helm-v3.0.3-linux-amd64.tar.gz && \ - mv linux-amd64/helm /usr/local/bin/ddc-helm && \ +ARG TARGETARCH +RUN curl -o helm-v3.0.3-linux-${TARGETARCH}.tar.gz https://get.helm.sh/helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + tar -xvf helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + mv linux-${TARGETARCH}/helm /usr/local/bin/ddc-helm && \ chmod u+x /usr/local/bin/ddc-helm && \ - rm -f helm-v3.0.3-linux-amd64.tar.gz + rm -f helm-v3.0.3-linux-${TARGETARCH}.tar.gz ENV K8S_VERSION v1.14.8 -RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl && chmod +x /usr/local/bin/kubectl +RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/${TARGETARCH}/kubectl && chmod +x /usr/local/bin/kubectl ADD charts/ /charts diff --git a/docker/Dockerfile.jindoruntime b/docker/Dockerfile.jindoruntime index 499bf0e0edc..0e4bf1bdf3e 100644 --- a/docker/Dockerfile.jindoruntime +++ b/docker/Dockerfile.jindoruntime @@ -16,14 +16,15 @@ RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone -RUN curl -o helm-v3.0.3-linux-amd64.tar.gz http://aliacs-k8s-cn-hongkong.oss-cn-hongkong.aliyuncs.com/public/pkg/helm/helm-v3.0.3-linux-amd64.tar.gz && \ - tar -xvf helm-v3.0.3-linux-amd64.tar.gz && \ - mv linux-amd64/helm /usr/local/bin/ddc-helm && \ +ARG TARGETARCH +RUN curl -o helm-v3.0.3-linux-${TARGETARCH}.tar.gz https://get.helm.sh/helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + tar -xvf helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + mv linux-${TARGETARCH}/helm /usr/local/bin/ddc-helm && \ chmod u+x /usr/local/bin/ddc-helm && \ - rm -f helm-v3.0.3-linux-amd64.tar.gz + rm -f helm-v3.0.3-linux-${TARGETARCH}.tar.gz ENV K8S_VERSION v1.14.8 -RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl && chmod +x /usr/local/bin/kubectl +RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/${TARGETARCH}/kubectl && chmod +x /usr/local/bin/kubectl ADD charts/jindofs /charts/jindofs ADD charts/jindofsx /charts/jindofsx diff --git a/docker/Dockerfile.juicefsruntime b/docker/Dockerfile.juicefsruntime index 813e59f781c..eb2a61977b3 100644 --- a/docker/Dockerfile.juicefsruntime +++ b/docker/Dockerfile.juicefsruntime @@ -16,14 +16,15 @@ RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone -RUN curl -o helm-v3.0.3-linux-amd64.tar.gz http://aliacs-k8s-cn-hongkong.oss-cn-hongkong.aliyuncs.com/public/pkg/helm/helm-v3.0.3-linux-amd64.tar.gz && \ - tar -xvf helm-v3.0.3-linux-amd64.tar.gz && \ - mv linux-amd64/helm /usr/local/bin/ddc-helm && \ +ARG TARGETARCH +RUN curl -o helm-v3.0.3-linux-${TARGETARCH}.tar.gz https://get.helm.sh/helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + tar -xvf helm-v3.0.3-linux-${TARGETARCH}.tar.gz && \ + mv linux-${TARGETARCH}/helm /usr/local/bin/ddc-helm && \ chmod u+x /usr/local/bin/ddc-helm && \ - rm -f helm-v3.0.3-linux-amd64.tar.gz + rm -f helm-v3.0.3-linux-${TARGETARCH}.tar.gz ENV K8S_VERSION v1.14.8 -RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl && chmod +x /usr/local/bin/kubectl +RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/${TARGETARCH}/kubectl && chmod +x /usr/local/bin/kubectl ADD charts/ /charts diff --git a/docker/Dockerfile.webhook b/docker/Dockerfile.webhook index 8d729bb024d..f688cecebc4 100644 --- a/docker/Dockerfile.webhook +++ b/docker/Dockerfile.webhook @@ -16,8 +16,9 @@ RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone +ARG TARGETARCH ENV K8S_VERSION v1.14.8 -RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl && chmod +x /usr/local/bin/kubectl +RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/${TARGETARCH}/kubectl && chmod +x /usr/local/bin/kubectl COPY --from=builder /go/bin/fluid-webhook /usr/local/bin/fluid-webhook COPY --from=builder /go/bin/dlv /usr/local/bin/dlv diff --git a/docs/en/dev/how_to_develop.md b/docs/en/dev/how_to_develop.md index 4156eb04164..4286b374def 100644 --- a/docs/en/dev/how_to_develop.md +++ b/docs/en/dev/how_to_develop.md @@ -54,6 +54,10 @@ By default, the binary would be put under `/bin`. # build all images $ make docker-build-all + + # build and push all images using docker buildx (Run QEMU emulation before docker buildx, as below) + $ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + $ make docker-buildx-all-push ``` Before running Fluid, you need to push the built image to an accessible image registry. diff --git a/docs/zh/dev/how_to_develop.md b/docs/zh/dev/how_to_develop.md index cb0d14e0fed..b15e610c372 100644 --- a/docs/zh/dev/how_to_develop.md +++ b/docs/zh/dev/how_to_develop.md @@ -291,4 +291,4 @@ $ dlv debug --headless --listen ":12345" --log --api-version=2 cmd/alluxio/main. $ dlv connect ":12345" --api-version=2 ``` -> 注意:要进行远程调试,请确保远程主机指定的端口未被占用并且已经对远程主机的防火墙进行了适当的配置 \ No newline at end of file +> 注意:要进行远程调试,请确保远程主机指定的端口未被占用并且已经对远程主机的防火墙进行了适当的配置