Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[k8s](improve)add docker resource script for k8s #33329

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docker/runtime/be/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/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
Expand Down Expand Up @@ -51,10 +50,14 @@ ADD resource/apache-doris-${DORIS_VERSION}-bin-${TARGETARCH:-amd64}/be /opt/apac

COPY resource/be_*.sh /opt/apache-doris/

COPY --from=selectdb/doris-debug-ubuntu:latest /doris-debug /opt/apache-doris/

COPY resource/entry_point.sh /usr/local/bin/

COPY resource/init_be.sh /usr/local/bin/

#RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

WORKDIR /opt/apache-doris

ENTRYPOINT ["bash","entry_point.sh"]
244 changes: 244 additions & 0 deletions docker/runtime/be/resource/be_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
#!/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.


# the fe query port for mysql.
FE_QUERY_PORT=${FE_QUERY_PORT:-9030}
# timeout for probe fe master.
PROBE_TIMEOUT=60
# interval time to probe fe.
PROBE_INTERVAL=2
# rpc port for fe communicate with be.
HEARTBEAT_PORT=9050
# fqdn or ip
MY_SELF=
MY_IP=`hostname -i`
MY_HOSTNAME=`hostname -f`
DORIS_ROOT=${DORIS_ROOT:-"/opt/apache-doris"}
# if config secret for basic auth about operate node of doris, the path must be `/etc/basic_auth`. This is set by operator and the key of password must be `password`.
AUTH_PATH="/etc/basic_auth"
DORIS_HOME=${DORIS_ROOT}/be
BE_CONFIG=$DORIS_HOME/conf/be.conf
# represents self in fe meta or not.
REGISTERED=false

DB_ADMIN_USER=${USER:-"root"}

DB_ADMIN_PASSWD=$PASSWD

log_stderr()
{
echo "[`date`] $@" >&2
}

update_conf_from_configmap()
{
if [[ "x$CONFIGMAP_MOUNT_PATH" == "x" ]] ; then
log_stderr '[info] Empty $CONFIGMAP_MOUNT_PATH env var, skip it!'
return 0
fi
if ! test -d $CONFIGMAP_MOUNT_PATH ; then
log_stderr "[info] $CONFIGMAP_MOUNT_PATH not exist or not a directory, ignore ..."
return 0
fi
local tgtconfdir=$DORIS_HOME/conf
for conffile in `ls $CONFIGMAP_MOUNT_PATH`
do
log_stderr "[info] Process conf file $conffile ..."
local tgt=$tgtconfdir/$conffile
if test -e $tgt ; then
# make a backup
mv -f $tgt ${tgt}.bak
fi
ln -sfT $CONFIGMAP_MOUNT_PATH/$conffile $tgt
done
}

# resolve password for root
resolve_password_from_secret()
{
if [[ -f "$AUTH_PATH/password" ]]; then
DB_ADMIN_PASSWD=`cat $AUTH_PATH/password`
fi
if [[ -f "$AUTH_PATH/username" ]]; then
DB_ADMIN_USER=`cat $AUTH_PATH/username`
fi
}

# get all backends info to check self exist or not.
show_backends(){
local svc=$1
backends=`timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -uroot --skip-column-names --batch -e 'SHOW BACKENDS;' 2>&1`
log_stderr "[info] use root no password show backends result $backends ."
if echo $backends | grep -w "1045" | grep -q -w "28000" &>/dev/null; then
log_stderr "[info] use username and password that configured to show backends."
backends=`timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -u$DB_ADMIN_USER -p$DB_ADMIN_PASSWD --skip-column-names --batch -e 'SHOW BACKENDS;'`
fi

echo "$backends"

#if [[ "x$DB_ADMIN_PASSWD" != "x" ]]; then
# timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -u$DB_ADMIN_USER -p$DB_ADMIN_PASSWD --skip-column-names --batch -e 'SHOW BACKENDS;'
#else
# timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -u$DB_ADMIN_USER --skip-column-names --batch -e 'SHOW BACKENDS;'
#fi
}

# get all registered fe in cluster, for check the fe have `MASTER`.
function show_frontends()
{
local addr=$1
frontends=`timeout 15 mysql --connect-timeout 2 -h $addr -P $FE_QUERY_PORT -uroot --batch -e 'show frontends;' 2>&1`
log_stderr "[info] use root no password show frontends result $frontends ."
if echo $frontends | grep -w "1045" | grep -q -w "28000" &>/dev/null; then
log_stderr "[info] use username and passwore that configured to show frontends."
frontends=`timeout 15 mysql --connect-timeout 2 -h $addr -P $FE_QUERY_PORT -u$DB_ADMIN_USER -p$DB_ADMIN_PASSWD --batch -e 'show frontends;'`
fi

echo "$frontends"
#if [[ "x$DB_ADMIN_PASSWD" != "x" ]]; then
# timeout 15 mysql --connect-timeout 2 -h $addr -P $FE_QUERY_PORT -u$DB_ADMIN_USER -p$DB_ADMIN_PASSWD --batch -e 'show frontends;'
#else
# timeout 15 mysql --connect-timeout 2 -h $addr -P $FE_QUERY_PORT -u$DB_ADMIN_USER --batch -e 'show frontends;'
#fi
}

