From c8d4ce75a4e19fe701ffd9cd3bc573fe72f08c4d Mon Sep 17 00:00:00 2001 From: Cailiang Liu Date: Sun, 20 Aug 2023 23:18:45 +0800 Subject: [PATCH] support multi planet in deployment --- Dockerfile | 12 ++++++++---- deploy.sh | 10 +++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 42a8676..8c4a3d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/re && apk update\ && mkdir -p /usr/include/nlohmann/ && cd /usr/include/nlohmann/ && wget https://ghself.markxu.online/https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp \ && apk add --no-cache git python3 npm make g++ zerotier-one linux-headers\ - && mkdir /app -p && cd /app && git clone --progress https://ghself.markxu.online/https://github.com/key-networks/ztncui.git\ + && mkdir /app /var/lib -p && cd /app && git clone --progress https://ghself.markxu.online/https://github.com/key-networks/ztncui.git\ && cd /app/ztncui/src \ && cp /app/patch/binding.gyp .\ && echo "开始配置npm环境"\ @@ -22,13 +22,17 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/re && echo 'HTTP_ALL_INTERFACES=true' >>.env \ && echo "ZT_ADDR=localhost:${ZT_PORT}" >>.env\ && echo "${ZT_PORT}" >/app/zerotier-one.port \ - && cp -v etc/default.passwd etc/passwd + && cp -v etc/default.passwd etc/passwd +#ADD ./pztier/zerotier-one* /var/lib/ +RUN cp -r /app/pztier/zerotier-one /var/lib/ || true + +#RUN ls -al /var/lib/ /var/lib/zerotier-one/ |grep -v zerotier && sleep 20 RUN cd /app && git clone --progress https://ghself.markxu.online/https://github.com/zerotier/ZeroTierOne.git --depth 1\ && zerotier-one -d && sleep 5s && ps -ef |grep zerotier-one |grep -v grep |awk '{print $1}' |xargs kill -9 \ - && cd /var/lib/zerotier-one && zerotier-idtool initmoon identity.public >moon.json\ + && cd /var/lib/zerotier-one && ( [ -f ./moon.json ] || zerotier-idtool initmoon identity.public >moon.json ) \ && cd /app/patch && python3 patch.py \ - && cd /var/lib/zerotier-one && zerotier-idtool genmoon moon.json && mkdir moons.d && cp ./*.moon ./moons.d \ + && cd /var/lib/zerotier-one && zerotier-idtool genmoon moon.json && mkdir -p moons.d && cp ./*.moon ./moons.d \ && cd /app/ZeroTierOne/attic/world/ && sh build.sh \ && sleep 5s \ && cd /app/ZeroTierOne/attic/world/ && ./mkworld \ diff --git a/deploy.sh b/deploy.sh index d7f5b58..c4e1739 100755 --- a/deploy.sh +++ b/deploy.sh @@ -37,10 +37,11 @@ function install() { if [[ -n "$ipv6" ]]; then ipv6_entry="${ipv6}/${port}" endpoints="[\"$ipv4_entry\",\"$ipv6_entry\"]" - else + echo "[{\"stableEndpoints\":$endpoints}]" > ./patch/patch.json + elif [[ -n "$ipv4" ]]; then endpoints="[\"$ipv4_entry\"]" + echo "[{\"stableEndpoints\":$endpoints}]" > ./patch/patch.json fi - echo "{\"stableEndpoints\":$endpoints}" > ./patch/patch.json echo "配置内容为:" echo "`cat ./patch/patch.json`" @@ -92,9 +93,12 @@ case "$choice" in 1) echo "您选择了安装功能" install + docker cp zerotier-planet:/var/lib/zerotier-one/ ./pztier/ ;; 2) echo "您选择了更新功能" + [ -f ./pztier/zerotier-one/moon.json ] && docker cp ./pztier/zerotier-one/moon.json zerotier-planet:/var/lib/zerotier-one/moon.json + [ -f ./pztier/zerotier-one/planet ] && docker cp ./pztier/zerotier-one/planet zerotier-planet:/var/lib/zerotier-one/planet upgrade ;; 3) @@ -102,7 +106,7 @@ case "$choice" in docker cp zerotier-planet:/app/bin/planet . ;; *) - echo "谢谢使用!" + echo "多planet:各planet执行完1之后,将各planet的stableendpoint合并到moon.json中,编辑好patch.json,planet0上重新执行1,将moon.json planet放到其他各planet中,重新执行2.谢谢使用!" exit 0 ;; esac