From 6ba1a8832e4302249f9d923240bf29cb9ccdf33d Mon Sep 17 00:00:00 2001 From: Kang Date: Wed, 28 Feb 2024 10:54:36 +0800 Subject: [PATCH] [#2326] feat(docker): support build with arg platform=all on Doris docker image (#2327) ### What changes were proposed in this pull request? support `platform=all` for doris images ### Why are the changes needed? Fix: #2326 ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? local ``` ./build-docker.sh --type doris --image doris_ci --tag test ./build-docker.sh --platform linux/arm64 --type doris --image doris_ci --tag test ./build-docker.sh --platform linux/amd64 --type doris --image doris_ci --tag test ``` --- dev/docker/build-docker.sh | 2 +- dev/docker/doris/Dockerfile | 12 ++- dev/docker/doris/doris-dependency.sh | 108 ++++++++++++++++++--------- 3 files changed, 79 insertions(+), 43 deletions(-) diff --git a/dev/docker/build-docker.sh b/dev/docker/build-docker.sh index be00d27f736..fd7abff159d 100755 --- a/dev/docker/build-docker.sh +++ b/dev/docker/build-docker.sh @@ -80,7 +80,7 @@ elif [ "${component_type}" == "gravitino" ]; then . ${script_dir}/gravitino/gravitino-dependency.sh elif [ "${component_type}" == "doris" ]; then . ${script_dir}/doris/doris-dependency.sh --platform ${platform_type} - build_args="--build-arg DORIS_PACKAGE_NAME=${DORIS_PACKAGE_NAME} --build-arg DORIS_FILE_NAME=${DORIS_FILE_NAME}" + build_args="--build-arg DORIS_VERSION=${DORIS_VERSION}" else echo "ERROR : ${component_type} is not a valid component type" usage diff --git a/dev/docker/doris/Dockerfile b/dev/docker/doris/Dockerfile index acf42ad69e9..f655d56e590 100644 --- a/dev/docker/doris/Dockerfile +++ b/dev/docker/doris/Dockerfile @@ -5,9 +5,8 @@ FROM ubuntu:22.04 LABEL maintainer="support@datastrato.com" -ARG DORIS_PACKAGE_NAME -ARG DORIS_FILE_NAME -ARG TARGET_ARCH +ARG DORIS_VERSION +ARG TARGETARCH WORKDIR / @@ -42,9 +41,8 @@ RUN ARCH=$(uname -m) && \ ################################################################################# ## add files - -ADD packages/${DORIS_FILE_NAME} /opt -RUN ln -s /opt/${DORIS_PACKAGE_NAME} ${DORIS_HOME} +ADD packages/doris-${TARGETARCH}.tar.xz /opt/ +RUN ln -s /opt/apache-doris-${DORIS_VERSION}-bin-* ${DORIS_HOME} COPY start.sh ${DORIS_HOME} @@ -56,4 +54,4 @@ WORKDIR ${DORIS_HOME} EXPOSE 8030 EXPOSE 9030 -CMD ["bash", "start.sh"] \ No newline at end of file +CMD ["bash", "start.sh"] diff --git a/dev/docker/doris/doris-dependency.sh b/dev/docker/doris/doris-dependency.sh index 043af530e68..887a8909173 100755 --- a/dev/docker/doris/doris-dependency.sh +++ b/dev/docker/doris/doris-dependency.sh @@ -8,6 +8,11 @@ doris_dir="$(dirname "${BASH_SOURCE-$0}")" doris_dir="$(cd "${doris_dir}">/dev/null; pwd)" TARGET_ARCH="" +AMD64="amd64" +ARM64="arm64" + +DORIS_X64="x64" +DORIS_ARM64="arm64" # Get platform type if [[ "$1" == "--platform" ]]; then @@ -15,13 +20,13 @@ if [[ "$1" == "--platform" ]]; then platform_type="$1" if [[ "${platform_type}" == "linux/amd64" ]]; then echo "INFO : doris build platform type is ${platform_type}" - TARGET_ARCH="x64" + TARGET_ARCH="${AMD64}" elif [[ "${platform_type}" == "linux/arm64" ]]; then echo "INFO : doris build platform type is ${platform_type}" - TARGET_ARCH="arm64" + TARGET_ARCH="${ARM64}" elif [[ "${platform_type}" == "all" ]]; then - echo "ERROR : doris not support ${platform_type}" - exit 1 + echo "INFO : doris build platform type is ${platform_type}" + TARGET_ARCH="all" else echo "ERROR : ${platform_type} is not a valid platform type for doris" usage @@ -29,49 +34,82 @@ if [[ "$1" == "--platform" ]]; then fi shift else - echo "ERROR: must specify platform for doris" - exit 1 + TARGET_ARCH="all" fi # Environment variables definition DORIS_VERSION="1.2.7.1" -DORIS_PACKAGE_NAME="apache-doris-${DORIS_VERSION}-bin-${TARGET_ARCH}" -DORIS_FILE_NAME="${DORIS_PACKAGE_NAME}.tar.xz" -DORIS_DOWNLOAD_URL="https://apache-doris-releases.oss-accelerate.aliyuncs.com/${DORIS_FILE_NAME}" -SHA512SUMS_URL="${DORIS_DOWNLOAD_URL}.sha512" +download_and_check() { + local arch="${1}" + local doris_package_arch="" -# Prepare download packages -if [[ ! -d "${doris_dir}/packages" ]]; then - mkdir -p "${doris_dir}/packages" -fi + if [[ "$arch" == "${ARM64}" ]]; then + doris_package_arch="${DORIS_ARM64}" + elif [[ "$arch" == "${AMD64}" ]]; then + doris_package_arch="${DORIS_X64}" + else + echo "ERROR : ${arch} is not a valid arch type for doris" + exit 1 + fi -if [[ ! -f "${doris_dir}/packages/${DORIS_FILE_NAME}" ]]; then - curl -s -o "${doris_dir}/packages/${DORIS_FILE_NAME}" ${DORIS_DOWNLOAD_URL} -fi + # Download doris package + DORIS_PACKAGE_NAME="apache-doris-${DORIS_VERSION}-bin-${doris_package_arch}" + DORIS_FILE_NAME="${DORIS_PACKAGE_NAME}.tar.xz" + DORIS_DOWNLOAD_URL="https://apache-doris-releases.oss-accelerate.aliyuncs.com/${DORIS_FILE_NAME}" + SHA512SUMS_URL="${DORIS_DOWNLOAD_URL}.sha512" -# download sha512sum file -if [[ ! -f "${doris_dir}/packages/${DORIS_FILE_NAME}.sha512" ]]; then - curl -s -o "${doris_dir}/packages/${DORIS_FILE_NAME}.sha512" ${SHA512SUMS_URL} -fi + download_dir="${doris_dir}/packages/" + # Prepare download packages + if [[ ! -d "${download_dir}" ]]; then + mkdir -p "${download_dir}" + fi + + if [[ ! -f "${download_dir}/${DORIS_FILE_NAME}" ]]; then + echo "INFO : Downloading doris package ${download_dir}/${DORIS_FILE_NAME}" + curl -s -o "${download_dir}/${DORIS_FILE_NAME}" ${DORIS_DOWNLOAD_URL} + echo "INFO : Downloading doris package done" + fi -cd "${doris_dir}/packages" || exit 1 + # download sha512sum file + if [[ ! -f "${download_dir}/${DORIS_FILE_NAME}.sha512" ]]; then + curl -s -o "${download_dir}/${DORIS_FILE_NAME}.sha512" ${SHA512SUMS_URL} + fi -# check sha512sum, if check file failed, exit 1 + cd "${download_dir}" || exit 1 -if command -v shasum &>/dev/null; then - shasum -c "${DORIS_FILE_NAME}.sha512" -elif command -v sha512sum &>/dev/null; then - sha512sum -c "${DORIS_FILE_NAME}.sha512" -else - cat << EOF - WARN: cannot find shasum or sha512sum command, skip sha512sum check, please check the sha512sum by yourself. - if build Docker image failed, maybe the package is broken. + # check sha512sum, if check file failed, exit 1 + echo "INFO : Checking sha512sum for ${DORIS_FILE_NAME}" + if command -v shasum &>/dev/null; then + shasum -c "${DORIS_FILE_NAME}.sha512" + elif command -v sha512sum &>/dev/null; then + sha512sum -c "${DORIS_FILE_NAME}.sha512" + else + cat << EOF + WARN: cannot find shasum or sha512sum command, skip sha512sum check, please check the sha512sum by yourself. + if build Docker image failed, maybe the package is broken. EOF -fi + fi + + if [ $? -ne 0 ]; then + echo "ERROR: check doris package sha512sum failed" + exit 1 + fi + + # copy doris package and rename to doris-${arch}.tar.xz + # it's a little trick, because the doris package name for 'amd64' is different as 'x64' + # rename to x64 can use ADD (instead of COPY) in Dockerfile, this will reduce the image size(about 1.6GB) + if [[ -f "${download_dir}/doris-${arch}.tar.xz" ]]; then + rm -f "${download_dir}/doris-${arch}.tar.xz" + fi + + cp "${DORIS_FILE_NAME}" "doris-${arch}.tar.xz" +} -if [ $? -ne 0 ]; then - echo "ERROR: sha512sum check failed" - exit 1 +if [[ "${TARGET_ARCH}" == "all" ]]; then + download_and_check "${AMD64}" + download_and_check "${ARM64}" +else + download_and_check "${TARGET_ARCH}" fi \ No newline at end of file