HoshinoBot icon indicating copy to clipboard operation
HoshinoBot copied to clipboard

Docker deployment for Hoshino

Open zzbslayer opened this issue 4 years ago • 22 comments

Hoshino can be run as daemon in linux, implemented by python-daemon. Hoshino can be deployed by docker. Usage is updated in README.

zzbslayer avatar May 02 '20 08:05 zzbslayer

Good idea. Daemon is very useful!

But for docker, Hoshino need to direct access to custom RESOURCE_DIR, you should also make a link. More tests required. Hoshino is designed for multi QQ accounts. All QQ accounts using the same back-end can share the same data. I don't think it's really necessary to deploy with docker. As for the dependence, pyvenv or pyenv is a better practice.

Ice9Coffee avatar May 02 '20 09:05 Ice9Coffee

For the RESOURCE_DIR, just mount the directory to the container by -v.

docker run -d --name=hoshino \
-v ~/.hoshino:/root/.hoshino \
-p 8080:8080 \
hoshino

zzbslayer avatar May 02 '20 09:05 zzbslayer

I know. But RESOURCE_DIR is custom. It doesn't have to in ~/.hoshino. You should add more tips in README.md

Ice9Coffee avatar May 02 '20 09:05 Ice9Coffee

I see. README updated in the latest commit.

zzbslayer avatar May 02 '20 09:05 zzbslayer

Basically, there're 3 advantages to deploy Hoshino with docker.

  1. Hoshino can be run as daemon without python-daemon.
  2. Environment isolation. No need for pyvenv, conda, or other virtual environment.
  3. With docker network, we can bridge coolq and hoshino. Set the host url as localhost. No worries about localhost, 172.17.0.1 or others. (this is not mentioned in README)

Anyway, docker deployment is just an option.

zzbslayer avatar May 02 '20 12:05 zzbslayer

大佬大佬,我觉得docker对于linux自建来说还是可以的,但是想自己定制化机器人就显得比较麻烦,hoshinobot整个的框架已经挺完善了,很容易自己写点小东西来学习玩耍:-( 萌新是用vscode远程改代码 用screen运行hoshinobot ,总体来说还是体验很不错的

AkiraXie avatar May 02 '20 20:05 AkiraXie

docker部署优点在于隔离性好,无须任何额外环境配置。 我提供了docker部署的feature,但并不影响你直接在linux上运行。

至少我看好几个想用Hoshino的人,连配环境都不会,有各种各样的问题(我自己配环境的时候也因为系统缺少_sqlite 导致我得自行编译python3.8,属实麻烦)。他们也不会conda等工具管理虚拟环境,这种情况下,docker一键部署对他们来说是一个更好的选择。(连配环境都不会,所以他们当然更不会去改代码了…)

zzbslayer avatar May 03 '20 15:05 zzbslayer

我觉得docker比较适合作为发行版,或许可以直接放到docker hub上,但缺点在于需要经常去维护。 现在的Dockerfile是将代码和配置文件拷贝到容器中,这样并不方便去修改零碎的config.json配置文件,或许可以考虑开一个新的branch,Dockerfile从这个branch拉取精简版的hoshino(仅包含不需要额外config.json的功能)来实现一行命令直接部署;同时也免去了升级的问题,删掉旧容器重建即可。

Ice9Coffee avatar May 03 '20 15:05 Ice9Coffee

Dockerfile 一般都是本地将代码和配置文件拷贝到容器内,不知道你是想怎么做? 如果是为了更方便的修改config.json,可以在config.json中允许使用环境变量赋值。 然后通过 docker-compose来启动,这样修改compose配置文件中的环境变量,就相当于修改了config.json配置。

zzbslayer avatar May 03 '20 15:05 zzbslayer

环境变量是修改docker中的配置的常用手段。比如cqhttp镜像就是通过环境变量来修改配置文件。

zzbslayer avatar May 03 '20 15:05 zzbslayer

config.json是各插件独立的,插件的功能不同其中的结构也不同。比较简单的仅存放一个AUTH_KEY,而复杂的则存了多个列表、字典(如gacha/config.json),我想这不是简单修改环境变量就能调整的。 我的想法有2个,一种办法是提供精简版的docker image,仅保留无外部依赖的功能;另一种办法是将代码目录也进行映射,这样以后维护config.json时才能更加方便。 或许你可以参考NoneBot的文档->部署,将酷Q与Hoshino一起部署。

Ice9Coffee avatar May 03 '20 15:05 Ice9Coffee

  1. 列表、字典或者更复杂的对象的配置可以通过编写parser进行环境变量配置,比如json parser。
  2. 通过 -v 参数把代码挂在进去的话,也并不能够做到动态修改。每次修改了代码,还是得进入容器,把里面的 Hoshino 停止重启,并没有比 rebuild 方便到哪里去… Nonebot的解决方案,我觉得把coolq跟nonebot分成两个compose文件更好。coolq镜像一直运行在那相对稳定,而nonebot有频繁改动。 另外就是,编写简单的 shell 脚本也可以做到一键 销毁容器、重建容器、启动容器。有 docker 的分层机制,rebuild 非常快。 不过着确实是一个比较让人舒适的方案。这个镜像仅仅是环境而已。我就先按照这个修改吧。

zzbslayer avatar May 03 '20 16:05 zzbslayer

仅生成包含必要环境的镜像。运行时将代码挂载。通过 docker-compose 启停。

zzbslayer avatar May 03 '20 19:05 zzbslayer

使用 docker 网络,避免 8080 端口暴露在外。

zzbslayer avatar May 03 '20 19:05 zzbslayer

将中文字体复制到镜像内。防止 Matplotlib 生成的图像中的中文显示乱码。

zzbslayer avatar May 09 '20 12:05 zzbslayer

  • Remove ttf file.
  • Provide a link to download it in README.

zzbslayer avatar May 09 '20 13:05 zzbslayer

https://github.com/Ice-Cirno/HoshinoBot/compare/050ff19cf8ec008ed78db0583e1d8748db6c62fe..f8c80a873c18ee208fadee725b00e9e06a3c7d19 Well.. I think the ttf file is deleted in the latest commit.

zzbslayer avatar May 09 '20 14:05 zzbslayer

Yes, you delete it indeed, but it is still tracked by git. The size of the repo increased, and someone else could revert this commit.

Ice9Coffee avatar May 09 '20 14:05 Ice9Coffee

lol. interesting.

zzbslayer avatar May 09 '20 14:05 zzbslayer

是不是可以参考一下yobot的docker部署方式。如果以后添加工会战web管理功能,docker的物理隔离就十分重要了,毕竟web那套东西没有物理隔离在自己服务器上跑谁都不放心。

zyujs avatar Jul 03 '20 01:07 zyujs