From 0e2791b847f198ed2088de522bd33ad88ec0eeed Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Tue, 14 Dec 2021 12:32:03 +0800 Subject: [PATCH] Add arm64 Docker images --- build/build_java_test_image.sh | 2 +- build/docker/Dockerfile | 9 +- build/docker/README.md | 23 ++- build/docker/publish.sh | 57 -------- docker/build.sh | 2 +- docker/{publish.sh => build_and_publish.sh} | 29 ++-- docker/pulsar-all/pom.xml | 98 +++++++------ docker/pulsar/Dockerfile | 7 +- docker/pulsar/pom.xml | 131 +++++++++++------- pulsar-client-cpp/docker/.dockerignore | 19 +++ .../docker/Dockerfile.build.wheels | 10 +- ...sh-images.sh => create-and-push-images.sh} | 32 ++--- .../latest-version-image/pom.xml | 6 - 13 files changed, 221 insertions(+), 204 deletions(-) delete mode 100755 build/docker/publish.sh rename docker/{publish.sh => build_and_publish.sh} (69%) create mode 100644 pulsar-client-cpp/docker/.dockerignore rename docker/get-version.sh => pulsar-client-cpp/docker/Dockerfile.build.wheels (81%) mode change 100755 => 100644 rename pulsar-client-cpp/docker/{push-images.sh => create-and-push-images.sh} (62%) diff --git a/build/build_java_test_image.sh b/build/build_java_test_image.sh index 3fa3be9e0082d..fc81a2beb8e51 100755 --- a/build/build_java_test_image.sh +++ b/build/build_java_test_image.sh @@ -28,4 +28,4 @@ if [[ "$(docker version -f '{{.Server.Experimental}}' 2>/dev/null)" == "true" ]] fi mvn -am -pl tests/docker-images/java-test-image -Pcore-modules,-main,integrationTests,docker \ -Dmaven.test.skip=true -DskipSourceReleaseAssembly=true -Dspotbugs.skip=true -Dlicense.skip=true $SQUASH_PARAM \ - "$@" install \ No newline at end of file + "$@" install diff --git a/build/docker/Dockerfile b/build/docker/Dockerfile index 4b6b8a3a84765..da4b04e9f0f3e 100644 --- a/build/docker/Dockerfile +++ b/build/docker/Dockerfile @@ -51,8 +51,13 @@ RUN cd /usr/src/gmock && cmake . && make && cp libgmock.a /usr/lib # Include gtest parallel to speed up unit tests RUN git clone https://github.com/google/gtest-parallel.git -ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 -ENV JAVA_HOME_11=/usr/lib/jvm/java-1.11.0-openjdk-amd64 +RUN java_home=$(ls -d1 /usr/lib/jvm/java-1.8.0-openjdk-*) ; \ + ln -s "$java_home" /usr/lib/jvm/java8 ; \ + java_home_11=$(ls -d1 /usr/lib/jvm/java-1.11.0-openjdk-*) ; \ + ln -s "$java_home_11" /usr/lib/jvm/java11 + +ENV JAVA_HOME /usr/lib/jvm/java8 +ENV JAVA_HOME_11 /usr/lib/jvm/java11 ## Website build dependencies diff --git a/build/docker/README.md b/build/docker/README.md index bc2fe532f74e0..cfb21dd687f33 100644 --- a/build/docker/README.md +++ b/build/docker/README.md @@ -36,13 +36,32 @@ Example: `apachepulsar/pulsar-build:ubuntu-16.04` ### Build pulsar-build image +We provide Docker images for multiple architectures including amd64 and arm64, by leveraging Docker build kit, please +make sure to start a BuildKit daemon with command `docker buildx create --use --driver docker-container`. + +If you want to build Docker image only for local testing in your current machine (without pushing to a registry), you +can build the image without BuildKit, like this: ```shell docker build -t apachepulsar/pulsar-build:ubuntu-16.04 . ``` -### Publish pulsar-build image +It's an unusual case when you want to build multi-arch images locally without pushing to a registry, but in case you +want to do this, run command: ```shell -publish.sh +docker buildx build --no-cache --platform=linux/amd64,linux/arm64 --load -t apachepulsar/pulsar-build:ubuntu-16.04 . ``` + +This command builds multi-arch images in your local machine, but be careful when you +run `docker push apachepulsar/pulsar-build:ubuntu-16.04`, **only one** image matching your system architecture will be +pushed. + +If you want to push all images with different architectures to remote Docker registry, you can build and push with +command: + +```shell +docker buildx build --no-cache --platform=linux/amd64,linux/arm64 --push -t apachepulsar/pulsar-build:ubuntu-16.04 . +``` + +> Make sure to log into the registry with command `docker login ` before running the command above. diff --git a/build/docker/publish.sh b/build/docker/publish.sh deleted file mode 100755 index 6bfa56bace6d8..0000000000000 --- a/build/docker/publish.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -ROOT_DIR=$(git rev-parse --show-toplevel) -cd $ROOT_DIR/build/docker - -if [ -z "$DOCKER_USER" ]; then - echo "Docker user in variable \$DOCKER_USER was not set. Skipping image publishing" - exit 1 -fi - -if [ -z "$DOCKER_PASSWORD" ]; then - echo "Docker password in variable \$DOCKER_PASSWORD was not set. Skipping image publishing" - exit 1 -fi - -DOCKER_ORG="${DOCKER_ORG:-apachepulsar}" - -docker login ${DOCKER_REGISTRY} -u="$DOCKER_USER" -p="$DOCKER_PASSWORD" -if [ $? -ne 0 ]; then - echo "Failed to loging to Docker Hub" - exit 1 -fi - -if [[ -z ${DOCKER_REGISTRY} ]]; then - docker_registry_org=${DOCKER_ORG} -else - docker_registry_org=${DOCKER_REGISTRY}/${DOCKER_ORG} - echo "Starting to push images to ${docker_registry_org}..." -fi - -set -x - -# Fail if any of the subsequent commands fail -set -e - -# Push all images and tags -docker push ${docker_registry_org}/pulsar-build:ubuntu-16.04 - -echo "Finished pushing images to ${docker_registry_org}" diff --git a/docker/build.sh b/docker/build.sh index d8ab4bea882c4..05756706f05e0 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -21,4 +21,4 @@ ROOT_DIR=$(git rev-parse --show-toplevel) cd $ROOT_DIR/docker -mvn package -Pdocker,-main +mvn package -Ddocker.push.skip -Pdocker,-main diff --git a/docker/publish.sh b/docker/build_and_publish.sh similarity index 69% rename from docker/publish.sh rename to docker/build_and_publish.sh index af0d72d4b3437..d940052638c1c 100755 --- a/docker/publish.sh +++ b/docker/build_and_publish.sh @@ -47,9 +47,6 @@ if [ $? -ne 0 ]; then exit 1 fi -MVN_VERSION=`./get-version.sh` -echo "Pulsar version: ${MVN_VERSION}" - if [[ -z ${DOCKER_REGISTRY} ]]; then docker_registry_org=${DOCKER_ORG} else @@ -62,16 +59,22 @@ set -x # Fail if any of the subsequent commands fail set -e -docker tag pulsar:latest ${docker_registry_org}/pulsar:latest -docker tag pulsar-all:latest ${docker_registry_org}/pulsar-all:latest - -docker tag pulsar:latest ${docker_registry_org}/pulsar:$MVN_VERSION -docker tag pulsar-all:latest ${docker_registry_org}/pulsar-all:$MVN_VERSION +# TODO mvnd -> mvn +mvn -f pulsar/pom.xml install -Ddocker.organization=${docker_registry_org} -Pdocker,push,-main -am -# Push all images and tags -docker push ${docker_registry_org}/pulsar:latest -docker push ${docker_registry_org}/pulsar-all:latest -docker push ${docker_registry_org}/pulsar:$MVN_VERSION -docker push ${docker_registry_org}/pulsar-all:$MVN_VERSION +#docker tag pulsar:latest ${docker_registry_org}/pulsar:latest +#docker tag pulsar-all:latest ${docker_registry_org}/pulsar-all:latest +# +#docker tag pulsar:latest ${docker_registry_org}/pulsar:$MVN_VERSION +#docker tag pulsar-all:latest ${docker_registry_org}/pulsar-all:$MVN_VERSION +#docker tag pulsar-grafana:latest ${docker_registry_org}/pulsar-grafana:$MVN_VERSION +# +## Push all images and tags +#docker push ${docker_registry_org}/pulsar:latest +#docker push ${docker_registry_org}/pulsar-all:latest +#docker push ${docker_registry_org}/pulsar-grafana:latest +#docker push ${docker_registry_org}/pulsar:$MVN_VERSION +#docker push ${docker_registry_org}/pulsar-all:$MVN_VERSION +#docker push ${docker_registry_org}/pulsar-grafana:$MVN_VERSION echo "Finished pushing images to ${docker_registry_org}" diff --git a/docker/pulsar-all/pom.xml b/docker/pulsar-all/pom.xml index b008f5a90a552..22b2c04934724 100644 --- a/docker/pulsar-all/pom.xml +++ b/docker/pulsar-all/pom.xml @@ -69,14 +69,6 @@ docker - - - ${project.groupId} - pulsar-docker-image - ${project.version} - docker-info - - @@ -119,57 +111,73 @@ - com.spotify - dockerfile-maven-plugin - ${dockerfile-maven.version} + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin.version} - default + docker-build + package - build - - - - add-no-repo-and-version - - tag - - - pulsar-all - ${project.version} - - - - add-no-repo-and-latest - - tag + exec - pulsar-all - latest + + 1 + + docker + ${project.basedir} + + build + --no-cache + --build-arg + PULSAR_TARBALL=target/pulsar-server-distribution-${project.version}-bin.tar.gz + -t + pulsar-all:${project.version} + -t + pulsar-all:latest + -t + ${docker.organization}/pulsar-all:${project.version} + -t + ${docker.organization}/pulsar-all:latest + . + - tag-and-push-latest + docker-push + deploy - tag - push + exec - ${docker.organization}/pulsar-all - latest + + 1 + + docker + ${project.basedir} + + buildx + build + --no-cache + --platform=linux/amd64,linux/arm64 + --build-arg + + PULSAR_IO_DIR=target/apache-pulsar-io-connectors-${project.version}-bin + + + PULSAR_OFFLOADER_TARBALL=target/pulsar-offloader-distribution-${project.version}-bin.tar.gz + + --push + -t + ${docker.organization}/pulsar-all:${project.version} + -t + ${docker.organization}/pulsar-all:latest + . + - - ${docker.organization}/pulsar-all - false - ${project.version} - - target/apache-pulsar-io-connectors-${project.version}-bin - target/pulsar-offloader-distribution-${project.version}-bin.tar.gz - - diff --git a/docker/pulsar/Dockerfile b/docker/pulsar/Dockerfile index 1a19220d45575..0389f3458c1bf 100644 --- a/docker/pulsar/Dockerfile +++ b/docker/pulsar/Dockerfile @@ -71,8 +71,11 @@ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 10 # 4. /pulsar - hadoop writes to this directory RUN mkdir /pulsar && chmod g+w /pulsar -ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64 -RUN echo networkaddress.cache.ttl=1 >> /usr/lib/jvm/java-11-openjdk-amd64/conf/security/java.security +RUN java_home=$(ls -d1 /usr/lib/jvm/java-11-openjdk-*) ; \ + ln -s "$java_home" /usr/lib/jvm/java + +ENV JAVA_HOME /usr/lib/jvm/java +RUN echo networkaddress.cache.ttl=1 >> /usr/lib/jvm/java/conf/security/java.security ADD target/python-client/ /pulsar/pulsar-client ENV PULSAR_ROOT_LOGGER=INFO,CONSOLE diff --git a/docker/pulsar/pom.xml b/docker/pulsar/pom.xml index 6d61417f049ee..f27a3906954c6 100644 --- a/docker/pulsar/pom.xml +++ b/docker/pulsar/pom.xml @@ -33,6 +33,8 @@ false false + true + true @@ -53,6 +55,24 @@ + + build + + false + + + false + + + + push + + false + + + false + + docker @@ -79,6 +99,64 @@ + + docker-build + compile + + exec + + + ${docker.build.skip} + docker + ${project.basedir} + + build + --no-cache + --build-arg + PULSAR_TARBALL=target/pulsar-server-distribution-${project.version}-bin.tar.gz + -t + pulsar:${project.version} + -t + pulsar:latest + -t + ${docker.organization}/pulsar:${project.version} + -t + ${docker.organization}/pulsar:latest + . + + + + + docker-push + compile + + exec + + + ${docker.push.skip} + + 1 + + docker + ${project.basedir} + + buildx + build + --no-cache + --platform=linux/amd64,linux/arm64 + --build-arg + PULSAR_TARBALL=target/pulsar-server-distribution-${project.version}-bin.tar.gz + --build-arg + UBUNTU_MIRROR=${env.UBUNTU_MIRROR} + --push + -t + ${docker.organization}/pulsar:${project.version} + -t + ${docker.organization}/pulsar:latest + . + + + @@ -102,59 +180,6 @@ - - com.spotify - dockerfile-maven-plugin - ${dockerfile-maven.version} - - - default - - build - - - - add-no-repo-and-version - - tag - - - pulsar - ${project.version} - - - - add-no-repo-and-latest - - tag - - - pulsar - latest - - - - tag-and-push-latest - - tag - push - - - ${docker.organization}/pulsar - latest - - - - - ${docker.organization}/pulsar - false - ${project.version} - - target/pulsar-server-distribution-${project.version}-bin.tar.gz - ${env.UBUNTU_MIRROR} - - - org.apache.maven.plugins maven-dependency-plugin diff --git a/pulsar-client-cpp/docker/.dockerignore b/pulsar-client-cpp/docker/.dockerignore new file mode 100644 index 0000000000000..64e3e9ee98474 --- /dev/null +++ b/pulsar-client-cpp/docker/.dockerignore @@ -0,0 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +**/target diff --git a/docker/get-version.sh b/pulsar-client-cpp/docker/Dockerfile.build.wheels old mode 100755 new mode 100644 similarity index 81% rename from docker/get-version.sh rename to pulsar-client-cpp/docker/Dockerfile.build.wheels index 07145e7cf0c18..4f8c250b2e949 --- a/docker/get-version.sh +++ b/pulsar-client-cpp/docker/Dockerfile.build.wheels @@ -1,4 +1,3 @@ -#!/usr/bin/env bash # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file @@ -18,11 +17,10 @@ # under the License. # -ROOT_DIR=$(git rev-parse --show-toplevel) +ARG BASE_IMAGE -pushd $ROOT_DIR > /dev/null +FROM $BASE_IMAGE -# Get the project version from the Maven pom.xml -src/get-project-version.py +COPY . /pulsar -popd > /dev/null +RUN /pulsar/pulsar-client-cpp/docker/build-wheel-file-within-docker.sh diff --git a/pulsar-client-cpp/docker/push-images.sh b/pulsar-client-cpp/docker/create-and-push-images.sh similarity index 62% rename from pulsar-client-cpp/docker/push-images.sh rename to pulsar-client-cpp/docker/create-and-push-images.sh index 0501670e52664..0415cb7d42fa6 100755 --- a/pulsar-client-cpp/docker/push-images.sh +++ b/pulsar-client-cpp/docker/create-and-push-images.sh @@ -23,30 +23,30 @@ set -e -DOCKER_ORG=apachepulsar - PYTHON_VERSIONS=( - '2.7 cp27-cp27mu' - '2.7 cp27-cp27m' - '3.5 cp35-cp35m' - '3.6 cp36-cp36m' - '3.7 cp37-cp37m' - '3.8 cp38-cp38' - '3.9 cp39-cp39' + '2.7 cp27-cp27mu manylinux1' + '2.7 cp27-cp27m manylinux1' + '3.5 cp35-cp35m manylinux2014' + '3.6 cp36-cp36m manylinux2014' + '3.7 cp37-cp37m manylinux2014' + '3.8 cp38-cp38 manylinux2014' + '3.9 cp39-cp39 manylinux2014' ) for line in "${PYTHON_VERSIONS[@]}"; do read -r -a PY <<< "$line" PYTHON_VERSION=${PY[0]} PYTHON_SPEC=${PY[1]} - + BASE_IMAGE=${PY[2]} + echo "--------- Build Docker image for $PYTHON_VERSION -- $PYTHON_SPEC" + IMAGE_NAME=pulsar-build:manylinux-$PYTHON_SPEC - FULL_NAME=$DOCKER_ORG/$IMAGE_NAME - echo "IMAGE_NAME: $IMAGE_NAME" - echo "FULL_NAME: $FULL_NAME" - docker tag $IMAGE_NAME $FULL_NAME - docker push $FULL_NAME + docker buildx build -t ${DOCKER_ORG:-apachepulsar}/$IMAGE_NAME $BASE_IMAGE \ + --platform=linux/amd64,linux/arm64 \ + --build-arg PYTHON_VERSION=$PYTHON_VERSION \ + --build-arg PYTHON_SPEC=$PYTHON_SPEC \ + --push - echo "==== Successfully pushed image $FULL_NAME" + echo "==== Successfully built and pushed image $IMAGE_NAME" done diff --git a/tests/docker-images/latest-version-image/pom.xml b/tests/docker-images/latest-version-image/pom.xml index 697772b5dfee4..42a2181022da5 100644 --- a/tests/docker-images/latest-version-image/pom.xml +++ b/tests/docker-images/latest-version-image/pom.xml @@ -44,12 +44,6 @@ java-test-functions ${project.parent.version} - - org.apache.pulsar - pulsar-all-docker-image - ${project.parent.version} - docker-info -