Skip to content

Commit

Permalink
Merge pull request #6 from lee-cq/重构-worker
Browse files Browse the repository at this point in the history
使用新的架构重构,可配置性高且易于拓展
  • Loading branch information
lee-cq authored Mar 2, 2024
2 parents db4d974 + 0eccdba commit 6d0ea4f
Show file tree
Hide file tree
Showing 48 changed files with 1,806 additions and 1,656 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/alist-sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Alist Sync

env:
_ALIST_SYNC_NAME: "action-${{github.actor}}-${{github.run_id}}-${{github.run_number}}"

on:
workflow_dispatch:
inputs:
reload_storage:
description: |
是否重新创建存储: true or false
默认情况下,如果存储已经存在,则不会重新创建
如果指定了true,则会删除全部的存储器,并从新载入
required: false
default: false
type: boolean

jobs:
run:
name: "sync-actions"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python v4
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install alist-sync
run: |
pip install --upgrade pip
pip install -e .
- name: Load Cache
id: alist-data-cache
uses: actions/cache@v4
with:
key: ${{ runner.name }}-alist-sync-data
path: |
./.alist-sync-cache/*.db
./.alist-sync-cache/*.json
./alist/data
- name: Install and Init Alist Server
env:
_ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }}
run: |
# init-alist 总是会重置管理员密码为环境变量。
bash -ex bootstrap.sh init-alist.sh
- name: Create Storage for Alist if load cache failed
if: ${{ github.event.inputs.reload_storage == 'true' }} or ${{ steps.alist-data-cache.outputs.cache-hit != 'true'}}
env:
_ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }}

_ALIST_BACKUP: ${{secrets.ALIST_BACKUP}}
_ALIST_BACKUP_URL: ${{secrets.ALIST_BACKUP_URL}}
_ALIST_BACKUP_USERNAME: ${{secrets.ALIST_BACKUP_USERNAME}}
_ALIST_BACKUP_PASSWORD: ${{secrets.ALIST_BACKUP_PASSWORD}}

_RELOAD_STORAGE: ${{ github.event.inputs.reload_storage }}
run: |
# 这将会导入全部的内容包括:设置,元数据,用户,存储器。
cat > alist-backup-config.json < EOF
${{ secrets.ALIST_BACKUP_CONFIG }}
EOF
python3 tools/create_storage.py
- name: RUN
env:
SYNC_CONFIG: ${{secrets.SYNC_CONFIG}}
_ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }}
run: |
cat > alist-backup-config.json < EOF
${{ secrets.ALIST_BACKUP_CONFIG }}
EOF
python3 -m alist_sync sync -c $SYNC_CONFIG
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
alist-version: [ '3.29.1', '3.30.0' ]
alist-version: [ '3.31.0' ]
python-version: [ '3.10', '3.11', '3.12' ]
fail-fast: false

Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ __pycache__/
tests/alist/
local_test*
tmp/
config.json
config.yaml

.alist-sync-cache/
alist_sync/.alist-sync-cache/
alist/
tools/alist/

# C extensions
*.so
Expand Down Expand Up @@ -161,3 +168,4 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
alist-backup-config.json
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.isort",
"ms-python.autopep8",
"ms-python.black-formatter",
"ms-python.debugpy",

"github.github-vscode-theme",
"github.copilot"
"github.copilot",
"mongodb.mongodb-vscode"
]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"editor.formatOnPaste": true,
"diffEditor.ignoreTrimWhitespace": false,
"editor.formatOnType": true,
"editor.wordBasedSuggestions": false
"editor.wordBasedSuggestions": "off"
}
}
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,32 @@ Alist 同步工具

终极目标:利用GitHub Actions实现使用Github的计算和网络资源定期同步各个网盘之间的数据。

## 本地运行

```bash
python -m alist_sync -c "<config-file.yaml>"
```

## Actions 运行

1. FORK存储库

2. 创建SYNC_CONFIG文件,内容参见:[config-template.yaml](./config-template.yaml)

3. 创建存储库机密(Action):
1. ALIST_BACKUP: `可选 [JSON]` 现有ALIST网页端导出的备份配置, 用于初始化Alist
2. ALIST_BACKUP_URL: `可选 [URL]` 可以从远程导出BACKUP的URL, 与ALIST_BACKUP二选一
3. ALIST_BACKUP_USERNAME: `可选 [string]` 当ALIST_BACKUP存在时,需要提供用户名
4. ALIST_BACKUP_PASSWORD: `可选 [string]` 当ALIST_BACKUP存在时,需要提供密码
5. ALIST_ADMIN_PASSWORD: `可选[string]` 管理员密码,默认值: `123456`
6. SYNC_CONFIG: `必选[YAML|JSON]` Alist-sync的配置

4. 启用Action

## 预期同步模式:

### 1. copy 简单复制 (已实现)

*命令:* `alist-sync copy -h http://localhost:5244 -u admin -p 123456 -s /源目录 -t /目标目录1 -t /目标目录2 ...`

#### 工作原理:

Expand All @@ -19,8 +40,6 @@ Alist 同步工具

### 2. mirror 镜像复制 (已实现)

*命令:* `alist-sync mirror -h http://localhost:5244 -u admin -p 123456 -s /源目录 -t /目标目录1 -t /目标目录2 ...`

#### 工作原理:

将源目录中的文件分别镜像同步到全部的目标目录中,
Expand All @@ -30,8 +49,6 @@ Alist 同步工具

### 3. sync 多源双向复制(实现中)

*命令:* `alist-sync sync -h http://localhost:5244 -u admin -p 123456 -s /目录1 -s /目录2 -s /目录3 ...`

#### 工作原理:

-s 指定的目录分别作为源目录,想其他的目录中发起copy命令
Expand All @@ -42,8 +59,6 @@ Alist 同步工具

### 4. sync-incr 多源增量复制(设计中)

*命令:* `alist-sync sync_incr -h http://localhost:5244 -u admin -p 123456 -s /目录1 -s /目录2 -s /目录3 ...`

#### 工作原理:

-s 指定的目录分别作为源目录,想其他的目录中发起copy命令, 首次运行后会生成配置文件,持久化保存,作为增量的识别文件。
Expand Down
Loading

0 comments on commit 6d0ea4f

Please sign in to comment.