From 6eb08b8c9d876c990d6a57d71543e2aa6e7d8598 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} | 34 ++--- docker/get-version.sh | 28 ---- docker/grafana/pom.xml | 71 +++++----- docker/pulsar-all/pom.xml | 91 ++++++++----- docker/pulsar/Dockerfile | 9 +- docker/pulsar/pom.xml | 128 +++++++++++------- pulsar-client-cpp/docker/.dockerignore | 1 + .../docker/Dockerfile.build.wheels | 7 + ...sh-images.sh => create-and-push-images.sh} | 32 ++--- 14 files changed, 245 insertions(+), 249 deletions(-) delete mode 100755 build/docker/publish.sh rename docker/{publish.sh => build_and_publish.sh} (68%) delete mode 100755 docker/get-version.sh create mode 100644 pulsar-client-cpp/docker/.dockerignore create mode 100644 pulsar-client-cpp/docker/Dockerfile.build.wheels 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 3fa3be9e0082d6..fc81a2beb8e51b 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 4b6b8a3a84765a..da4b04e9f0f3e6 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 bc2fe532f74e05..cfb21dd687f336 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 6bfa56bace6d86..00000000000000 --- 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 d8ab4bea882c42..05756706f05e0e 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 68% rename from docker/publish.sh rename to docker/build_and_publish.sh index 1df2dd7bebabe0..aefa592d4ff4a7 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,20 +59,23 @@ 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-grafana:latest ${docker_registry_org}/pulsar-grafana: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 +# TODO mvnd -> mvn +mvnd -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-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 +#docker tag pulsar:latest ${docker_registry_org}/pulsar:latest +#docker tag pulsar-all:latest ${docker_registry_org}/pulsar-all:latest +#docker tag pulsar-grafana:latest ${docker_registry_org}/pulsar-grafana: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/get-version.sh b/docker/get-version.sh deleted file mode 100755 index 07145e7cf0c186..00000000000000 --- a/docker/get-version.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env 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) - -pushd $ROOT_DIR > /dev/null - -# Get the project version from the Maven pom.xml -src/get-project-version.py - -popd > /dev/null diff --git a/docker/grafana/pom.xml b/docker/grafana/pom.xml index 5a3b85fa7fed57..c8c77ad3e4f25a 100644 --- a/docker/grafana/pom.xml +++ b/docker/grafana/pom.xml @@ -36,53 +36,58 @@ - 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-grafana - ${project.version} - - - - add-no-repo-and-latest - - tag + exec - pulsar-grafana - latest + docker + ${project.basedir} + + build + -t + pulsar-grafana:${project.version} + -t + pulsar-grafana:latest + -t + ${docker.organization}/pulsar-grafana:${project.version} + -t + ${docker.organization}/pulsar-grafana:latest + . + - tag-and-push-latest + docker-push + deploy - tag - push + exec - ${docker.organization}/pulsar-grafana - latest + + 1 + + docker + ${project.basedir} + + buildx + build + --push + -t + ${docker.organization}/pulsar-grafana:${project.version} + -t + ${docker.organization}/pulsar-grafana:latest + . + - - ${docker.organization}/pulsar-grafana - ${project.version} - false - diff --git a/docker/pulsar-all/pom.xml b/docker/pulsar-all/pom.xml index b008f5a90a5527..09f2b9239ff4c2 100644 --- a/docker/pulsar-all/pom.xml +++ b/docker/pulsar-all/pom.xml @@ -119,57 +119,74 @@ - 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 + --platform=linux/amd64,linux/arm64 + --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 2dbd78dabead2d..b78f887d337456 100644 --- a/docker/pulsar/Dockerfile +++ b/docker/pulsar/Dockerfile @@ -59,8 +59,11 @@ RUN python3 get-pip.py RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 10 -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 @@ -69,4 +72,4 @@ ENV PULSAR_ROOT_LOGGER=INFO,CONSOLE COPY --from=pulsar /pulsar /pulsar WORKDIR /pulsar -RUN /pulsar/bin/install-pulsar-client.sh \ No newline at end of file +RUN /pulsar/bin/install-pulsar-client.sh diff --git a/docker/pulsar/pom.xml b/docker/pulsar/pom.xml index 20a9c2eaa3676c..7c44cb33877c66 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,62 @@ + + docker-build + compile + + exec + + + ${docker.build.skip} + docker + ${project.basedir} + + build + + --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 + + --platform=linux/amd64,linux/arm64 + --build-arg + PULSAR_TARBALL=target/pulsar-server-distribution-${project.version}-bin.tar.gz + --push + -t + ${docker.organization}/pulsar:${project.version} + -t + ${docker.organization}/pulsar:latest + . + + + @@ -102,58 +178,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 - - - 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 00000000000000..b60de5b5f2c97e --- /dev/null +++ b/pulsar-client-cpp/docker/.dockerignore @@ -0,0 +1 @@ +**/target diff --git a/pulsar-client-cpp/docker/Dockerfile.build.wheels b/pulsar-client-cpp/docker/Dockerfile.build.wheels new file mode 100644 index 00000000000000..dde96cf40df034 --- /dev/null +++ b/pulsar-client-cpp/docker/Dockerfile.build.wheels @@ -0,0 +1,7 @@ +ARG BASE_IMAGE + +FROM $BASE_IMAGE + +COPY . /pulsar + +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 0501670e52664a..0415cb7d42fa6d 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