#parse the `$BE_CONFIG` file, passing the key need resolve as parameter.
parse_confval_from_conf()
{
# a naive script to grep given confkey from fe conf file
# assume conf format: ^\s*<key>\s*=\s*<value>\s*$
local confkey=$1
local confvalue=`grep "\<$confkey\>" $BE_CONFIG | grep -v '^\s*#' | sed 's|^\s*'$confkey'\s*=\s*\(.*\)\s*$|\1|g'`
echo "$confvalue"
}

collect_env_info()
{
# heartbeat_port from conf file
local heartbeat_port=`parse_confval_from_conf "heartbeat_service_port"`
if [[ "x$heartbeat_port" != "x" ]] ; then
HEARTBEAT_PORT=$heartbeat_port
fi

if [[ "x$HOST_TYPE" == "xIP" ]] ; then
MY_SELF=$MY_IP
else
MY_SELF=$MY_HOSTNAME
fi
}

add_self()
{
local svc=$1
start=`date +%s`
local timeout=$PROBE_TIMEOUT

while true
do
memlist=`show_backends $svc`
if echo "$memlist" | grep -q -w "$MY_SELF" &>/dev/null ; then
log_stderr "[info] Check myself ($MY_SELF:$HEARTBEAT_PORT) exist in FE, start be directly ..."
break;
fi

# check fe cluster have master, if fe have not master wait.
fe_memlist=`show_frontends $svc`
local pos=`echo "$fe_memlist" | grep '\<IsMaster\>' | awk -F '\t' '{for(i=1;i<NF;i++) {if ($i == "IsMaster") print i}}'`
local leader=`echo "$fe_memlist" | grep '\<FOLLOWER\>' | awk -v p="$pos" -F '\t' '{if ($p=="true") print $2}'`
log_stderr "'IsMaster' sequence in columns is $pos master=$leader ."

if [[ "x$leader" == "x" ]]; then
log_stderr "[info] resolve the eighth column for finding master !"
leader=`echo "$fe_memlist" | grep '\<FOLLOWER\>' | awk -F '\t' '{if ($8=="true") print $2}'`
fi
if [[ "x$leader" == "x" ]]; then
# compatible 2.1.0
log_stderr "[info] resoluve the ninth column for finding master!"
leader=`echo "$fe_memlist" | grep '\<FOLLOWER\>' | awk -F '\t' '{if ($9=="true") print $2}'`
fi

if [[ "x$leader" != "x" ]]; then
log_stderr "[info] myself ($MY_SELF:$HEARTBEAT_PORT) not exist in FE and fe have leader register myself into fe."
add_result=`timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -uroot --skip-column-names --batch -e "ALTER SYSTEM ADD BACKEND \"$MY_SELF:$HEARTBEAT_PORT\";" 2>&1`
if echo $add_result | grep -w "1045" | grep -q -w "28000" &>/dev/null ; then
timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -u$DB_ADMIN_USER -p$DB_ADMIN_PASSWD --skip-column-names --batch -e "ALTER SYSTEM ADD BACKEND \"$MY_SELF:$HEARTBEAT_PORT\";"
fi

#if [[ "x$DB_ADMIN_PASSWD" != "x" ]]; then
# timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -u$DB_ADMIN_USER -p$DB_ADMIN_PASSWD --skip-column-names --batch -e "ALTER SYSTEM ADD BACKEND \"$MY_SELF:$HEARTBEAT_PORT\";"
#else
# timeout 15 mysql --connect-timeout 2 -h $svc -P $FE_QUERY_PORT -u$DB_ADMIN_USER --skip-column-names --batch -e "ALTER SYSTEM ADD BACKEND \"$MY_SELF:$HEARTBEAT_PORT\";"
#fi

let "expire=start+timeout"
now=`date +%s`
if [[ $expire -le $now ]] ; then
log_stderr "[error] exit probe master for probing timeout."
return 0
fi
else
log_stderr "[info] not have leader wait fe cluster elect a master, sleep 2s..."
sleep $PROBE_INTERVAL
fi
done
}

