ngbs 2 years ago
parent
commit
2600572fcb

+ 63 - 0
.github/workflows/build-mdc-baseimages.yml

@@ -0,0 +1,63 @@
+name: Build MDC Baseimage
+
+on:
+  workflow_dispatch:
+    inputs:
+      manual:
+        description: 'manual build and publish'
+  schedule:
+    - cron: '0 20 15,30 * *'
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Set Variables
+        run: |
+          echo "MDC_BASEIMAGE_VERSION=$(curl -fsSL https://api.github.com/repos/pyinstaller/pyinstaller/releases/latest | grep '"tag_name":' | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/v//g;s/,//g;s/ //g')" >> $GITHUB_ENV
+        shell: bash
+
+      - name: Check Out Repo
+        uses: actions/checkout@v3
+
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v1
+
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v2
+
+      - name: Cache Docker layers
+        uses: actions/cache@v3
+        with:
+          path: /tmp/.buildx-cache
+          key: ${{ runner.os }}-buildx-${{ github.sha }}
+          restore-keys: |
+            ${{ runner.os }}-buildx-
+
+      - name: Login to Docker Hub
+        uses: docker/login-action@v2
+        with:
+          username: ${{ secrets.DOCKER_HUB_USERNAME }}
+          password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
+
+      - name: Build and push Docker images
+        uses: docker/build-push-action@v3
+        id: docker_build_mdc_baseimage
+        with:
+          context: ./mdc
+          file: ./mdc/Dockerfile.builder
+          push: true
+          tags: |
+            ${{ secrets.DOCKER_HUB_USERNAME }}/mdc-buildimage:dev
+            ${{ secrets.DOCKER_HUB_USERNAME }}/mdc-buildimage:${{ env.MDC_BASEIMAGE_VERSION }}
+          builder: ${{ steps.buildx.outputs.name }}
+          cache-from: type=local,src=/tmp/.buildx-cache
+          cache-to: type=local,dest=/tmp/.buildx-cache-new
+
+      - name: Move cache
+        run: |
+          rm -rf /tmp/.buildx-cache
+          mv /tmp/.buildx-cache-new /tmp/.buildx-cache
+
+      - name: Image digest
+        run: echo ${{ steps.docker_build_mdc_baseimage.outputs.digest }}

+ 61 - 0
.github/workflows/build-mdc.yml

@@ -0,0 +1,61 @@
+name: Build MDC
+
+on:
+  workflow_dispatch:
+    inputs:
+      manual:
+        description: 'manual build and publish'
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Set Variables
+        run: |
+          echo "MDC_VERSION=$(curl -fsSL https://api.github.com/repos/yoshiko2/Movie_Data_Capture/releases/latest | grep '"tag_name":' | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/v//g;s/,//g;s/ //g')" >> $GITHUB_ENV
+        shell: bash
+
+      - name: Check Out Repo
+        uses: actions/checkout@v3
+
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v1
+
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v2
+
+      - name: Cache Docker layers
+        uses: actions/cache@v3
+        with:
+          path: /tmp/.buildx-cache
+          key: ${{ runner.os }}-buildx-${{ github.sha }}
+          restore-keys: |
+            ${{ runner.os }}-buildx-
+
+      - name: Login to DockerHub
+        uses: docker/login-action@v1
+        with:
+          username: playn
+          password: ${{ secrets.DOCKERHUB_TOKEN }}
+
+      - name: Build and push Docker images
+        uses: docker/build-push-action@v3
+        id: docker_build_mdc
+        with:
+          context: ./mdc
+          file: ./mdc/Dockerfile
+          push: true
+          tags: |
+            ${{ secrets.DOCKER_HUB_USERNAME }}/mdc:latest
+            ${{ secrets.DOCKER_HUB_USERNAME }}/mdc:${{ env.MDC_VERSION }}
+          builder: ${{ steps.buildx.outputs.name }}
+          cache-from: type=local,src=/tmp/.buildx-cache
+          cache-to: type=local,dest=/tmp/.buildx-cache-new
+
+      - name: Move cache
+        run: |
+          rm -rf /tmp/.buildx-cache
+          mv /tmp/.buildx-cache-new /tmp/.buildx-cache      
+
+      - name: Image digest
+        run: echo ${{ steps.docker_build.outputs.digest }}

+ 44 - 0
mdc/Dockerfile

