From 59f7c5ae63d1cbc2a6acfa32f41144acc5596dfc Mon Sep 17 00:00:00 2001 From: WolfBolin Date: Wed, 13 Oct 2021 21:00:28 +0800 Subject: [PATCH 1/3] Update README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 989de47..c2dbf63 100644 --- a/README.md +++ b/README.md @@ -69,3 +69,4 @@ httpx: [github](https://github.com/encode/httpx) [pypi](https://pypi.org/project ## License [MIT License](https://github.com/Womsxd/AutoMihoyoBBS/blob/master/LICENSE) + From dd3f8ef48211d9a043083a72548003856e18e996 Mon Sep 17 00:00:00 2001 From: WolfBolin Date: Sat, 6 Nov 2021 19:06:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Docker=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++++ Dockerfile | 26 ++++++++++++++++++++++++++ make-docker.sh | 18 ++++++++++++++++++ restart-docker.sh | 4 ++++ 4 files changed, 52 insertions(+) create mode 100644 Dockerfile create mode 100644 make-docker.sh create mode 100644 restart-docker.sh diff --git a/.gitignore b/.gitignore index e343837..cb4e9d0 100644 --- a/.gitignore +++ b/.gitignore @@ -133,3 +133,7 @@ dmypy.json #自己用的推送(( push_main.py + +# 避免上传配置文件 +.idea/ +config/*.json diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..50456b0 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/make-docker.sh b/make-docker.sh new file mode 100644 index 0000000..e6e5008 --- /dev/null +++ b/make-docker.sh @@ -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 \ No newline at end of file diff --git a/restart-docker.sh b/restart-docker.sh new file mode 100644 index 0000000..a05ac34 --- /dev/null +++ b/restart-docker.sh @@ -0,0 +1,4 @@ +#!/bin/bash +docker_name="mihoyo-bbs" +docker restart ${docker_name} +docker logs -f ${docker_name} \ No newline at end of file From 545a593fa9b072f3d24f909f7f031118dc01d620 Mon Sep 17 00:00:00 2001 From: WolfBolin Date: Sat, 6 Nov 2021 19:18:50 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0Docker=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++ restart-docker.sh | 4 ---- 2 files changed, 49 insertions(+), 4 deletions(-) delete mode 100644 restart-docker.sh diff --git a/README.md b/README.md index c2dbf63..087d408 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/restart-docker.sh b/restart-docker.sh deleted file mode 100644 index a05ac34..0000000 --- a/restart-docker.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -docker_name="mihoyo-bbs" -docker restart ${docker_name} -docker logs -f ${docker_name} \ No newline at end of file