diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 31b349f..0000000 --- a/Dockerfile +++ /dev/null @@ -1,49 +0,0 @@ -# web -FROM node:16.17.1-alpine3.15 as builder_node -WORKDIR /web -COPY ./web /web -RUN yarn install \ - && yarn run build \ - && ls /web/ui - -# server -FROM golang:1.18-alpine as builder_golang -#TODO 本地打包时使用镜像 -ENV GOPROXY=https://goproxy.io -ENV GOOS=linux -WORKDIR /anylink -COPY . /anylink -COPY --from=builder_node /web/ui /anylink/server/ui - -#TODO 本地打包时使用镜像 -RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories -RUN apk add --no-cache git gcc musl-dev -RUN cd /anylink/server;go mod tidy;go build -o anylink -ldflags "-X main.CommitId=$(git rev-parse HEAD)" \ - && /anylink/server/anylink tool -v - -# anylink -FROM alpine -LABEL maintainer="github.com/bjdgyc" - -ENV IPV4_CIDR="192.168.10.0/24" - -WORKDIR /app -COPY --from=builder_golang /anylink/server/anylink /app/ -COPY docker_entrypoint.sh /app/ - -COPY ./server/bridge-init.sh /app/ -COPY ./server/conf /app/conf -COPY ./LICENSE /app/LICENSE - - -#TODO 本地打包时使用镜像 -RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories -RUN apk add --no-cache bash iptables \ - && chmod +x /app/docker_entrypoint.sh \ - && ls /app - -EXPOSE 443 8800 - -#CMD ["/app/anylink"] -ENTRYPOINT ["/app/docker_entrypoint.sh"] - diff --git a/build_docker.sh b/build_docker.sh index fad70ff..ec94d0f 100644 --- a/build_docker.sh +++ b/build_docker.sh @@ -5,7 +5,8 @@ echo $ver #docker login -u bjdgyc -docker build -t bjdgyc/anylink . +#docker build -t bjdgyc/anylink . +docker build -t bjdgyc/anylink -f docker/Dockerfile . docker tag bjdgyc/anylink:latest bjdgyc/anylink:$ver diff --git a/docker/docker_entrypoint.sh b/docker/docker_entrypoint.sh index 1ddfe54..ea23118 100644 --- a/docker/docker_entrypoint.sh +++ b/docker/docker_entrypoint.sh @@ -1,41 +1,23 @@ #!/bin/sh -USER="admin" -MM=$(pwgen -1s) -CREATE_USER=1 -CONFIG_FILE='/app/conf/server.toml' +var1=$1 -if [ $CREATE_USER -eq 1 ]; then - if [ ! -e $CREATE_USER ]; then - MM=$(pwgen -1s) - touch $CREATE_USER - bash /app/generate-certs.sh - cd /app/conf/ && cp *.crt /usr/local/share/ca-certificates/ - update-ca-certificates --fresh - userpass=$(/app/anylink -passwd "${MM}"| cut -d : -f2) - echo "${userpass}" - jwttoken=$(/app/anylink -secret | cut -d : -f2) - echo "-- First container startup --user:${USER} pwd:${MM}" - sed -i "s/admin/${USER}/g" /app/server-example.toml - sed -i "s/123456/${MM}/g" /app/server-example.toml - sed -i "s#usertoken#${userpass}#g" /app/server-example.toml - sed -i "s/jwttoken/${jwttoken}/g" /app/server-example.toml - else - echo "-- Not first container startup --" - fi +#set -x -else - echo "user switch not create" +case $var1 in +"bash" | "sh") + echo $var1 + exec "$@" + ;; -fi +"tool") + /app/anylink "$@" + ;; -if [ ! -f $CONFIG_FILE ]; then -echo "#####Generating configuration file#####" -cp /app/server-example.toml /app/conf/server.toml -else - echo "#####Configuration file already exists#####" -fi +*) + sysctl -w net.ipv4.ip_forward=1 + iptables -t nat -A POSTROUTING -s "${IPV4_CIDR}" -o eth0+ -j MASQUERADE + iptables -nL -t nat -rtaddr=$(grep "cidr" /app/conf/server.toml |awk -F \" '{print $2}') -sysctl -w net.ipv4.ip_forward=1 -iptables -t nat -A POSTROUTING -s "${rtaddr}" -o eth0+ -j MASQUERADE -/app/anylink -conf="/app/conf/server.toml" + exec /app/anylink "$@" + ;; +esac diff --git a/docker/docker_entrypoint_fix.sh b/docker/docker_entrypoint_fix.sh deleted file mode 100644 index 7ddf805..0000000 --- a/docker/docker_entrypoint_fix.sh +++ /dev/null @@ -1,37 +0,0 @@ -#! /bin/bash -version=(`wget -qO- -t1 -T2 "https://api.github.com/repos/bjdgyc/anylink/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g'`) -count=(`ls anylink | wc -w `) -wget https://github.com/bjdgyc/anylink/releases/download/${version}/anylink-deploy.tar.gz -tar xf anylink-deploy.tar.gz -rm -rf anylink-deploy.tar.gz -if [ ${count} -eq 0 ]; then - echo "init anylink" - mv anylink-deploy/* anylink/ -else - if [ ! -d "/anylink/log" ]; then - mv anylink-deploy/log anylink/ - fi - if [ ! -d "/anylink/conf" ]; then - mv anylink-deploy/conf anylink/ - fi - echo "update anylink" - rm -rf anylink/ui anylink/anylink anylink/files - mv anylink-deploy/ui anylink/ - mv anylink-deploy/anylink anylink/ - mv anylink-deploy/files anylink/ -fi -rm -rf anylink-deploy -sysctl -w net.ipv4.ip_forward=1 -if [[ ${mode} == pro ]];then - iptables -t nat -A POSTROUTING -s ${iproute} -o eth0 -j MASQUERADE - iptables -L -n -t nat - /anylink/anylink -conf=/anylink/conf/server.toml -elif [[ ${mode} == password ]];then - if [ -z ${password} ];then - echo "invalid password" - else - /anylink/anylink -passwd ${password} - fi -elif [[ ${mode} -eq jwt ]];then - /anylink/anylink -secret -fi \ No newline at end of file diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh deleted file mode 100644 index ea23118..0000000 --- a/docker_entrypoint.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -var1=$1 - -#set -x - -case $var1 in -"bash" | "sh") - echo $var1 - exec "$@" - ;; - -"tool") - /app/anylink "$@" - ;; - -*) - sysctl -w net.ipv4.ip_forward=1 - iptables -t nat -A POSTROUTING -s "${IPV4_CIDR}" -o eth0+ -j MASQUERADE - iptables -nL -t nat - - exec /app/anylink "$@" - ;; -esac