@@ -0,0 +1,44 @@
+# syntax=docker/dockerfile:1
+FROM playn/mdc-buildimage:dev as builder
+
+RUN mkdir -p /tmp/mdc && cd /tmp/mdc && \
+    # get mdc source code
+    export MDC_SOURCE_VERSION=$(wget -qO- https://api.github.com/repos/yoshiko2/Movie_Data_Capture/releases/latest | grep '"tag_name":' | head -n 1 | sed -E 's/.*"([^"]+)".*/\1/') && \
+    wget -O- https://github.com/yoshiko2/Movie_Data_Capture/archive/$MDC_SOURCE_VERSION.tar.gz | tar xz -C /tmp/mdc --strip-components 1 && \
+    # fix dowload error
+    sed -i "s/if configProxy:/if configProxy.enable:/g" core.py && \
+    # build mdc
+    /pyinstaller/pyinstaller.sh \
+        --onefile Movie_Data_Capture.py \
+        --hidden-import "ImageProcessing.cnn" \
+        --add-data "Img:Img" \
+        --add-data "$(python -c 'import cloudscraper as _; print(_.__path__[0])' | tail -n 1):cloudscraper" \
+        --add-data "$(python -c 'import opencc as _; print(_.__path__[0])' | tail -n 1):opencc" \
+        --add-data "$(python -c 'import face_recognition_models as _; print(_.__path__[0])' | tail -n 1):face_recognition_models"
+
+FROM playn/alpine
+
+RUN apk --update --no-cache add \
+    libxcb
+
+ENV TZ="Asia/Shanghai"
+ENV UID=99
+ENV GID=100
+ENV UMASK=002
+
+ADD entrypoint.sh entrypoint.sh
+
+RUN chmod +x entrypoint.sh && \
+    mkdir -p /app && \
+    mkdir -p /data && \
+    mkdir -p /config && \
+    useradd -d /config -s /bin/sh mdc && \
+    chown -R mdc /config && \
+    chown -R mdc /data
+
+COPY --from=builder /tmp/mdc/dist/Movie_Data_Capture /app
+COPY --from=builder /tmp/mdc/config.ini /app/config.template
+
+VOLUME [ "/data", "/config" ]
+
+ENTRYPOINT ["/entrypoint.sh"]

+ 42 - 0
mdc/Dockerfile.builder

@@ -0,0 +1,42 @@
+# syntax=docker/dockerfile:1
+FROM python:3.10-alpine
+
+# Official Python base image is needed or some applications will segfault.
+# PyInstaller needs zlib-dev, gcc, libc-dev, and musl-dev
+RUN apk --update --no-cache add \
+    zlib-dev \
+    musl-dev \
+    libc-dev \
+    libffi-dev \
+    gcc \
+    g++ \
+    git \
+    make \
+    cmake \
+    pwgen \
+    jpeg-dev \
+    # mdc builder depenencies
+    libxml2-dev \
+    libxslt-dev \
+    # download utils
+    wget && \
+    # update pip
+    pip install --upgrade pip
+
+# build bootloader for alpine
+RUN mkdir -p /tmp/pyinstaller && \
+    export PYINSTALLER_SOURCE_VERISON=$(wget -qO- https://api.github.com/repos/pyinstaller/pyinstaller/releases/latest | grep '"tag_name":' | head -n 1 | sed -E 's/.*"([^"]+)".*/\1/') && \
+    wget -O- https://github.com/pyinstaller/pyinstaller/archive/$PYINSTALLER_SOURCE_VERISON.tar.gz | tar xz -C /tmp/pyinstaller --strip-components 1 && \
+    cd /tmp/pyinstaller/bootloader && \
+    CFLAGS="-Wno-stringop-overflow -Wno-stringop-truncation" python ./waf configure --no-lsb all && \
+    pip install .. && \
+    rm -Rf /tmp/pyinstaller
+
+ADD /root/ /pyinstaller/
+RUN chmod a+x /pyinstaller/*
+
+# install requirements
+RUN cd /tmp && \
+    export MDC_REQUIREMENTS_SOURCE_VERSION=$(wget -qO- https://api.github.com/repos/yoshiko2/Movie_Data_Capture/releases/latest | grep '"tag_name":' | head -n 1 | sed -E 's/.*"([^"]+)".*/\1/') && \
+    wget -O mdc_requirements.txt https://raw.githubusercontent.com/yoshiko2/Movie_Data_Capture/$MDC_REQUIREMENTS_SOURCE_VERSION/requirements.txt && \
+    pip install -r mdc_requirements.txt

+ 33 - 0
mdc/entrypoint.sh

@@ -0,0 +1,33 @@
+#! /bin/sh
+
+USER=mdc
+config_file="/config/mdc.ini"
+
+echo "---Setup Timezone to ${TZ}---"
+echo "${TZ}" > /etc/timezone
+echo "---Checking if UID: ${UID} matches user---"
+usermod -o -u ${UID} ${USER}
+echo "---Checking if GID: ${GID} matches user---"
+groupmod -o -g ${GID} ${USER} > /dev/null 2>&1 ||:
+usermod -g ${GID} ${USER}
+echo "---Setting umask to ${UMASK}---"
+umask ${UMASK}
+
+echo "---Taking ownership of data...---"
+if [ ! -d /config ]; then
+    echo "---no config folder found, create...---"
+    mkdir -p /config
+fi
+chown -R ${UID}:${GID} /app /data /config 
+
+echo "Checking if config file exist"
+if [ ! -f "${config_file}" ]; then
+    cp /app/config.template "${config_file}"
+    echo "config file missing, we create a new config file, modify the config file and restart container please!"
+    echo "没有找到配置文件,我们创建了一个新的配置文件,请修改后重启镜像"
+    exit 1
+fi
+
+echo "Starting..."
+cd /data
+gosu ${USER} /app/Movie_Data_Capture "$@"