name: Docker Build and Push on: push: branches: - '**' workflow_dispatch: jobs: check-secrets: runs-on: ubuntu-latest outputs: has_secrets: ${{ steps.check.outputs.has_secrets }} steps: - id: check run: | if [[ -n "${{ secrets.DOCKERHUB_USERNAME }}" && -n "${{ secrets.DOCKERHUB_TOKEN }}" ]]; then echo "has_secrets=true" >> $GITHUB_OUTPUT else echo "has_secrets=false" >> $GITHUB_OUTPUT echo "未设置 Docker Hub 凭据,将跳过整个 Action" fi build-and-push: needs: check-secrets if: needs.check-secrets.outputs.has_secrets == 'true' 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: Free disk space run: | sudo rm -rf /usr/share/dotnet /usr/local/lib/android df -h - 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: ${{ secrets.DOCKERHUB_USERNAME }}/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: ${{ secrets.DOCKERHUB_USERNAME }}/video-subtitle-remover