From ea7e01e3aa3dd075394eba6dcaf3d27f531742c4 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 24 Apr 2025 21:43:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83docker=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-docker.yml | 87 ++++++++++++++++++++++++++++++ README.md | 15 ++++++ docker/Dockerfile | 30 +++++++++++ 3 files changed, 132 insertions(+) create mode 100644 .github/workflows/build-docker.yml create mode 100644 docker/Dockerfile diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 0000000..851d9d9 --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,87 @@ +name: Docker Build and Push + +on: + push: + branches: + - '**' + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - type: cuda + version: "11.8" + - type: cuda + version: "12.6" + - type: cuda + version: "12.8" + - type: directml + version: "latest" + + steps: + + - name: Show system + run: | + echo -e "Total CPU cores\t: $(nproc)" + cat /proc/cpuinfo | grep 'model name' + ulimit -a + + - name: Maximize build space + uses: easimon/maximize-build-space@master + with: + swap-size-mb: 512 + temp-reserve-mb: 1024 + root-reserve-mb: 2048 + remove-dotnet: 'true' + remove-android: 'true' + remove-haskell: 'true' + remove-codeql: 'true' + + - name: 检出代码 + uses: actions/checkout@v4 + + - name: 读取 VERSION + id: version + run: | + VERSION=$(sed -n 's/^VERSION = "\(.*\)"/\1/p' backend/config.py) + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + shell: bash + + - name: 设置 Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: 登录到 Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: 提取元数据 + id: meta + uses: docker/metadata-action@v4 + with: + images: eritpchy/video-subtitle-remover + tags: | + type=raw,value=${{ env.VERSION }}-${{ matrix.type }}${{ matrix.type == 'cuda' && matrix.version || '' }} + + - name: 构建并推送 + uses: docker/build-push-action@v6 + with: + context: . + file: ./docker/Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + build-args: | + ${{ matrix.type == 'cuda' && format('CUDA_VERSION={0}', matrix.version) || '' }} + ${{ matrix.type == 'directml' && 'USE_DIRECTML=1' || '' }} + + - name: Docker Hub Description + uses: peter-evans/dockerhub-description@v4 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: eritpchy/video-subtitle-remover \ No newline at end of file diff --git a/README.md b/README.md index 28af760..f7db5a1 100755 --- a/README.md +++ b/README.md @@ -31,6 +31,21 @@ Windows GPU版本v1.1.0(GPU): > 仅供具有Nvidia显卡的用户使用(AMD的显卡不行) +**Docker版本:** +```shell + # Nvidia 10 20 30系显卡 + docker run -it --rm --gpus all eritpchy/video-subtitle-remover:1.1.1-cuda11.8 + + # Nvidia 40系显卡 + docker run -it --rm --gpus all eritpchy/video-subtitle-remover:1.1.1-cuda12.6 + + # Nvidia 50系显卡 + docker run -it --rm --gpus all eritpchy/video-subtitle-remover:1.1.1-cuda12.8 + + # AMD / Intel 独显 集显 + docker run -it --rm --gpus all eritpchy/video-subtitle-remover:1.1.1-directml +``` + ## 演示 - GUI版: diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..655fa37 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,30 @@ +FROM python:3.12 + +RUN --mount=type=cache,target=/root/.cache,sharing=private \ + apt update && \ + apt install -y libgl1-mesa-glx && \ + true + +ADD . /vsr +ARG CUDA_VERSION=11.8 +ARG USE_DIRECTML=0 + +# 如果是 CUDA 版本,执行 CUDA 特定设置 +RUN --mount=type=cache,target=/root/.cache,sharing=private \ + if [ "${USE_DIRECTML:-0}" != "1" ]; then \ + pip install paddlepaddle==3.0 && \ + pip install torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu$(echo ${CUDA_VERSION} | tr -d '.') && \ + pip install -r /vsr/requirements.txt; \ + fi + +# 如果是 DirectML 版本,执行 DirectML 特定设置 +RUN --mount=type=cache,target=/root/.cache,sharing=private \ + if [ "${USE_DIRECTML:-0}" = "1" ]; then \ + pip install paddlepaddle==3.0 && \ + pip install torch_directml==0.2.5.dev240914 && \ + pip install -r /vsr/requirements.txt; \ + fi + +ENV LD_LIBRARY_PATH=/usr/local/lib/python3.12/site-packages/nvidia/cudnn/lib/ +WORKDIR /vsr +CMD ["python", "/vsr/backend/main.py"] \ No newline at end of file