diff --git a/.github/workflows/build_meta_image.yml b/.github/workflows/build_meta_image.yml new file mode 100644 index 00000000..6c800088 --- /dev/null +++ b/.github/workflows/build_meta_image.yml @@ -0,0 +1,49 @@ +name: build_meta_image + +on: + push: + paths: + - 'docker/Metafile' + - 'docker/Metafile.alpine' + - 'requirements.txt' + branches: + - "dev" + +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: Set Environment Variables + run: | + IMG=fulltclash + echo "IMG=${IMG}" >> $GITHUB_ENV + echo "IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/${IMG}" >> $GITHUB_ENV + - name: Build Debian Image + uses: docker/build-push-action@v5 + with: + context: . + file: ./docker/Metafile + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ${{ env.IMAGE }}:debian + - name: Build Alpine Image + uses: docker/build-push-action@v5 + with: + context: . + file: ./docker/Metafile.alpine + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ${{ env.IMAGE }}:alpine diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 0faaae40..a5215109 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -9,6 +9,7 @@ on: - ".github/ISSUE_TEMPLATE/**" branches: - "master" + - "dev" jobs: docker: @@ -20,19 +21,18 @@ jobs: uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Login to GitHub Container Registry + - name: Login to Docker Hub uses: docker/login-action@v3 with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Set Environment Variables run: | IMG=fulltclash - OWNER="$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')" echo "IMG=${IMG}" >> $GITHUB_ENV - echo "IMAGE=ghcr.io/${OWNER}/${IMG}" >> $GITHUB_ENV - - name: Build and push + echo "IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/${IMG}" >> $GITHUB_ENV + - name: Build Latest Image + if: ${{ github.ref_name == 'dev' }} uses: docker/build-push-action@v5 with: platforms: linux/amd64,linux/arm64 @@ -41,8 +41,20 @@ jobs: push: true tags: | ${{ env.IMAGE }}:latest - ${{ env.IMAGE }}:dev - - name: Build alpine Docker + ${{ env.IMAGE }}:debian-${{ github.ref_name }} + build-args: | + GIT_Branch=${{ github.ref_name }} + - name: Build Debian Image + if: ${{ github.ref_name != 'dev' }} + uses: docker/build-push-action@v5 + with: + platforms: linux/amd64,linux/arm64 + context: . + file: ./docker/Dockerfile + push: true + tags: | + ${{ env.IMAGE }}:debian-${{ github.ref_name }} + - name: Build Alpine Image uses: docker/build-push-action@v5 with: platforms: linux/amd64,linux/arm64 @@ -50,4 +62,6 @@ jobs: file: ./docker/Dockerfile.alpine push: true tags: | - ${{ env.IMAGE }}:alpine \ No newline at end of file + ${{ env.IMAGE }}:alpine-${{ github.ref_name }} + build-args: | + GIT_Branch=${{ github.ref_name }} diff --git a/docker/Dockerfile b/docker/Dockerfile index ca33048e..c66b93f3 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,18 +1,9 @@ -FROM python:3.11.7-slim-bookworm AS compile-image - -RUN apt-get update && \ - apt-get install --no-install-recommends -y \ - gcc g++ make ca-certificates - -RUN python -m venv /opt/venv - -ENV PATH="/opt/venv/bin:$PATH" -ADD https://raw.githubusercontent.com/AirportR/FullTclash/dev/requirements.txt . -RUN pip3 install --no-cache-dir -r requirements.txt && \ - pip3 install --no-cache-dir supervisor +FROM airportr/fulltclash:debian AS compile-image FROM python:3.11.7-slim-bookworm +ARG GIT_Branch +ENV GIT_Branch=$GIT_Branch ENV TZ=Asia/Shanghai ENV admin=12345678 ENV api_id=123456 @@ -30,7 +21,7 @@ WORKDIR /app RUN apt-get update && \ apt-get install --no-install-recommends -y \ git tzdata curl wget jq bash nano cron && \ - git clone -b dev --single-branch --depth=1 https://github.com/AirportR/FullTclash.git /app && \ + git clone -b $GIT_Branch --single-branch --depth=1 https://github.com/AirportR/FullTclash.git /app && \ git clone --single-branch --depth=1 https://github.com/twitter/twemoji.git /app/resources/emoji/twemoji && \ ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \ echo $TZ > /etc/timezone && \ diff --git a/docker/Dockerfile.alpine b/docker/Dockerfile.alpine index 40bcf2ba..c675206d 100644 --- a/docker/Dockerfile.alpine +++ b/docker/Dockerfile.alpine @@ -1,17 +1,9 @@ -FROM python:3.11.7-alpine3.19 AS compile-image - -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 . -RUN pip3 install --no-cache-dir -r requirements.txt && \ - pip3 install --no-cache-dir supervisor +FROM airportr/fulltclash:alpine AS compile-image FROM python:3.11.7-alpine3.19 +ARG GIT_Branch +ENV GIT_Branch=$GIT_Branch ENV TZ=Asia/Shanghai ENV admin=12345678 ENV api_id=123456 @@ -28,7 +20,7 @@ WORKDIR /app RUN apk add --no-cache \ git tzdata curl jq wget bash nano && \ - git clone -b dev --single-branch --depth=1 https://github.com/AirportR/FullTclash.git /app && \ + git clone -b $GIT_Branch --single-branch --depth=1 https://github.com/AirportR/FullTclash.git /app && \ git clone --single-branch --depth=1 https://github.com/twitter/twemoji.git /app/resources/emoji/twemoji && \ ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \ echo $TZ > /etc/timezone && \ diff --git a/docker/Metafile b/docker/Metafile new file mode 100644 index 00000000..fe36b482 --- /dev/null +++ b/docker/Metafile @@ -0,0 +1,19 @@ +FROM python:3.11.7-slim-bookworm AS compile-image + +RUN apt-get update && \ + apt-get install --no-install-recommends -y \ + gcc g++ make ca-certificates + +RUN python -m venv /opt/venv + +ENV PATH="/opt/venv/bin:$PATH" +ADD https://raw.githubusercontent.com/AirportR/FullTclash/dev/requirements.txt . +RUN pip3 install --no-cache-dir -r requirements.txt && \ + pip3 install --no-cache-dir supervisor + +FROM python:3.11.7-slim-bookworm + +COPY --from=compile-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=compile-image /opt/venv /opt/venv + +ENV PATH="/opt/venv/bin:$PATH" \ No newline at end of file diff --git a/docker/Metafile.alpine b/docker/Metafile.alpine new file mode 100644 index 00000000..9c2548eb --- /dev/null +++ b/docker/Metafile.alpine @@ -0,0 +1,18 @@ +FROM python:3.11.7-alpine3.19 AS compile-image + +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 . +RUN pip3 install --no-cache-dir -r requirements.txt && \ + pip3 install --no-cache-dir supervisor + +FROM python:3.11.7-alpine3.19 + +COPY --from=compile-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=compile-image /opt/venv /opt/venv + +ENV PATH="/opt/venv/bin:$PATH" \ No newline at end of file diff --git a/docker/README.md b/docker/README.md index 55233afb..28aaec1b 100644 --- a/docker/README.md +++ b/docker/README.md @@ -3,19 +3,25 @@ > 这能让你在Windows、Mac、Linux、openwrt、Nas几乎任何支持Docker(目前仅Amd64和Arm64)的环境下使用此项目! ## 创建配置文件 -新建配置文件保存目录`mkdir /etc/FullTclash` + +新建配置文件保存目录`mkdir /etc/fulltclash` 下载并编辑配置文件 + +```bash +wget -O /etc/fulltclash/config.yaml https://raw.githubusercontent.com/AirportR/FullTclash/dev/resources/config.yaml.example ``` -wget -O /etc/FullTclash/config.yaml https://raw.githubusercontent.com/AirportR/FullTclash/dev/resources/config.yaml.example -``` + 修改 config.yaml (path是必须修改的配置,不能使用默认的) -``` + +```bash clash: path: './bin/fulltclash-origin' branch: origin ``` + 或者 [Meta内核](https://github.com/AirportR/FullTCore/tree/meta) -``` + +```bash clash: path: './bin/fulltclash-meta' branch: meta @@ -23,15 +29,19 @@ clash: ## 部署 - ### 拉取镜像 -> 镜像可选dev或者alpine,dev是通过Debian构建的 - ```bash -docker pull ghcr.io/airportr/fulltclash:dev +docker pull airportr/fulltclash:latest ``` +镜像还可以选择以下标签,其中 `latest` 标签是基于 `debian` `dev分支`构建 + +- debian-dev +- alpine-dev +- debian-master +- alpine-master + ### docker #### 快速启动 @@ -49,12 +59,12 @@ docker run -idt \ -e core=4 \ -e startup=1124 \ -e speedthread=4 \ - -e nospeed=true \ + -e nospeed=false \ -e s5_proxy=127.0.0.1:7890 \ -e http_proxy=127.0.0.1:7890 \ --network=host \ --restart always \ - ghcr.io/airportr/fulltclash:dev + airportr/fulltclash:latest ``` #### 挂载配置文件启动(推荐) @@ -65,7 +75,7 @@ docker run -itd \ --network=host \ --restart=always \ -v /etc/fulltclash/config.yaml:/app/resources/config.yaml \ - ghcr.io/airportr/fulltclash:dev + airportr/fulltclash:latest ``` ### docker-compose(推荐) @@ -83,14 +93,29 @@ docker-compose down ``` 查看日志 -``` + +```bash docker exec -it fulltclash tail -f /var/log/fulltclash.log ``` + 更新版本 -``` + +```bash docker exec -it fulltclash bash /app/docker/update.sh ``` + 重启程序 -``` + +```bash docker exec -it fulltclash supervisorctl restart fulltclash -``` \ No newline at end of file +``` + +进入容器 + +```bash +docker exec -it fulltclash bash +``` + +退出容器 + +`root@deeb9eaf66aa:/app# exit` diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index ea162138..ae7ad7a1 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.9' services: fulltclash: - image: ghcr.io/airportr/fulltclash:dev + image: airportr/fulltclash:latest restart: always network_mode: host container_name: fulltclash diff --git a/docker/update.sh b/docker/update.sh index ad1bb4ab..9cd9c108 100644 --- a/docker/update.sh +++ b/docker/update.sh @@ -1,13 +1,31 @@ #!/bin/bash . /etc/profile +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) -last_version=$(curl -Ls "https://api.github.com/repos/AirportR/FullTclash/commits/dev" | jq .sha | sed -E 's/.*"([^"]+)".*/\1/') + +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 --git-dir='/app/.git' --work-tree='/app' fetch --all - git --git-dir='/app/.git' --work-tree='/app' reset --hard origin/dev + 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) } if [[ $last_version == "$git_version" ]]; then @@ -15,5 +33,6 @@ if [[ $last_version == "$git_version" ]]; then else echo -e "检查到新版本,正在更新" update + echo -e "更新完成,当前commits位于 $git_version" /opt/venv/bin/supervisorctl restart fulltclash fi \ No newline at end of file