Merge pull request #31 from wolfbolin/develop

将脚本运行进行Docker封装
This commit is contained in:
Womsxd 2021-11-06 21:36:02 +08:00 committed by GitHub
commit 315eb7d884
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 172 additions and 75 deletions

4
.gitignore vendored
View File

@ -136,3 +136,7 @@ dmypy.json
#自己用的推送((
push_main.py
# 避免上传配置文件
.idea/
config/*.json

26
Dockerfile Normal file
View File

@ -0,0 +1,26 @@
FROM python:3.8-slim-buster
LABEL maintainer="mailto@wolfbolin.com"
# Why need these step?
# - fast mirror source
# - procps contains useful proccess control commands like: free, kill, pkill, ps, top
# - wget is quite basic tool
# - vim for online debugging
# - sync timezone
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
&& sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
&& apt-get update && apt-get install -y --no-install-recommends procps wget vim \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# Project environment
WORKDIR /var/app
COPY . /var/app
COPY ./Config/openssl.cnf /etc/ssl
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip \
&& pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
# Docker operation parameters
ENV MULTI TRUE
CMD if [ $MULTI==TRUE ];then python main_multi.py autorun;else python main.py;fi

View File

@ -60,6 +60,55 @@
7. **此时Cookie已经复制到你的粘贴板上了**
## 使用Docker运行
Docker的运行脚本基于Linux平台编写暂未在Win平台测试。
将本项目Clone至本地后请先按照上述步骤添加或修改配置文件。随后运行`make-docker.sh`脚本本地构建Docker镜像同时初次运行容器。
```shell
sh make-docker.sh
```
或手动执行
```
# 编译容器
docker build -f Dockerfile --tag ${docker_name}:"${time_now}" .
```
```
# 运行容器(默认自动多配置文件)
docker run -itd \
--name ${docker_name} \
--log-opt max-size=1m \
-v $(pwd):/var/app \
${docker_name}:"${time_now}"
# 运行容器直接运行main.py
docker run -itd \
--name ${docker_name} \
--log-opt max-size=1m \
-v $(pwd):/var/app \
-e MULTI=FALSE \
${docker_name}:"${time_now}"
```
若需要添加配置文件或修改配置文件可直接在主机config文件夹中修改修改的内容将实时同步在容器中。
若需要再次运行签到脚本可手动重启容器。每次运行Docker容器后容器内将自动按照参数执行签到活动签到完成后容器将自动停止运行。
```
docker restart ${docker_name} && docker logs -f ${docker_name}
```
关于每日定时,用户可在容器外部设计定时触发(启动)程序,每日定时运行脚本。
(若有需要可自行编写相关脚本通知完成状态
## 使用的第三方库
requests: [github](https://github.com/psf/requests) [pypi](https://pypi.org/project/requests/)

18
make-docker.sh Normal file
View File

@ -0,0 +1,18 @@
#!/bin/bash
docker_name="mihoyo-bbs"
docker stop ${docker_name}
docker rm ${docker_name}
echo -e "\033[5;36mOrz 旧容器(镜像)已清理\033[0m"
time_now=$(date "+%m%d%H")
docker build -f Dockerfile --tag ${docker_name}:"${time_now}" .
echo -e "\033[5;36mOrz 镜像重建完成\033[0m"
docker run -itd \
--name ${docker_name} \
--log-opt max-size=1m \
-v $(pwd):/var/app \
${docker_name}:"${time_now}"
echo -e "\033[5;36mOrz 镜像启动完成\033[0m"
docker ps -a
docker logs ${docker_name} -f