瀏覽代碼

新增lite镜像 (#408)

devome 3 年之前
父節點
當前提交
e1c615102f

+ 2 - 2
.github/workflows/build-base-image.yml

@@ -1,4 +1,4 @@
-name: 构建镜像:chinesesubfinder-base
+name: 构建base镜像
 on:
   workflow_dispatch:
 
@@ -31,7 +31,7 @@ jobs:
         uses: docker/build-push-action@v3
         with:
           context: docker
-          file: docker/base.Dockerfile
+          file: docker/full-base.Dockerfile
           platforms: |
             linux/amd64
             linux/arm64

+ 83 - 0
.github/workflows/build-lite-image.yml

@@ -0,0 +1,83 @@
+name: 构建lite镜像
+on:
+  push:
+    tags:
+      - v*.*.*
+      - v*.*-Beta*
+      - v*.*-ExeBeta*
+  workflow_dispatch:
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    if: "!contains(github.ref, 'ExeBeta')"
+    name: 构建lite镜像
+    steps:
+      - 
+        name: Checkout
+        uses: actions/checkout@master
+      
+      -
+        name: Prepare
+        id: prepare
+        run: |
+          echo "::set-output name=version::${GITHUB_REF:10}"
+          echo "version=${GITHUB_REF:10}"
+
+      - 
+        name: Set Up QEMU
+        uses: docker/setup-qemu-action@v2
+
+      - 
+        name: Set Up Buildx
+        uses: docker/setup-buildx-action@v2
+
+      - 
+        name: Login DockerHub
+        uses: docker/login-action@v2
+        with:
+          username: ${{ secrets.DOCKER_USERNAME }}
+          password: ${{ secrets.DOCKER_PASSWORD }}
+
+      -
+        name: Go Build
+        working-directory: docker
+        run: |
+          docker run --rm -e VERSION=${{ steps.prepare.outputs.version }} -v $(pwd)/go:/root/go -v $(pwd)/lite-init.sh:/init.sh --entrypoint "/init.sh" nevinee/csf-cross-builder
+
+      - 
+        name: Docker Buildx Latest Image
+        if: "!contains(steps.prepare.outputs.version, 'Beta')"
+        uses: docker/build-push-action@v3
+        with:
+          context: docker
+          file: docker/lite-release.Dockerfile
+          platforms: |
+            linux/386
+            linux/amd64
+            linux/arm64
+            linux/arm/v7
+          push: true
+          build-args: |
+            VERSION=${{ steps.prepare.outputs.version }}
+          tags: |
+            ${{ secrets.DOCKER_USERNAME }}/chinesesubfinder:${{ steps.prepare.outputs.version }}-lite
+            ${{ secrets.DOCKER_USERNAME }}/chinesesubfinder:latest-lite
+
+      - 
+        name: Docker Buildx Beta Image
+        if: contains(steps.prepare.outputs.version, 'Beta')
+        uses: docker/build-push-action@v3
+        with:
+          context: docker
+          file: docker/lite-release.Dockerfile
+          platforms: |
+            linux/386
+            linux/amd64
+            linux/arm64
+            linux/arm/v7
+          push: true
+          build-args: |
+            VERSION=${{ steps.prepare.outputs.version }}
+          tags: |
+            ${{ secrets.DOCKER_USERNAME }}/chinesesubfinder:${{ steps.prepare.outputs.version }}-lite

+ 1 - 1
.github/workflows/build_chrome_checker.yml

@@ -1,4 +1,4 @@
-name: release
+name: 编译ChromeChecker
 
 on:
   push:

+ 0 - 38
.github/workflows/manual_test.yml

@@ -1,38 +0,0 @@
-name: Dev Manual Build Docker
-
-on:
-  workflow_dispatch:
-
-jobs:
-  buildx:
-    runs-on: ubuntu-latest
-    steps:
-      - name: Checkout
-        uses: actions/checkout@v2
-        with:
-          ref: dev
-
-      # Docker Image 构建环境
-      - name: Set up QEMU
-        uses: docker/setup-qemu-action@v1
-
-      - name: Set up Docker Buildx
-        uses: docker/setup-buildx-action@v1
-
-      - name: Login to DockerHub
-        uses: docker/login-action@v1
-        with:
-          username: ${{ secrets.DOCKER_USERNAME }}
-          password: ${{ secrets.DOCKER_PASSWORD }}
-
-      # Build and push
-      - name: Build dockerfile
-        uses: docker/build-push-action@v2
-        with:
-          file: ./Dockerfile
-          platforms: linux/amd64
-          push: true
-          tags: |
-            allanpk716/chinesesubfinder:dev1014b05
-          build-args: |
-            VERSION=dev1014b05

+ 3 - 3
.github/workflows/release.yml

@@ -22,7 +22,7 @@ jobs:
         with:
           working-directory: frontend
 
-      - name: frontend build
+      - name: Frontend Build
         run: npm run build
         working-directory: frontend
 
@@ -76,7 +76,7 @@ jobs:
         uses: docker/build-push-action@v3
         with:
           context: docker
-          file: docker/Dockerfile
+          file: docker/full-release.Dockerfile
           platforms: linux/amd64,linux/arm64,linux/arm/v7
           push: true
           tags: |
@@ -91,7 +91,7 @@ jobs:
         uses: docker/build-push-action@v3
         with:
           context: docker
-          file: docker/Dockerfile
+          file: docker/full-release.Dockerfile
           platforms: linux/amd64,linux/arm64,linux/arm/v7
           push: true
           tags: |

+ 0 - 0
docker/base.Dockerfile → docker/full-base.Dockerfile


+ 1 - 1
docker/Dockerfile → docker/full-release.Dockerfile

@@ -15,7 +15,7 @@ RUN cd /tmp \
     && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
     && echo "${TZ}" > /etc/timezone \
     && rm -rf /tmp/*
-COPY normal-rootfs /
+COPY full-rootfs /
 ENTRYPOINT ["/init"]
 WORKDIR /config
 VOLUME ["/config", "/media"]

+ 0 - 0
docker/normal-rootfs/etc/cont-init.d/10-fixuser → docker/full-rootfs/etc/cont-init.d/10-fixuser


+ 0 - 0
docker/normal-rootfs/etc/services.d/chinesesubfinder/run → docker/full-rootfs/etc/services.d/chinesesubfinder/run


+ 0 - 0
docker/normal-rootfs/etc/services.d/xvfb/run → docker/full-rootfs/etc/services.d/xvfb/run


+ 29 - 0
docker/lite-entrypoint.sh

@@ -0,0 +1,29 @@
+#!/bin/bash
+
+## 重设权限
+chown -R "${PUID}:${PGID}" /config
+if [[ ${PERMS} == true ]]; then
+    echo "已设置 PERMS=true,重设 '/media' 目录权限为 ${PUID}:${PGID} 所有..."
+    chown -R ${PUID}:${PGID} /media
+fi
+
+## 兼容旧的缓存目录
+if [[ -d /app/cache ]]; then
+    echo "检测到映射了 '/app/cache',创建软连接 '/config/cache' -> '/app/cache'"
+    chown -R ${PUID}:${PGID} /app
+    if [[ -L /config/cache && $(readlink -f /config/cache) != /app/cache ]]; then
+        rm -rf /config/cache &>/dev/null
+    fi
+    if [[ ! -e /config/cache ]]; then
+        s6-setuidgid ${PUID}:${PGID} ln -sf /app/cache /config/cache
+    fi
+else
+    if [[ -L /config/cache ]]; then
+        echo "检测到 '/config/cache' 指向了不存在的目录 '/app/cache',删除之,如想保留缓存,请将旧的 'cache' 目录移动到 '/config' 路径下..."
+        rm -rf /config/cache &>/dev/null
+    fi
+fi
+
+umask ${UMASK:-022}
+cd /config
+exec su-exec "${PUID}:${PGID}" chinesesubfinder

+ 56 - 0
docker/lite-init.sh

@@ -0,0 +1,56 @@
+#!/bin/bash
+
+set -e
+
+export CGO_ENABLED=1
+export GO111MODULE=on
+export GOOS=linux
+export MUSL=/musl
+
+## 准备必要的环境
+[[ ! -d ~/go/src ]] && mkdir -p ~/go/src
+[[ ! -d ~/go/bin ]] && mkdir -p ~/go/bin
+
+## 下载源码并下载go mod
+cd ~/go/src
+curl -sSL https://github.com/allanpk716/ChineseSubFinder/archive/refs/tags/${VERSION}.tar.gz | tar xvz --strip-components 1
+npm --prefix frontend ci
+npm --prefix frontend run build
+go mod tidy
+
+## 编译共用函数
+cross_make() {
+    export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+    if [[ -n ${CROSS_NAME} ]]; then
+        export CPLUS_VERSION=$(${MUSL}/${CROSS_NAME}-cross/bin/${CROSS_NAME}-g++ --version | grep -oE '\d+\.\d+\.\d+' | head -1)
+        export PATH=${MUSL}/${CROSS_NAME}-cross/bin:${MUSL}/${CROSS_NAME}-cross/${CROSS_NAME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+        export C_INCLUDE_PATH=${MUSL}/${CROSS_NAME}-cross/${CROSS_NAME}/include
+        export CPLUS_INCLUDE_PATH=${MUSL}/${CROSS_NAME}-cross/${CROSS_NAME}/include/c++/${CPLUS_VERSION}
+        export LIBRARY_PATH=${MUSL}/${CROSS_NAME}-cross/${CROSS_NAME}/lib
+        export CC=${CROSS_NAME}-gcc
+        export CXX=${CROSS_NAME}-g++
+        export AR=${CROSS_NAME}-ar
+    fi
+    echo "[$(date +'%H:%M:%S')] 开始编译 ${GOARCH} 平台..."
+    go build -ldflags="-s -w --extldflags '-static -fpic' -X main.AppVersion=${VERSION} -X main.LiteMode=true" -o ~/go/out/${GOARCH}/chinesesubfinder ./cmd/chinesesubfinder
+    if [[ -n ${CROSS_NAME} ]]; then
+        unset -v CPLUS_VERSION PATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH LIBRARY_PATH CC CXX AR
+    fi
+    export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+}
+
+## 开始交叉编译
+arches=( amd64 386 arm64 arm )
+crosses=( "" i686-linux-musl aarch64-linux-musl armv7l-linux-musleabihf )
+for ((i=0; i<${#arches[@]}; i++)); do
+    export GOARCH=${arches[i]}
+    export CROSS_NAME=${crosses[i]}
+    [[ ${GOARCH} == amd64 ]] && export GOAMD64=v1
+    [[ ${GOARCH} == arm ]] && export GOARM=7
+    cross_make
+    unset -v GOARCH CROSS_NAME GOAMD64 GOARM
+done
+
+## 列出文件
+ls -lR ~/go/out
+exit 0

+ 22 - 0
docker/lite-release.Dockerfile

@@ -0,0 +1,22 @@
+FROM alpine
+ENV TZ=Asia/Shanghai \
+    PUID=1026 \
+    PGID=100 \
+    UMASK=022 \
+    PS1="\u@\h:\w \$ "
+ARG TARGETARCH
+RUN apk add --no-cache \
+       bash \
+       ffmpeg \
+       ca-certificates \
+       tini \
+       su-exec \
+       tzdata \
+    && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
+    && echo "${TZ}" > /etc/timezone \
+    && rm -rf /tmp/* /var/cache/apk/*
+COPY go/out/${TARGETARCH}/chinesesubfinder /usr/bin/chinesesubfinder
+COPY lite-entrypoint.sh /usr/bin/entrypoint.sh
+VOLUME ["/config"]
+WORKDIR /config
+ENTRYPOINT ["tini", "entrypoint.sh"]

+ 75 - 0
docker/readme.md

@@ -1,10 +1,39 @@
+## 镜像标签说明
+
+### latest
+
+- 提供全功能镜像;
+
+- 基于ubuntu,包含`chrome` `xorg` `imagemagic`及大量依赖等,镜像大;
+
+- 支持 `linux/amd64` `linux/arm64`;
+
+- 可以从subhd、zimuku下载字幕;
+
+- 宿主机是基于 musl-libc 的系统,无法正常使用,如 openwrt 和 alpine。
+
+### lite
+
+- 提供轻量模式镜像;
+
+- 基于alpine,删减了许多包,镜像小;
+
+- 支持`linux/amd64` `linux/arm64` `linux/386` `linux/arm/v7`平台;
+
+- 不支持从subhd、zimuku下载字幕;
+
+- 无论是基于 glibc 还是 musl-libc 的系统,都可以使用。
+
 ## 创建
 
 > 建议在 v0.31.x 版本开始使用本教程的 Docker 配置,如果是之前的版本见 v0.26.x 的教程即可。
 
 **docker cli**
 
+
+
 ```
+## latest
 docker run -d \
     -v $(pwd)/config:/config   `# 冒号左边请修改为你想在主机上保存配置、日志等文件的路径` \
     -v $(pwd)/media:/media     `# 请修改为需要下载字幕的媒体目录,冒号右边可以改成你方便记忆的目录,多个媒体目录需要添加多个-v映射` \
@@ -21,6 +50,23 @@ docker run -d \
     --log-driver "json-file" \
     --log-opt "max-size=100m" `# 限制日志大小,可自行调整` \
     allanpk716/chinesesubfinder
+
+## lite
+docker run -d \
+    -v $(pwd)/config:/config   `# 冒号左边请修改为你想在主机上保存配置、日志等文件的路径` \
+    -v $(pwd)/media:/media     `# 请修改为需要下载字幕的媒体目录,冒号右边可以改成你方便记忆的目录,多个媒体目录需要添加多个-v映射` \
+    -e PUID=1026 \
+    -e PGID=100 \
+    -e PERMS=true       `# 是否重设/media权限` \
+    -e TZ=Asia/Shanghai `# 时区` \
+    -e UMASK=022        `# 权限掩码` \
+    -p 19035:19035 `# 从0.20.0版本开始,通过webui来设置` \
+    -p 19037:19037 `# webui 的视频列表读取图片用,务必设置不要暴露到外网` \
+    --name chinesesubfinder \
+    --hostname chinesesubfinder \
+    --log-driver "json-file" \
+    --log-opt "max-size=100m" `# 限制日志大小,可自行调整` \
+    allanpk716/chinesesubfinder:lite
 ```
 
 创建好后访问`http://<ip>:19035`来进行下一步设置。
@@ -29,6 +75,7 @@ docker run -d \
 
 新建`docker-compose.yml`文件如下,并以命令`docker-compose up -d`启动。
 
+latest
 ```
 version: "3"
 services:
@@ -57,6 +104,34 @@ services:
           max-size: "100m" # 限制日志大小,可自行调整
 ```
 
+lite
+```
+version: "3"
+services:
+  chinesesubfinder:
+    image: allanpk716/chinesesubfinder:lite
+    volumes:
+      - ./config:/config  # 冒号左边请修改为你想在主机上保存配置、日志等文件的路径
+      - ./media:/media    # 请修改为你的媒体目录,冒号右边可以改成你方便记忆的目录,多个媒体目录需要分别映射进来
+    environment:
+      - PUID=1026         # uid
+      - PGID=100          # gid
+      - PERMS=true        # 是否重设/media权限
+      - TZ=Asia/Shanghai  # 时区
+      - UMASK=022         # 权限掩码
+    restart: always
+    network_mode: bridge
+    hostname: chinesesubfinder
+    container_name: chinesesubfinder
+    ports:
+      - 19035:19035
+      - 19037:19037  # webui 的视频列表读取图片用,务必设置不要暴露到外网
+    logging:
+        driver: "json-file"
+        options:
+          max-size: "100m" # 限制日志大小,可自行调整
+```
+
 创建好后访问`http://<ip>:19035`来进行下一步设置。
 
 ## 关于 PUID/PGID 的说明