support remote rpm & local rpm / forbid user to set different port
Signed-off-by: 汪渺 <shanhaikang.shk@oceanbase.com>
This commit is contained in:
		@ -2,7 +2,7 @@ FROM openanolis/anolisos
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# docker build --build-arg --build-arg LOCAL_RPM="oceanbase-ce-4.3.0.0-1.alios7.aarch64.rpm" --build-arg LOCAL_LIB_RPM="oceanbase-ce-libs-4.3.0.0-1.alios7.aarch64.rpm" -t observer .
 | 
					# docker build --build-arg --build-arg LOCAL_RPM="oceanbase-ce-4.3.0.0-1.alios7.aarch64.rpm" --build-arg LOCAL_LIB_RPM="oceanbase-ce-libs-4.3.0.0-1.alios7.aarch64.rpm" -t observer .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ARG VERSION
 | 
					ARG VERSION="4.3.0.0"
 | 
				
			||||||
ARG LOCAL_RPM
 | 
					ARG LOCAL_RPM
 | 
				
			||||||
ARG LOCAL_LIB_RPM
 | 
					ARG LOCAL_LIB_RPM
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,9 +1,37 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					MODE_FLAG=$1  # -L | --local | -R | --remote
 | 
				
			||||||
 | 
					REMOTE_VERSION_OR_LOCAL_RPM_PATH=$2
 | 
				
			||||||
 | 
					LOCAL_LIB_RPM_PATH=$3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					REMOTE_VERSION_OR_LOCAL_RPM_NAME=""
 | 
				
			||||||
 | 
					LOCAL_LIB_RPM_NAME=""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TMP_INIT_STORE_PY_SCRIPT="init_store_for_fast_start.tmp.py"
 | 
				
			||||||
 | 
					ACTUAL_INIT_STORE_PY_SCRIPT="./fast_boot_docker_build_prepare/init_store_for_fast_start.py"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CWD=$(cd `dirname $0`;pwd)
 | 
					CWD=$(cd `dirname $0`;pwd)
 | 
				
			||||||
cd "${CWD}"
 | 
					cd "${CWD}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function local_rpm_build() {
 | 
				
			||||||
 | 
					    if [ ! -e ${REMOTE_VERSION_OR_LOCAL_RPM_PATH} ]; then
 | 
				
			||||||
 | 
					        echo "local rpm is not exist"
 | 
				
			||||||
 | 
					        exit -1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if [ ! -e ${LOCAL_LIB_RPM_PATH} ]; then
 | 
				
			||||||
 | 
					        echo "local lib rpm is not exist"
 | 
				
			||||||
 | 
					        exit -1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cp ${REMOTE_VERSION_OR_LOCAL_RPM_PATH} ./fast_boot_docker_build_prepare
 | 
				
			||||||
 | 
					    cp ${REMOTE_VERSION_OR_LOCAL_RPM_PATH} .
 | 
				
			||||||
 | 
					    cp ${LOCAL_LIB_RPM_PATH} ./fast_boot_docker_build_prepare
 | 
				
			||||||
 | 
					    cp ${LOCAL_LIB_RPM_PATH} .
 | 
				
			||||||
 | 
					    REMOTE_VERSION_OR_LOCAL_RPM_NAME=$(basename ${REMOTE_VERSION_OR_LOCAL_RPM_PATH})
 | 
				
			||||||
 | 
					    LOCAL_LIB_RPM_NAME=$(basename ${LOCAL_LIB_RPM_PATH})
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    cd fast_boot_docker_build_prepare && \
 | 
					    cd fast_boot_docker_build_prepare && \
 | 
				
			||||||
