FROM hectorqin/reader:openj9-latest USER root # socat: 端口转发 # python3/pip + huggingface_hub: 上传/下载 dataset 文件 RUN apt-get update && apt-get install -y socat python3 python3-pip && \ pip3 install --no-cache-dir huggingface_hub RUN mkdir -p /storage /app/bin/logs && chmod -R 777 /storage /app/bin/logs EXPOSE 7860 RUN cat > /app/run.sh <<'SH' #!/bin/sh set -u : "${BACKUP_REPO:=yourname/reader-backup}" : "${BACKUP_FILENAME:=reader_backup_min.tgz}" : "${BACKUP_INTERVAL:=1800}" # 30 分钟一次,别太频繁 : "${STORAGE_DIR:=/storage}" echo "==== Reader minimal backup via HF Dataset ====" echo "BACKUP_REPO=$BACKUP_REPO" echo "BACKUP_FILENAME=$BACKUP_FILENAME" echo "BACKUP_INTERVAL=$BACKUP_INTERVAL" echo "STORAGE_DIR=$STORAGE_DIR" mkdir -p "$STORAGE_DIR" chmod -R 777 "$STORAGE_DIR" || true # 1) 启动时:从 dataset 恢复(如果存在) echo "[1/3] Try restore from dataset..." RESTORE_PATH="$(python3 - </bookSource.json, data//bookshelf.json find data -maxdepth 2 -type f \( -name "bookSource.json" -o -name "bookshelf.json" \) 2>/dev/null || true ) > "$TMP_DIR/filelist.txt" if [ -s "$TMP_DIR/filelist.txt" ]; then (cd "$STORAGE_DIR" && tar -czf "$TMP_TGZ" -T "$TMP_DIR/filelist.txt") || true if [ -f "$TMP_TGZ" ]; then echo "[backup $TS] Uploading minimal backup..." python3 - <8080" socat TCP-LISTEN:7860,fork TCP:127.0.0.1:8080 & # 4) 启动 Reader,并明确 storage 路径 echo "[3/3] Start Reader..." exec java -Dreader.app.storagePath=/storage -jar /app/bin/reader.jar --server.port=8080 SH RUN chmod +x /app/run.sh ENTRYPOINT ["/app/run.sh"]