Skip to content

Commit

Permalink
build: modify the dockerfile and bootup logic
Browse files Browse the repository at this point in the history
Signed-off-by: Phoeniix Zhao <[email protected]>
  • Loading branch information
Phoenix500526 committed Dec 1, 2023
1 parent 844fc53 commit a514acf
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 36 deletions.
6 changes: 4 additions & 2 deletions doc/quick-start/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand All @@ -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"]
4 changes: 3 additions & 1 deletion scripts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
49 changes: 16 additions & 33 deletions scripts/quick_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
36 changes: 36 additions & 0 deletions scripts/start_xline.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a514acf

Please sign in to comment.