docker build --build-arg LOCAL_RPM="oceanbase-ce-4.3.0.0-1.alios7.aarch64.rpm" --build-arg LOCAL_LIB_RPM="oceanbase-ce-libs-4.3.0.0-1.alios7.aarch64.rpm" -t raw_observer .
 | 
					    docker build --build-arg LOCAL_RPM="${REMOTE_VERSION_OR_LOCAL_RPM_NAME}" --build-arg LOCAL_LIB_RPM="${LOCAL_LIB_RPM_NAME}" -t raw_observer .
 | 
				
			||||||
    if [ $? == 0 ]; then
 | 
					    if [ $? == 0 ]; then
 | 
				
			||||||
        echo "================== build prepare docker ok ==============="
 | 
					        echo "================== build prepare docker ok ==============="
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
@ -23,10 +51,72 @@ else
 | 
				
			|||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cd "${CWD}"
 | 
					    cd "${CWD}"
 | 
				
			||||||
docker build --build-arg LOCAL_RPM="oceanbase-ce-4.3.0.0-1.alios7.aarch64.rpm" --build-arg LOCAL_LIB_RPM="oceanbase-ce-libs-4.3.0.0-1.alios7.aarch64.rpm" -t observer .
 | 
					    docker build --build-arg LOCAL_RPM="${REMOTE_VERSION_OR_LOCAL_RPM_NAME}" --build-arg LOCAL_LIB_RPM="${LOCAL_LIB_RPM_NAME}" -t observer .
 | 
				
			||||||
    if [ $? == 0 ]; then
 | 
					    if [ $? == 0 ]; then
 | 
				
			||||||
        echo "================== fast boot docker build ok ==============="
 | 
					        echo "================== fast boot docker build ok ==============="
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        echo "================== fast boot docker build failed ==============="
 | 
					        echo "================== fast boot docker build failed ==============="
 | 
				
			||||||
        exit -1
 | 
					        exit -1
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function remote_rpm_build() {
 | 
				
			||||||
 | 
					    cd fast_boot_docker_build_prepare && \
 | 
				
			||||||
 | 
					    docker build --build-arg VERSION="${REMOTE_VERSION_OR_LOCAL_RPM_NAME}" -t raw_observer .
 | 
				
			||||||
 | 
					    if [ $? == 0 ]; then
 | 
				
			||||||
 | 
					        echo "================== build prepare docker ok ==============="
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        echo "================== build prepare docker failed ==============="
 | 
				
			||||||
 | 
					        exit -1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cd "${CWD}" && mkdir -p ${CWD}/boot/etc
 | 
				
			||||||
 | 
					    docker run -it -v ${CWD}/boot:/root/dest raw_observer
 | 
				
			||||||
 | 
					    if [ $? == 0 ]; then
 | 
				
			||||||
 | 
					        echo "================== prepare docker run ok ==============="
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        echo "================== prepare docker run failed ==============="
 | 
				
			||||||
 | 
					        rm -rf ${CWD}/boot/etc
 | 
				
			||||||
 | 
					        rm -rf ${CWD}/boot/store.tar.gz
 | 
				
			||||||
 | 
					        exit -1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cd "${CWD}"
 | 
				
			||||||
 | 
					    docker build --build-arg VERSION="${REMOTE_VERSION_OR_LOCAL_RPM_NAME}" -t observer .
 | 
				
			||||||
 | 
					    if [ $? == 0 ]; then
 | 
				
			||||||
 | 
					        echo "================== fast boot docker build ok ==============="
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        echo "================== fast boot docker build failed ==============="
 | 
				
			||||||
 | 
					        exit -1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					source ./boot/_env
 | 
				
			||||||
 | 
					OS=`uname`
 | 
				
			||||||
 | 
					cp ${TMP_INIT_STORE_PY_SCRIPT} ${ACTUAL_INIT_STORE_PY_SCRIPT}
 | 
				
			||||||
 | 
					if [ "$OS" == 'Darwin' ]; then
 | 
				
			||||||
 | 
					    sed -i '' -e "s/@OB_MYSQL_PORT@/${OB_MYSQL_PORT}/g" ${ACTUAL_INIT_STORE_PY_SCRIPT}
 | 
				
			||||||
 | 
					    sed -i '' -e "s/@OB_RPC_PORT@/${OB_RPC_PORT}/g" ${ACTUAL_INIT_STORE_PY_SCRIPT}
 | 
				
			||||||
 | 
					    sed -i '' -e "s/@OB_TENANT_NAME@/${OB_TENANT_NAME}/g" ${ACTUAL_INIT_STORE_PY_SCRIPT}
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					    sed -i'' -e "s/@OB_MYSQL_PORT@/${OB_MYSQL_PORT}/g" ${ACTUAL_INIT_STORE_PY_SCRIPT}
 | 
				
			||||||
 | 
					    sed -i'' -e "s/@OB_RPC_PORT@/${OB_RPC_PORT}/g" ${ACTUAL_INIT_STORE_PY_SCRIPT}
 | 
				
			||||||
 | 
					    sed -i'' -e "s/@OB_TENANT_NAME@/${OB_TENANT_NAME}/g" ${ACTUAL_INIT_STORE_PY_SCRIPT}
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					case $MODE_FLAG in
 | 
				
			||||||
 | 
					    -L | --local)
 | 
				
			||||||
 | 
					    local_rpm_build
 | 
				
			||||||
 | 
					    if [ $? != 0 ]; then
 | 
				
			||||||
 | 
					        echo "use local rpm build docker failed"
 | 
				
			||||||
 | 
					        exit -1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					    -R | --remote)
 | 
				
			||||||
 | 
					    remote_rpm_build
 | 
				
			||||||
 | 
					    if [ $? != 0 ]; then
 | 
				
			||||||
 | 
					        echo "use remote rpm build docker failed"
 | 
				
			||||||
 | 
					        exit -1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					esac
 | 
				
			||||||
@ -2,20 +2,28 @@ FROM openanolis/anolisos
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# docker build --build-arg LOCAL_RPM="oceanbase-ce-4.3.0.0-1.alios7.aarch64.rpm" --build-arg LOCAL_LIB_RPM="oceanbase-ce-libs-4.3.0.0-1.alios7.aarch64.rpm" -t raw_observer .
 | 
					# docker build --build-arg LOCAL_RPM="oceanbase-ce-4.3.0.0-1.alios7.aarch64.rpm" --build-arg LOCAL_LIB_RPM="oceanbase-ce-libs-4.3.0.0-1.alios7.aarch64.rpm" -t raw_observer .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Maybe another default version?
 | 
				
			||||||
 | 
					ARG VERSION="4.3.0.0"
 | 
				
			||||||
ARG LOCAL_RPM
 | 
					ARG LOCAL_RPM
 | 
				
			||||||
ARG LOCAL_LIB_RPM
 | 
					ARG LOCAL_LIB_RPM
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RUN yum install -y yum-utils && \
 | 
					RUN yum install -y yum-utils && \
 | 
				
			||||||
 | 
					    yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo && \
 | 
				
			||||||
 | 
					    sed -i 's/$releasever/7/' /etc/yum.repos.d/OceanBase.repo && \
 | 
				
			||||||
    yum install -y libaio mysql && \
 | 
					    yum install -y libaio mysql && \
 | 
				
			||||||
    yum clean all
 | 
					    yum clean all
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RUN mkdir -p /root/pkg && mkdir -p /root/store && mkdir -p /root/dest
 | 
					RUN mkdir -p /root/pkg && mkdir -p /root/store && mkdir -p /root/dest && \
 | 
				
			||||||
 | 
					    if [ "${LOCAL_RPM}" == "" ]; then \
 | 
				
			||||||
 | 
					    yum install -y --downloadonly --downloaddir=. oceanbase-ce-${VERSION}.el7 oceanbase-ce-libs-${VERSION}.el7; \
 | 
				
			||||||
 | 
					    fi && \
 | 
				
			||||||
 | 
					    yum clean all
 | 
				
			||||||
 | 
					
 | 
				
			||||||
COPY ${LOCAL_RPM} /root/pkg
 | 
					COPY ${LOCAL_RPM} /root/pkg
 | 
				
			||||||
COPY ${LOCAL_LIB_RPM} /root/pkg
 | 
					COPY ${LOCAL_LIB_RPM} /root/pkg
 | 
				
			||||||
