diff --git a/.github/workflows/docker-backend-image.yml b/.github/workflows/docker-backend-image.yml new file mode 100644 index 00000000..29fede82 --- /dev/null +++ b/.github/workflows/docker-backend-image.yml @@ -0,0 +1,33 @@ +name: docker-backend-image + +on: + push: + branches: + - "backend" + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + file: ./docker/Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ${{ secrets.DOCKERHUB_USERNAME }}/fulltclash:ws + build-args: | + GIT_Branch=${{ github.ref_name }} \ No newline at end of file diff --git a/README.md b/README.md index 73f8bc0c..28101135 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,19 @@ options: ```shell python3 main.py -t fulltclash -b 0.0.0.0:8765 -``` \ No newline at end of file +``` + +### Docker启动 +> Docker镜像是基于alpine构建的 + +```bash +docker run -idt \ + --name fulltclash-ws \ + -e branch=origin \ + -e core=4 \ + -e token=114514 \ + -e buildtoken=BUILDTOKEN \ + -p 8765:8765 \ + --restart always \ + airportr/fulltclash:ws +``` diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 00000000..b498fd49 --- /dev/null +++ b/bin/.gitkeep @@ -0,0 +1 @@ +/ diff --git a/bin/fulltclash-linux-amd64 b/bin/fulltclash-linux-amd64 deleted file mode 100644 index 636a9503..00000000 Binary files a/bin/fulltclash-linux-amd64 and /dev/null differ diff --git a/bin/fulltclash-macos-amd64 b/bin/fulltclash-macos-amd64 deleted file mode 100644 index 49c4ed9c..00000000 Binary files a/bin/fulltclash-macos-amd64 and /dev/null differ diff --git a/bin/fulltclash-windows-amd64.exe b/bin/fulltclash-windows-amd64.exe deleted file mode 100644 index c96d0d12..00000000 Binary files a/bin/fulltclash-windows-amd64.exe and /dev/null differ diff --git a/docker/Dockerfile b/docker/Dockerfile index 911c7659..20fd9d6c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,56 +1,44 @@ -FROM golang:1.20.7-bookworm AS build-core +FROM python:3.11.7-alpine3.19 AS compile-image -WORKDIR /app/fulltclash-origin -RUN apt-get update && \ - apt-get install --no-install-recommends -y \ - git && \ - git clone https://github.com/AirportR/FullTCore.git /app/fulltclash-origin && \ - go build -ldflags="-s -w" fulltclash.go - -WORKDIR /app/fulltclash-meta -RUN git clone -b meta https://github.com/AirportR/FullTCore.git /app/fulltclash-meta && \ - go build -tags with_gvisor -ldflags="-s -w" fulltclash.go && \ - mkdir /app/FullTCore-file && \ - cp /app/fulltclash-origin/fulltclash /app/FullTCore-file/fulltclash-origin && \ - cp /app/fulltclash-meta/fulltclash /app/FullTCore-file/fulltclash-meta - -FROM python:3.9.18-slim-bookworm AS compile-image - -RUN apt-get update && \ - apt-get install --no-install-recommends -y \ - gcc g++ make ca-certificates +RUN apk add --no-cache \ + gcc g++ make libffi-dev libstdc++ gcompat libgcc build-base py3-pybind11-dev abseil-cpp-dev re2-dev ca-certificates RUN python -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" -ADD https://raw.githubusercontent.com/AirportR/FullTclash/dev/requirements.txt . +ADD https://raw.githubusercontent.com/AirportR/FullTclash/backend/requirements.txt . RUN pip3 install --no-cache-dir -r requirements.txt && \ pip3 install --no-cache-dir supervisor -FROM python:3.9.18-slim-bookworm +FROM python:3.11.7-alpine3.19 + +ARG GIT_Branch +ENV GIT_Branch=$GIT_Branch +ENV TZ=Asia/Shanghai +ENV bind=0.0.0.0:8765 +ENV token=fulltclash +ENV branch=origin +ENV core=4 WORKDIR /app -RUN apt-get update && \ - apt-get install --no-install-recommends -y \ - git tzdata curl jq bash nano cron && \ - git clone -b dev --single-branch --depth=1 https://github.com/AirportR/FullTclash.git /app && \ - cp resources/config.yaml.example resources/config.yaml && \ - rm -f /etc/localtime && \ - cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ - echo "Asia/Shanghai" > /etc/timezone && \ +RUN apk add --no-cache \ + git tzdata curl jq wget bash nano && \ + git clone -b $GIT_Branch --single-branch --depth=1 https://github.com/AirportR/FullTclash.git /app && \ + ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \ + echo $TZ > /etc/timezone && \ echo "00 6 * * * bash /app/docker/update.sh" >> /var/spool/cron/crontabs/root && \ mkdir /etc/supervisord.d && \ mv /app/docker/supervisord.conf /etc/supervisord.conf && \ mv /app/docker/fulltclash.conf /etc/supervisord.d/fulltclash.conf && \ - chmod +x /app/docker/docker-entrypoint.sh && \ - rm -rf /var/lib/apt/lists/* && \ - rm -f /app/bin/* + chmod +x /app/docker/fulltcore.sh && \ + bash /app/docker/fulltcore.sh && \ + chmod +x /app/docker/update.sh && \ + chmod +x /app/docker/docker-entrypoint.sh COPY --from=compile-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=compile-image /opt/venv /opt/venv -COPY --from=build-core /app/FullTCore-file/* ./bin/ ENV PATH="/opt/venv/bin:$PATH" -ENTRYPOINT ["/app/docker/docker-entrypoint.sh"] +ENTRYPOINT ["/app/docker/docker-entrypoint.sh"] \ No newline at end of file diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 32c3cfce..07d85b8c 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -1,5 +1,22 @@ #!/bin/bash +if [[ ! -f /app/resources/config.yaml ]]; then +cat > /app/resources/config.yaml <> /app/resources/config.yaml +fi + supervisord -c /etc/supervisord.conf -cron -f > /dev/null 2>&1 \ No newline at end of file +crond -f > /dev/null 2>&1 \ No newline at end of file diff --git a/docker/fulltclash.conf b/docker/fulltclash.conf index c5a86a47..fdd34912 100644 --- a/docker/fulltclash.conf +++ b/docker/fulltclash.conf @@ -1,4 +1,5 @@ [program:fulltclash] -command=python3 /app/main.py +command=python3 -u /app/main.py directory=/app +redirect_stderr=true stdout_logfile=/var/log/fulltclash.log \ No newline at end of file diff --git a/docker/fulltcore.sh b/docker/fulltcore.sh new file mode 100644 index 00000000..91700815 --- /dev/null +++ b/docker/fulltcore.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +rm -f /app/bin/* + +ORIGIN_AMD64_URL=https://github.com/AirportR/FullTCore/releases/download/v1.0/FullTCore_1.0_linux_amd64.tar.gz +META_AMD64_URL=https://github.com/AirportR/FullTCore/releases/download/v1.1-meta/FullTCore_1.1-meta_linux_amd64.tar.gz +ORIGIN_ARM64_URL=https://github.com/AirportR/FullTCore/releases/download/v1.0/FullTCore_1.0_linux_arm64.tar.gz +META_ARM64_URL=https://github.com/AirportR/FullTCore/releases/download/v1.1-meta/FullTCore_1.1-meta_linux_arm64.tar.gz + +arch=$(arch) + +if [[ $arch == "x86_64" || $arch == "x64" || $arch == "amd64" ]]; then + arch="amd64" + wget -O /app/bin/FullTCore_origin.tar.gz ${ORIGIN_AMD64_URL} > /dev/null 2>&1 + wget -O /app/bin/FullTCore_meta.tar.gz ${META_AMD64_URL} > /dev/null 2>&1 +elif [[ $arch == "aarch64" || $arch == "arm64" ]]; then + arch="arm64" + wget -O /app/bin/FullTCore_origin.tar.gz ${ORIGIN_ARM64_URL} > /dev/null 2>&1 + wget -O /app/bin/FullTCore_meta.tar.gz ${META_ARM64_URL} > /dev/null 2>&1 +fi + +tar -C /app/bin/ -xvzf /app/bin/FullTCore_origin.tar.gz +mv /app/bin/FullTCore /app/bin/fulltclash-origin + +tar -C /app/bin/ -xvzf /app/bin/FullTCore_meta.tar.gz +mv /app/bin/FullTCore /app/bin/fulltclash-meta + +find /app/bin/* | egrep -v "fulltclash-origin|fulltclash-meta" | xargs rm -f + +chmod +x /app/bin/fulltclash-origin +chmod +x /app/bin/fulltclash-meta + +echo "架构: ${arch}下载FullTCore完成" \ No newline at end of file diff --git a/docker/update.sh b/docker/update.sh index fe097d21..9cd9c108 100644 --- a/docker/update.sh +++ b/docker/update.sh @@ -1,20 +1,38 @@ #!/bin/bash +. /etc/profile -git_version=$(git rev-parse HEAD) -last_version=$(curl -Ls "https://api.github.com/repos/AirportR/FullTclash/commits/dev" | jq .sha | sed -E 's/.*"([^"]+)".*/\1/') +git_branch=$(git --git-dir='/app/.git' --work-tree='/app' rev-parse --abbrev-ref HEAD) +git_version=$(git --git-dir='/app/.git' --work-tree='/app' rev-parse HEAD) + +if [[ master == "$git_branch" ]]; then + echo -e "当前分支为 $git_branch" + echo -e "当前commits位于 $git_version" + last_version=$(curl -Ls "https://api.github.com/repos/AirportR/FullTclash/commits/master" | jq .sha | sed -E 's/.*"([^"]+)".*/\1/') +elif [[ dev == "$git_branch" ]]; then + echo -e "当前分支为 $git_branch" + echo -e "当前commits位于 $git_version" + last_version=$(curl -Ls "https://api.github.com/repos/AirportR/FullTclash/commits/dev" | jq .sha | sed -E 's/.*"([^"]+)".*/\1/') +elif [[ backend == "$git_branch" ]]; then + echo -e "当前分支为 $git_branch" + echo -e "当前commits位于 $git_version" + last_version=$(curl -Ls "https://api.github.com/repos/AirportR/FullTclash/commits/backend" | jq .sha | sed -E 's/.*"([^"]+)".*/\1/') +else + echo -e "暂不支持此分支" + exit 1 +fi update() { - git fetch --all - git reset --hard origin/dev - git pull + git --git-dir='/app/.git' --work-tree='/app' fetch --all + git --git-dir='/app/.git' --work-tree='/app' reset --hard origin/$git_branch + git --git-dir='/app/.git' --work-tree='/app' pull + git_version=$(git --git-dir='/app/.git' --work-tree='/app' rev-parse HEAD) } -cd /app - -if [[ $last_version == $git_version ]]; then +if [[ $last_version == "$git_version" ]]; then echo -e "已是最新版本,无需更新" else echo -e "检查到新版本,正在更新" update - supervisorctl restart fulltclash + echo -e "更新完成,当前commits位于 $git_version" + /opt/venv/bin/supervisorctl restart fulltclash fi \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 6ea835b4..28f11882 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,4 @@ geoip2==4.6.0 cryptography==40.0.2 PySocks==1.7.1 lxml==4.9.2 -google-re2 \ No newline at end of file +google-re2==1.0 \ No newline at end of file