diff --git a/doc/quick-start/Dockerfile b/doc/quick-start/Dockerfile index 54b2edd0e..1031f0ae2 100644 --- a/doc/quick-start/Dockerfile +++ b/doc/quick-start/Dockerfile @@ -5,6 +5,7 @@ WORKDIR /build COPY . . RUN set -eux && \ + sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list && \ apt-get update && apt-get install -y git build-essential autoconf autogen libtool clang && \ git clone --branch v3.21.12 --recurse-submodules https://github.com/protocolbuffers/protobuf && \ cd protobuf && ./autogen.sh && ./configure && make -j4 && make install && cd .. && ldconfig && \ @@ -19,6 +20,7 @@ RUN set -eux && \ COPY --from=builder /build/target/release/xline /usr/local/bin COPY --from=builder /build/target/release/benchmark /usr/local/bin -COPY --from=builder /build/target/release/lock_client /usr/local/bin +COPY --from=builder /build/target/release/validation_lock_client /usr/local/bin +COPY --from=builder /build/scripts/start_xline.sh /usr/local/bin -CMD ["/usr/local/bin/xline"] +CMD ["/bin/bash", "/usr/local/bin/start_xline.sh"] diff --git a/scripts/Dockerfile b/scripts/Dockerfile index 7ec81facb..3ac273b30 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -2,7 +2,9 @@ FROM ubuntu:latest COPY xline /usr/local/bin COPY benchmark /usr/local/bin +COPY start_xline.sh /usr/local/bin RUN apt-get update && apt-get install -y iproute2 iputils-ping -CMD ["/usr/local/bin/xline"] + +CMD ["/bin/bash", "/usr/local/bin/start_xline.sh"] diff --git a/scripts/quick_start.sh b/scripts/quick_start.sh index 2154c3b2c..fa1d41b4a 100755 --- a/scripts/quick_start.sh +++ b/scripts/quick_start.sh @@ -6,36 +6,6 @@ DIR=$( SERVERS=("172.20.0.2" "172.20.0.3" "172.20.0.4" "172.20.0.5") MEMBERS="node1=${SERVERS[1]}:2379,${SERVERS[1]}:2380,node2=${SERVERS[2]}:2379,${SERVERS[2]}:2380,node3=${SERVERS[3]}:2379,${SERVERS[3]}:2380" -# run xline node by index -# args: -# $1: index of the node -run_xline() { - cmd="/usr/local/bin/xline \ - --name node${1} \ - --members ${MEMBERS} \ - --storage-engine rocksdb \ - --data-dir /usr/local/xline/data-dir \ - --auth-public-key /mnt/public.pem \ - --auth-private-key /mnt/private.pem" - - if [ ${1} -eq 1 ]; then - cmd="${cmd} --is-leader" - fi - - docker exec -e RUST_LOG=debug -d node${1} ${cmd} - echo "command is: docker exec -e RUST_LOG=debug -d node${1} ${cmd}" -} - -# run cluster of xline/etcd in container -run_cluster() { - echo cluster starting - run_xline 1 & - run_xline 2 & - run_xline 3 & - wait - echo cluster started -} - # stop all containers stop_all() { echo stopping @@ -57,9 +27,23 @@ run_container() { size=${1} image="ghcr.io/xline-kv/xline:latest" for ((i = 1; i <= ${size}; i++)); do - docker run -d -it --rm --name=node${i} --net=xline_net --ip=${SERVERS[$i]} --cap-add=NET_ADMIN --cpu-shares=1024 -m=512M -v ${DIR}:/mnt ${image} bash & + if [ "$i" -eq 1 ]; then + docker run \ + -e RUST_LOG=debug -e HOSTNAME=node${i} -e MEMBERS=${MEMBERS} -e IS_LEADER=true \ + -d -it --rm --name=node${i} \ + --net=xline_net --ip=${SERVERS[$i]} --cap-add=NET_ADMIN \ + --cpu-shares=1024 -m=512M -v ${DIR}:/mnt ${image} & + else + docker run \ + -e RUST_LOG=debug -e HOSTNAME=node${i} -e MEMBERS=${MEMBERS} \ + -d -it --rm --name=node${i} \ + --net=xline_net --ip=${SERVERS[$i]} --cap-add=NET_ADMIN \ + --cpu-shares=1024 -m=512M -v ${DIR}:/mnt ${image} & + fi done - docker run -d -it --rm --name=client --net=xline_net --ip=${SERVERS[0]} --cap-add=NET_ADMIN --cpu-shares=1024 -m=512M -v ${DIR}:/mnt ghcr.io/xline-kv/etcdctl:v3.5.9 bash & + docker run -d -it --rm --name=client \ + --net=xline_net --ip=${SERVERS[0]} --cap-add=NET_ADMIN \ + --cpu-shares=1024 -m=512M -v ${DIR}:/mnt ghcr.io/xline-kv/etcdctl:v3.5.9 bash & wait echo container started } @@ -68,4 +52,3 @@ stop_all docker network create --subnet=172.20.0.0/24 xline_net >/dev/null 2>&1 run_container 3 -run_cluster diff --git a/scripts/start_xline.sh b/scripts/start_xline.sh new file mode 100755 index 000000000..41432889f --- /dev/null +++ b/scripts/start_xline.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +if [ -z "$HOSTNAME" ]; then + echo -e "Env HOSTNAME is not set" + exit 1 +fi + +if [ -z "$MEMBERS" ]; then + echo -e "Env MEMBERS is not set" + exit 1 +fi + +RUST_LOG="${RUST_LOG:-debug}" +ENGINE="${STORAGE_ENGINE:-rocksdb}" +DATA_DIR="${DATA_DIR:-/usr/local/xline/data-dir}" +PUBLIC_KEY="${PUBLIC_KEY:-/mnt/public.pem}" +PRIVATE_KEY="${PRIVATE_KEY:-/mnt/private.pem}" + +if [ -z "$IS_LEADER" ]; then + RUST_LOG=$RUST_LOG /usr/local/bin/xline \ + --name $HOSTNAME \ + --members $MEMBERS \ + --storage-engine rocksdb \ + --data-dir /usr/local/xline/data-dir \ + --auth-public-key /mnt/public.pem \ + --auth-private-key /mnt/private.pem +else + RUST_LOG=$RUST_LOG /usr/local/bin/xline \ + --name $HOSTNAME \ + --members $MEMBERS \ + --storage-engine rocksdb \ + --data-dir /usr/local/xline/data-dir \ + --auth-public-key /mnt/public.pem \ + --auth-private-key /mnt/private.pem \ + --is-leader +fi