Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker deployment for Hoshino #52

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

zzbslayer
Copy link

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

@Ice9Coffee
Copy link
Owner

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.

@zzbslayer
Copy link
Author

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

@Ice9Coffee
Copy link
Owner

Ice9Coffee commented May 2, 2020

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

@zzbslayer
Copy link
Author

I see. README updated in the latest commit.

@zzbslayer
Copy link
Author

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.

@AkiraXie
Copy link
Contributor

AkiraXie commented May 2, 2020

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

@zzbslayer
Copy link
Author

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

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

@Ice9Coffee
Copy link
Owner

Ice9Coffee commented May 3, 2020

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

@Ice9Coffee Ice9Coffee added enhancement New feature or request good first issue Good for newcomers labels May 3, 2020
@zzbslayer
Copy link
Author

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

@zzbslayer
Copy link
Author

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

@Ice9Coffee
Copy link
Owner

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

@zzbslayer
Copy link
Author

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

@zzbslayer
Copy link
Author

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

@zzbslayer
Copy link
Author

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

@zzbslayer
Copy link
Author

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

README.md Outdated Show resolved Hide resolved
hoshino-compose.yml Outdated Show resolved Hide resolved
Copy link
Owner

@Ice9Coffee Ice9Coffee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YaHei is owned by Microsoft, we should not add it in to our repo. You can provide a download link, or guide the users to copy themselves font.

@zzbslayer zzbslayer force-pushed the docker-deployment branch from 050ff19 to f8c80a8 Compare May 9, 2020 13:57
@zzbslayer
Copy link
Author

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

Ice9Coffee
Ice9Coffee previously approved these changes May 9, 2020
Copy link
Owner

@Ice9Coffee Ice9Coffee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ttf file (14.3MB) is still in the repo(笑)
Doesn't matter, I'll deal with it.

@zzbslayer
Copy link
Author

@Ice9Coffee
Copy link
Owner

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.

@zzbslayer
Copy link
Author

lol. interesting.

@zyujs
Copy link

zyujs commented Jul 3, 2020

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

@Ice9Coffee Ice9Coffee dismissed their stale review June 16, 2022 07:42

too old

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants