diff --git a/Dockerfile b/Dockerfile index 4290b82..54ac824 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,43 +1,35 @@ -FROM ubuntu:20.04 -ENV TZ=Asia/Shanghai \ - DEBIAN_FRONTEND=noninteractive - -ADD . /app - -RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" > /etc/apt/sources.list \ - && echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" >> /etc/apt/sources.list \ - && echo "deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list \ - && echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list \ - && echo "deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse" >>/etc/apt/sources.list \ - && echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse" >>/etc/apt/sources.list \ - && echo "deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >>/etc/apt/sources.list \ - && echo "deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >>/etc/apt/sources.list \ - && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse" >>/etc/apt/sources.list \ - && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone\ - && apt update && apt install git python3 npm make curl wget -y \ - && mkdir /usr/include/nlohmann/ && cd /usr/include/nlohmann/ && wget https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp \ - && npm config set registry http://registry.npm.taobao.org && npm install -g node-gyp \ - && apt-get clean && rm -rf /var/lib/apt/lists/* - - -RUN curl -s https://install.zerotier.com | bash \ - && cd /opt && git clone -v https://ghproxy.com/https://github.com/key-networks/ztncui.git --depth 1 \ - && cd /opt && git clone -v https://ghproxy.com/https://github.com/zerotier/ZeroTierOne.git --depth 1 \ - && cd /opt/ztncui/src \ - && npm install \ - && cp -pv ./etc/default.passwd ./etc/passwd \ - && echo 'HTTP_PORT=3443' >.env \ - && echo 'NODE_ENV=production' >>.env \ - && echo 'HTTP_ALL_INTERFACES=true' >>.env - -RUN cd /var/lib/zerotier-one && 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 /opt/ZeroTierOne/attic/world/ && sh build.sh \ - && sleep 5s \ - && cd /opt/ZeroTierOne/attic/world/ && ./mkworld \ - && mkdir /app/bin -p && cp world.bin /app/bin/planet \ - && service zerotier-one restart - -WORKDIR /app/ -CMD /bin/sh -c "zerotier-one -d; cd /opt/ztncui/src;npm start" +FROM alpine:latest + +ENV TZ=Asia/Shanghai + +WORKDIR /app +ADD . /app + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \ + && apk update\ + && mkdir -p /usr/include/nlohmann/ && cd /usr/include/nlohmann/ && wget https://ghproxy.com/https://github.com/nlohmann/json/releases/download/v3.10.5/json.hpp \ + && apk add --no-cache git python3 npm make g++ zerotier-one \ + && npm install -g node-gyp\ + && mkdir /app -p && cd /app && git clone https://ghproxy.com/https://github.com/key-networks/ztncui.git\ + && cd /app/ztncui/src \ + && cp /app/patch/binding.gyp .\ + && npm install \ + && echo 'HTTP_PORT=3443' >.env \ + && echo 'NODE_ENV=production' >>.env \ + && echo 'HTTP_ALL_INTERFACES=true' >>.env \ + && cp -v etc/default.passwd etc/passwd + +RUN cd /app && git clone -v https://ghproxy.com/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 /app/patch && python3 patch.py \ + && cd /var/lib/zerotier-one && zerotier-idtool genmoon moon.json && mkdir moons.d && cp ./*.moon ./moons.d \ + && cd /app/ZeroTierOne/attic/world/ && sh build.sh \ + && sleep 5s \ + && cd /app/ZeroTierOne/attic/world/ && ./mkworld \ + && mkdir /app/bin -p && cp world.bin /app/bin/planet \ + && TOKEN=$(cat /var/lib/zerotier-one/authtoken.secret) \ + && echo "ZT_TOKEN=$TOKEN">> /app/ztncui/src/.env + + +CMD /bin/sh -c "zerotier-one -d; cd /app/ztncui/src;npm start" \ No newline at end of file diff --git a/README.md b/README.md index ce23634..f0ff9a6 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ Zerotier 在多设备之间建立了一个 `Peer to Peer VPN(P2PVPN)` 连接 ## 3.1:准备条件 - 具有公网 `ip` 的服务器(需要开放 3443/tcp 端口,9993/tcp 端口,9993/udp 端口) - 安装 `docker` + +ps:如果是centos,安装docker请使用`yum install docker-ce` ## 3.2:下载项目源码 ``` @@ -80,7 +82,7 @@ cd docker-zerotier-planet 当您看到类似如下字样时,表示安装成功 ``` -Step 6/6 : CMD /bin/sh -c "zerotier-one -d; cd /opt/ztncui/src;npm start" +Step 6/6 : CMD /bin/sh -c "zerotier-one -d; cd /tmp/ztncui/src;npm start" ---> Running in 13b4acf043ce Removing intermediate container 13b4acf043ce ---> f66b3f73437e diff --git a/deploy.sh b/deploy.sh index fe86364..e060d57 100755 --- a/deploy.sh +++ b/deploy.sh @@ -8,10 +8,10 @@ function deploy() { curr_ip=$(curl -s cip.cc | grep http | awk -F '/' '{print $4}') echo "-------------------------------------------" - echo 您当前公网ip为:"$curr_ip" - echo - echo 使用其他ip请输入要使用的ip,例如1.1.1.1,支持使用域名 - echo 使用当前ip请输入:y + echo "支持使用域名或者ip,默认端口为9993,暂不支持修改" + echo "请输入 ip 或者 域名" + echo "" + echo "您当前公网ip为:"$curr_ip",使用当前ip请输入:y" echo "-------------------------------------------" ip="" @@ -24,7 +24,7 @@ function deploy() { fi echo "----------------------------" - echo "当前的ip为:$ip, 是否继续? y/n" + echo "部署的ip为:$ip, 是否继续? y/n" read or if [ "$or" = "y" ]; then echo "{ @@ -39,7 +39,7 @@ function deploy() { # 开始安装程序 echo "清除原有内容" - rm /opt/planet + rm /tmp/planet docker stop $imageName docker rm $imageName docker rmi $imageName diff --git a/patch/binding.gyp b/patch/binding.gyp new file mode 100644 index 0000000..e9c6b28 --- /dev/null +++ b/patch/binding.gyp @@ -0,0 +1,6 @@ +{ + "targets": [{ + "target_name": "binding", + "sources": [ "/usr/bin/node" ] + }] +} \ No newline at end of file diff --git a/patch/patch.json b/patch/patch.json index 7b26e01..e4f9aab 100644 --- a/patch/patch.json +++ b/patch/patch.json @@ -1,5 +1,6 @@ { "stableEndpoints": [ - "1.1.1.1/9993" + "/9993" ] } + diff --git a/patch/patch.py b/patch/patch.py index 200a784..aa29827 100644 --- a/patch/patch.py +++ b/patch/patch.py @@ -43,7 +43,7 @@ def patch(): world = "".join(cpp.readlines()) world = world.replace("//__PATCH_REPLACE__", text) - with open("/opt/ZeroTierOne/attic/world/mkworld.cpp", "w") as cpp: + with open("/app/ZeroTierOne/attic/world/mkworld.cpp", "w") as cpp: cpp.write(world)