Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Commit

Permalink
Add docker deployment method (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
enwaiax authored Feb 15, 2022
1 parent b1009f3 commit 8e46163
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.github/
__pycache__/
public/
serverless/
Dockerfile
.gitignore
ql_update.py
README.md
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:alpine as builder

RUN apk update && apk add --no-cache tzdata alpine-sdk libffi-dev
ADD requirements.txt /tmp/requirements.txt
RUN pip3 install --user -r /tmp/requirements.txt && rm /tmp/requirements.txt

FROM python:alpine
WORKDIR /root
ENV TZ=Asia/Shanghai

COPY --from=builder /root/.local /usr/local
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY . /root

CMD ["python", "scheduler.py"]
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
7. 自动领取 vip 成长值(任务需自己完成)
8. 多种推送方式
9. 支持多账号
10. 支持[腾讯云函数](#一部署到腾讯云函数) & [青龙面板](#二部署到青龙面板) & [本地运行](#三本地运行)
10. 支持[腾讯云函数](#一部署到腾讯云函数) & [青龙面板](#二部署到青龙面板) & [本地运行](#三本地运行) & [docker 部署](#四使用docker部署)

> 开发不易,如果你觉得本项目对你有用,可以点个 star,也可以到底部给个[赞赏](#赞赏)
Expand Down Expand Up @@ -514,6 +514,37 @@ pip install -r requirements.txt
python index.py
```

## 四、使用`docker`部署

> 1. 支持 ARM64/AMD64 docker 镜像
> 2. 支持指定时间定时执行
> 3. 未指定定时执行时间,每次重启随机设定执行时间
### 下载并配置 `config.json`

```shell
curl -fsSL -o config.json https://raw.githubusercontent.com/chen310/NeteaseCloudMusicTasks/main/config.json
```

### 随机时间执行

```shell
docker run -itd --restart=on-failure \
-v $(pwd)/config.json:/root/config.json \
--name netease-cloud-music-tasks \
enwaiax/netease-cloud-music-tasks:latest
```

### 指定时间执行

```shell
docker run -itd --restart=on-failure \
-v $(pwd)/config.json:/root/config.json \
-e "SCHEDULER_HOUR=8" -e "SCHEDULER_MINUTE=30" \
--name netease-cloud-music-tasks \
enwaiax/netease-cloud-music-tasks:latest
```

## 其他

### 对日推的影响
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
requests==2.26.0
json5==0.9.6
pycryptodomex==3.12.0
pycryptodomex==3.12.0
APScheduler==3.8.1
21 changes: 21 additions & 0 deletions scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import random
from apscheduler.schedulers.background import BlockingScheduler
from index import start

if __name__ == "__main__":
try:
start()
scheduler_hour = os.environ.get(
"SCHEDULER_HOUR", random.randint(0, 23))
scheduler_minute = os.environ.get(
"SCHEDULER_MINUTE", random.randint(0, 59))
print("Scheduler hour: %s, minute: %s" %
(scheduler_hour, scheduler_minute))
scheduler = BlockingScheduler(timezone='Asia/Shanghai')
scheduler.add_job(start, 'cron', hour=scheduler_hour,
minute=scheduler_minute)
scheduler.start()
except Exception as e:
print(e)
exit(1)
2 changes: 1 addition & 1 deletion user.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setUser(self, user_config, user_setting):
self.title += ': 请填写账号密码'
self.taskTitle('用户信息')
self.taskInfo('登录失败,请填写账号密码')
return
raise Exception('请填写账号密码')
self.music = self.login_check(user_config['username'], user_config['password'], user_config.get(
'countrycode', ''), user_config['X-Real-IP'])
if self.music.uid != 0:
Expand Down

0 comments on commit 8e46163

Please sign in to comment.