COPY boot /root/boot/
 | 
					COPY boot /root/boot/
 | 
				
			||||||
ENV PATH /root/boot:$PATH
 | 
					ENV PATH /root/boot:$PATH
 | 
				
			||||||
ENV LD_LIBRARY_PATH /root/ob/lib:$LD_LIBRARY_PATH
 | 
					ENV LD_LIBRARY_PATH /home/admin/oceanbase/lib:/root/ob/lib:$LD_LIBRARY_PATH
 | 
				
			||||||
ENV BOOT_LOCAL_RPM ${LOCAL_RPM}
 | 
					ENV BOOT_LOCAL_RPM ${LOCAL_RPM}
 | 
				
			||||||
ENV BOOT_LOCAL_LIB_RPM ${LOCAL_LIB_RPM}
 | 
					ENV BOOT_LOCAL_LIB_RPM ${LOCAL_LIB_RPM}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -41,18 +41,18 @@ if __name__ == "__main__":
 | 
				
			|||||||
    parser.add_argument("store_tar_file_dir", type=str, help="store dir zip target dir")
 | 
					    parser.add_argument("store_tar_file_dir", type=str, help="store dir zip target dir")
 | 
				
			||||||
    parser.add_argument("etc_dest_dir", type=str, help="the dest dir to save etc config files")
 | 
					    parser.add_argument("etc_dest_dir", type=str, help="the dest dir to save etc config files")
 | 
				
			||||||
    parser.add_argument("--only_build_env", action='store_true', help="build env & start observer without bootstrap and basic check")
 | 
					    parser.add_argument("--only_build_env", action='store_true', help="build env & start observer without bootstrap and basic check")
 | 
				
			||||||
    parser.add_argument("-p", dest="mysql_port", type=str, default="2881")
 | 
					    parser.add_argument("-p", dest="mysql_port", type=str, default="@OB_MYSQL_PORT@")
 | 
				
			||||||
    parser.add_argument("-P", dest="rpc_port", type=str, default="2882")
 | 
					    parser.add_argument("-P", dest="rpc_port", type=str, default="@OB_RPC_PORT@")
 | 
				
			||||||
    parser.add_argument("-z", dest="zone", type=str, default="zone1")
 | 
					    parser.add_argument("-z", dest="zone", type=str, default="zone1")
 | 
				
			||||||
    parser.add_argument("-c", dest="cluster_id", type=str, default="1")
 | 
					    parser.add_argument("-c", dest="cluster_id", type=str, default="1")
 | 
				
			||||||
    parser.add_argument("-d", dest="data_path", type=str, default="/data/store")
 | 
					    parser.add_argument("-d", dest="data_path", type=str, default="/data/store")
 | 
				
			||||||
    parser.add_argument("-i", dest="devname", type=str, default="lo")
 | 
					    parser.add_argument("-i", dest="devname", type=str, default="lo")
 | 
				
			||||||
    parser.add_argument("-r", dest="rootservice", type=str, default="127.0.0.1:2882")
 | 
					    parser.add_argument("-r", dest="rootservice", type=str, default="127.0.0.1:@OB_RPC_PORT@")
 | 
				
			||||||
    parser.add_argument("-I", dest="ip", type=str, default="127.0.0.1")
 | 
					    parser.add_argument("-I", dest="ip", type=str, default="127.0.0.1")
 | 
				
			||||||
    parser.add_argument("-l", dest="log_level", type=str, default="INFO")
 | 
					    parser.add_argument("-l", dest="log_level", type=str, default="INFO")
 | 
				
			||||||
    parser.add_argument("-o", dest="opt_str", type=str, default="__min_full_resource_pool_memory=2147483648,memory_limit=6G,system_memory=1G,datafile_size=256M,log_disk_size=5G,cpu_count=16")
 | 
					    parser.add_argument("-o", dest="opt_str", type=str, default="__min_full_resource_pool_memory=2147483648,memory_limit=6G,system_memory=1G,datafile_size=256M,log_disk_size=5G,cpu_count=16")
 | 
				
			||||||
    parser.add_argument("-N", dest="daemon", type=str, default="1")
 | 
					    parser.add_argument("-N", dest="daemon", type=str, default="1")
 | 
				
			||||||
    parser.add_argument("--tenant_name", type=str, default="test")
 | 
					    parser.add_argument("--tenant_name", type=str, default="@OB_TENANT_NAME@")
 | 
				
			||||||
    parser.add_argument("--max_cpu", type=float, default=14.0)
 | 
					    parser.add_argument("--max_cpu", type=float, default=14.0)
 | 
				
			||||||
    parser.add_argument("--min_cpu", type=float, default=14.0)
 | 
					    parser.add_argument("--min_cpu", type=float, default=14.0)
 | 
				
			||||||
    parser.add_argument("--memory_size", type=int, default=3221225472)
 | 
					    parser.add_argument("--memory_size", type=int, default=3221225472)
 | 
				
			||||||
