Skip to content

Commit

Permalink
[apache#2326] feat(docker): support build with arg platform=all on Do…
Browse files Browse the repository at this point in the history
…ris docker image (apache#2327)

### What changes were proposed in this pull request?

support `platform=all` for doris images

### Why are the changes needed?

Fix: apache#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
```
  • Loading branch information
zhoukangcn authored Feb 28, 2024
1 parent 2ea1eef commit 6ba1a88
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 43 deletions.
2 changes: 1 addition & 1 deletion dev/docker/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions dev/docker/doris/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
FROM ubuntu:22.04
LABEL maintainer="[email protected]"

ARG DORIS_PACKAGE_NAME
ARG DORIS_FILE_NAME
ARG TARGET_ARCH
ARG DORIS_VERSION
ARG TARGETARCH

WORKDIR /

Expand Down Expand Up @@ -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}

Expand All @@ -56,4 +54,4 @@ WORKDIR ${DORIS_HOME}
EXPOSE 8030
EXPOSE 9030

CMD ["bash", "start.sh"]
CMD ["bash", "start.sh"]
108 changes: 73 additions & 35 deletions dev/docker/doris/doris-dependency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,108 @@ 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
shift
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
exit 1
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

0 comments on commit 6ba1a88

Please sign in to comment.