# check be exist or not, if exist return 0, or register self in fe cluster. when all fe address failed exit script.
# `xxx1:port,xxx2:port` as parameter to function.
function check_and_register()
{
addrs=$1
local addrArr=(${addrs//,/ })
for addr in ${addrArr[@]}
do
add_self $addr

if [[ $REGISTERED ]]; then
break;
fi
done

if [[ $REGISTERED ]]; then
return 0
else
log_stderr "not find master in fe cluster, please use mysql connect to fe for verfing the master exist and verify domain connectivity with two pods in different node. "
exit 1
fi
}

fe_addrs=$1
if [[ "x$fe_addrs" == "x" ]]; then
echo "need fe address as paramter!"
echo " Example $0 <fe_addr>"
exit 1
fi

update_conf_from_configmap
# resolve password for root to manage nodes in doris.
resolve_password_from_secret
collect_env_info
#add_self $fe_addr || exit $?
check_and_register $fe_addrs
./doris-debug --component be
log_stderr "run start_be.sh"
# the server will start in the current terminal session, and the log output and console interaction will be printed to that terminal
# befor doris 2.0.2 ,doris start with : start_xx.sh
# sine doris 2.0.2 ,doris start with : start_xx.sh --console doc: https://doris.apache.org/docs/dev/install/standard-deployment/#version--202
$DORIS_HOME/bin/start_be.sh --console

21 changes: 21 additions & 0 deletions docker/runtime/be/resource/be_prestop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/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.

DORIS_ROOT=${DORIS_ROOT:-"/opt/apache-doris"}
DORIS_HOME=${DORIS_ROOT}/be
$DORIS_HOME/bin/stop_be.sh
Empty file modified docker/runtime/be/resource/entry_point.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion docker/runtime/be/resource/init_be.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ _main() {
fi
check_be_status
doris_note "Ready to start BE!"
start_be.sh --console &
${DORIS_HOME}/be/bin/start_be.sh --console &
child_pid=$!
wait $child_pid
exec "$@"
Expand Down
54 changes: 36 additions & 18 deletions docker/runtime/broker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/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
Expand All @@ -16,26 +15,45 @@
# specific language governing permissions and limitations
# under the License.

# choose a base image
FROM openjdk:8u342-jdk
# how to use Dockerfile.
# this is dockerfile for build doris broker image on amd64.
# when build youself image.
# 1. pull binary from official website and decompress into resource directory that the level equals with Dockerfile_broker_ubuntu.
# 2. untar xxxx.tar.gz in resource directory, update the dockerfile field `apache-doris-xxx`, replace with real version.
# 3. run commad docker build -t xxx.doris.broker:xx -f Dockerfile_broker_ubuntu.

# we have support buildx for amd64 and arm64 architecture image build.
# get the binary from doris github and utar into resource, update the directory as apache-`version(example:2.0.1)`-bin-`architecture(amd64/arm64)` mode.
#

FROM ubuntu:22.04

ARG TARGETARCH

ARG DORIS_VERSION="x.x.x"

RUN apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
patchelf gdb binutils binutils-common mysql-client \
curl wget less vim htop iproute2 numactl jq iotop sysstat \
tcpdump iputils-ping dnsutils strace lsof blktrace tzdata \
bpfcc-tools linux-headers-realtime linux-tools-realtime silversearcher-ag \
net-tools openjdk-8-jdk && \
rm -rf /var/lib/apt/lists/*

# set environment variables
ENV JAVA_HOME="/usr/local/openjdk-8/" \
PATH="/opt/apache-doris/broker/bin:$PATH"
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-${TARGETARCH:-amd64}

# apache-doris/broker from doris release xxxx.tar.gz
ADD resource/apache-doris-${DORIS_VERSION}-bin-${TARGETARCH:-amd64}/extensions/apache_hdfs_broker /opt/apache-doris/apache_hdfs_broker

COPY resource/broker_*.sh /opt/apache-doris/

RUN chmod +x /opt/apache-doris/broker_*.sh

# Download the software to the mirror, where the broker directory is synchronously compressed to the binary package of FE,
# which needs to be decompressed and repackaged by itself, and can be replaced as needed
ADD ./resource/apache_hdfs_broker.tar.gz /opt/
ADD ./resource/init_broker.sh /usr/local/bin/

# deploy software
RUN apt-get update && \
apt-get install -y default-mysql-client && \
apt-get clean && \
mkdir /opt/apache-doris && \
cd /opt && \
mv apache_hdfs_broker /opt/apache-doris/broker
RUN chmod 755 /usr/local/bin/init_broker.sh

ADD ./resource/init_broker.sh /opt/apache-doris/broker/bin
RUN chmod 755 /opt/apache-doris/broker/bin/init_broker.sh
WORKDIR /opt/apache-doris

ENTRYPOINT ["/opt/apache-doris/broker/bin/init_broker.sh"]
ENTRYPOINT ["bash","init_broker.sh"]
Loading
Loading