@ -97,6 +97,7 @@ if __name__ == "__main__":
 | 
				
			|||||||
        cursor = db.cursor(cursor=mysql.cursors.DictCursor)
 | 
					        cursor = db.cursor(cursor=mysql.cursors.DictCursor)
 | 
				
			||||||
        logging.info('connection success!')
 | 
					        logging.info('connection success!')
 | 
				
			||||||
        if not args.only_build_env:
 | 
					        if not args.only_build_env:
 | 
				
			||||||
 | 
					            logging.info("waiting for bootstrap...")
 | 
				
			||||||
            bootstrap_begin = datetime.datetime.now()
 | 
					            bootstrap_begin = datetime.datetime.now()
 | 
				
			||||||
            cursor.execute("ALTER SYSTEM BOOTSTRAP ZONE '%s' SERVER '%s'" % (args.zone, args.rootservice))
 | 
					            cursor.execute("ALTER SYSTEM BOOTSTRAP ZONE '%s' SERVER '%s'" % (args.zone, args.rootservice))
 | 
				
			||||||
            bootstrap_end = datetime.datetime.now()
 | 
					            bootstrap_end = datetime.datetime.now()
 | 
				
			||||||
@ -113,6 +114,7 @@ if __name__ == "__main__":
 | 
				
			|||||||
                            args.tenant_name, args.max_cpu, args.memory_size, args.min_cpu, args.log_disk_size))
 | 
					                            args.tenant_name, args.max_cpu, args.memory_size, args.min_cpu, args.log_disk_size))
 | 
				
			||||||
            cursor.execute("create resource pool %s_pool unit='%s_unit', unit_num=1, zone_list=('%s')" % ( \
 | 
					            cursor.execute("create resource pool %s_pool unit='%s_unit', unit_num=1, zone_list=('%s')" % ( \
 | 
				
			||||||
                            args.tenant_name, args.tenant_name, args.zone))
 | 
					                            args.tenant_name, args.tenant_name, args.zone))
 | 
				
			||||||
 | 
					            logging.info("waiting for create tenant...")
 | 
				
			||||||
            create_tenant_begin = datetime.datetime.now()
 | 
					            create_tenant_begin = datetime.datetime.now()
 | 
				
			||||||
            cursor.execute("create tenant %s replica_num=1,zone_list=('%s'),primary_zone='RANDOM',resource_pool_list=('%s_pool') set ob_tcp_invited_nodes='%%', ob_compatibility_mode = 'mysql'" % ( \
 | 
					            cursor.execute("create tenant %s replica_num=1,zone_list=('%s'),primary_zone='RANDOM',resource_pool_list=('%s_pool') set ob_tcp_invited_nodes='%%', ob_compatibility_mode = 'mysql'" % ( \
 | 
				
			||||||
                            args.tenant_name, args.zone, args.tenant_name))
 | 
					                            args.tenant_name, args.zone, args.tenant_name))
 | 
				
			||||||
		Reference in New Issue
	
	Block a user