Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SinKy-Yan committed May 29, 2022
1 parent 6d09822 commit ddc4e94
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 38 deletions.
35 changes: 21 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
FROM ubuntu:focal
LABEL org.opencontainers.image.authors="源源圆球"
WORKDIR /home
ENV bot_qq=${bot_qq}
ENV bot_qq_key=${bot_qq_key}
ENV admin_qq=${admin_qq}
ENV webui_passwd={$webui_passwd}
ENV webui_user={$webui_user}
ENV api_key={$api_key}

# 设为非交互命令
ARG DEBIAN_FRONTEND="noninteractive"

RUN sed -i 's/us.archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list; \
sed -i 's/cn.archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list; \
sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list; \
sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list;
# 更换软件源
# RUN sed -i 's/us.archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
# sed -i 's/cn.archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
# sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
# sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list

# 安装依赖
# apt安装依赖
RUN apt update && apt upgrade -y && apt install -y --no-install-recommends \
python3.8 \
python3.9 \
python3-distutils \
python3.8-dev \
python3.9-dev \
vim \
git \
curl \
Expand Down Expand Up @@ -46,17 +49,22 @@ libssl-dev && \
apt clean && rm -rf /var/lib/apt/lists/*

# 调整软链接
RUN ln -s /usr/bin/python3.8 /usr/bin/python
RUN rm -f /usr/bin/python3 && \
rm -f /usr/bin/python && \
ln -s /usr/bin/python3.9 /usr/bin/python && \
ln -s /usr/bin/python3.9 /usr/bin/python3

# 调整时区+设定语言
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
ENV LANG=zh_CN.UTF-8

# 安装pip,然后安装依赖,并清除缓存
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python get-pip.py && rm -f get-pip.py && \
pip install -r https://raw.githubusercontent.com/zhenxun-org/zhenxun_bot-deploy/master/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple && \
pip install rich requests jinja2 thefuzz aiocache baike nonebot_plugin_htmlrender imageio -i https://pypi.tuna.tsinghua.edu.cn/simple && \
pip install -r https://raw.githubusercontent.com/zhenxun-org/zhenxun_bot-deploy/master/requirements.txt && \
pip install rich requests jinja2 thefuzz aiocache baike nonebot_plugin_htmlrender imageio && \
rm -rf ~/.cache/pip/*

# 安装chromium
RUN playwright install chromium

# 克隆zhenxun_bot
Expand All @@ -70,9 +78,8 @@ npm install -g @vue/cli && \
git clone https://github.com/HibiKier/zhenxun_bot_webui.git && \
npm cache clean --force
WORKDIR /home/zhenxun_bot_webui
RUN npm config set registry https://registry.npmmirror.com/ && npm install && npm cache clean --force
RUN npm install && npm cache clean --force

RUN apt -y autoremove
# 拷贝文件
WORKDIR /home
COPY ./go-cqhttp ./go-cqhttp
Expand All @@ -81,4 +88,4 @@ COPY ./files/config.sh ./
COPY ./files/config.yaml ./zhenxun_bot/configs/
COPY ./files/config.py ./zhenxun_bot/configs/

ENTRYPOINT ["./docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]
107 changes: 97 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,121 @@
# [绪山真寻BOT](https://github.com/HibiKier/zhenxun_bot)的Docker版
# [绪山真寻BOT](https://github.com/HibiKier/zhenxun_bot)的Docker版镜像🐋

![](https://img.shields.io/github/workflow/status/SinKy-Yan/zhenxunbot-docker/Build%20Docker%20image?label=%E9%95%9C%E5%83%8F%E7%BC%96%E8%AF%91&style=for-the-badge)
![](https://img.shields.io/docker/image-size/jyishit/zhenxun_bot?label=%E9%95%9C%E5%83%8F%E5%A4%A7%E5%B0%8F&style=for-the-badge)
![](https://img.shields.io/docker/pulls/jyishit/zhenxun_bot?label=%E4%B8%8B%E8%BD%BD%E6%AC%A1%E6%95%B0&style=for-the-badge)
![](https://img.shields.io/badge/Python%E7%89%88%E6%9C%AC-3.8-ff69b4?style=for-the-badge)
![](https://img.shields.io/badge/Python%E7%89%88%E6%9C%AC-3.9-ff69b4?style=for-the-badge)
![](https://img.shields.io/badge/%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0-arm64%7Camd64-8B008B?style=for-the-badge)

## **镜像内已集成运行BOT必须的PostgreSQL、绪山真寻BOT本体、以及真寻BOT-WebUI**
![GitHub release (latest by date)](https://img.shields.io/github/v/release/HibiKier/zhenxun_bot?label=%E7%9C%9F%E5%AF%BBBOT%E7%89%88%E6%9C%AC&style=for-the-badge)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/Mrs4s/go-cqhttp?label=gocq%E7%89%88%E6%9C%AC&style=for-the-badge)
![](https://changkun.de/urlstat?mode=github&repo=SinKy-Yan/zhenxunbot-docker)

额外还有Python3.8、PIP、PIP编译工具链、Vim、wget、git、中文语言包

## 注意事项
**镜像内已集成运行BOT需要的PostgreSQL🐘、绪山真寻BOT本体、以及真寻BOT-WebUI😋**

额外还有Python3.9、PIP、PIP编译工具链、Vim、wget、Git、中文语言包

![Git](https://img.shields.io/badge/-Git-F05032?style=flat-square&logo=git&logoColor=white)
![Vim](https://img.shields.io/badge/-Vim-019733?style=flat-square&&logo=Vim&logoColor=white)
![Ubuntu](https://img.shields.io/badge/-Ubuntu-E95420?style=flat-square&&logo=ubuntu&logoColor=white)
![Ubuntu](https://img.shields.io/badge/-Python-3776AB?style=flat-square&&logo=python&logoColor=white)

## 注意事项⚠

镜像有点大,解压后接近3GB,需要有足够的空间(可能会出个精简版镜像)

需要有1G以上的内存

**先确定能用go-cqhttp登录上BOT的QQ,否则需要进入容器查看日志**

## 快速开始
## 迁移数据库📑

迁移数据库是为了如果你以前部署过真寻的话,可以继承好感度、金币等数据

请先导出旧数据库,如果你使用的是真寻文档里的搭建方法,那么应该可以用`pg_dump --host 127.0.0.1 --port 5432 --username uname > zhenxun.sql testdb`这条命令导出数据库到当前目录并**命名为**`zhenxun.sql`

然后将`zhenxun.sql`拷贝到将要部署Docker版真寻的宿主机的`~/my_plugins`目录下,**如果该目录不存在则需要手动创建**

然后就可以了,容器创建时会检测有没有这个文件,有的话就会帮你导入的,不过只是帮你导入,数据库本身有问题的话就跟我没关系了

## 快速开始🎉

将下面命令中**单引号内**`bot的QQ号``bot的QQ密码``管理员QQ号``识图API-KEY``WebUI用户名``WebUI密码`替换成对应的账号和密码之后执行就好了

将下面命令中**单引号内**`bot的QQ号``bot的QQ密码``管理员QQ号`替换成对应的QQ号和密码之后执行就好了
⚠识图API-KEY不替换也行,但是运行之后bot的识图功能会用不了,以后你想再加上的话需要进入容器自己更改,API_KEY通过[该网址](https://saucenao.com/user.php?page=search-api)注册获取

⚠会在当前用户的用户根目录里新建一个叫`my_plugins`的文件夹,这就是自定义插件的目录,可以使用`cd ~/my_plugins`命令来进入,进入后就可以下载需要的插件了

```
docker run -itd --restart=on-failure:3 \
-e bot_qq='bot的QQ号' \
-e bot_qq_key='bot的QQ密码' \
-e bot_qq='BOT的QQ号' \
-e bot_qq_key='BOT的QQ密码' \
-e admin_qq='管理员QQ号' \
-e api_key='识图API-KEY' \
-e webui_user='WebUI用户名' \
-e webui_passwd='WebUI密码' \
-p 8081:8081 \
-v ~/my_plugins:/home/zhenxun_bot/my_plugins \
--name=zhenxun_bot \
jyishit/zhenxun_bot
```

查看Docker日志,成功运行之后可以去`容器IP:8081`进入真寻的WebUI
执行之后会开始从Docker Hub上下载镜像,下载并解压之后容器创建成功的话终端会返回一长串的容器ID,下载速度取决于你的网速,推荐设置一个镜像加速器

第一次运行容器会自动停止一次容器,不过它应该会自动重启

查看Docker日志,成功运行之后可以去`容器IP:8081`进入真寻的WebUI,如果你没有自定义账号密码的话,默认账号是`admin`,密码是`123456`

## 需要帮助🐱‍💻?

你可以点击图片加入QQ交流群,或者提一个Issue

[![加入QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-1034439737-ddff95?style=for-the-badge)](https://jq.qq.com/?_wv=1027&k=u8PgBkMZ)

## 容器内文件结构📂

```
/home
├── docker-entrypoint.sh
├── go-cqhttp
│   ├── config.yml
│   ├── data
│   ├── device.json
│   ├── go-cqhttp
│   ├── gocq.log
│   ├── logs
│   └── session.token
├── zhenxun_bot
│   ├── basic_plugins
│   ├── bot.py
│   ├── configs
│   ├── data
│   ├── docs_image
│   ├── LICENSE
│   ├── log
│   ├── logo.png
│   ├── models
│   ├── my_plugins
│   ├── plugins
│   ├── poetry.lock
│   ├── pyproject.toml
│   ├── README.md
│   ├── resources
│   ├── restart.sh
│   ├── services
│   ├── update_info.json
│   ├── utils
│   └── __version__
└── zhenxun_bot_webui
├── babel.config.js
├── jsconfig.json
├── LICENSE
├── node_modules
├── package.json
├── package-lock.json
├── public
├── README.md
├── src
├── vue.config.js
├── webui.log
└── yarn.lock
43 changes: 33 additions & 10 deletions files/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,52 @@
set -e

sed -i 's/xxxxxx/'$bot_qq'/g' ./go-cqhttp/config.yml
echo -e "已设置BOT的QQ号为"$bot_qq
sed -i 's/yyyyyy/'$bot_qq_key'/g' ./go-cqhttp/config.yml
echo -e "已设置BOT的QQ密码为"$bot_qq_key
sed -i 's/qqqqqq/'$api_key'/g' ./zhenxun_bot/configs/config.yaml
echo -e "已设置识图API-KEY为"$api_key
sed -i 's/root/'$webui_user'/g' ./zhenxun_bot/configs/config.yaml
echo -e "已设置WebUI的用户名为"$webui_user
sed -i 's/123456/'$webui_passwd'/g' ./zhenxun_bot/configs/config.yaml
echo -e "已设置WebUI的密码为"$webui_passwd
sed -i '3c SUPERUSERS=["'$admin_qq'"]' ./zhenxun_bot/.env.dev
echo -e "已设置超级管理员的QQ为"$admin_qq

mkdir ./zhenxun_bot/my_plugins
sed -i '14a nonebot.load_plugins("my_plugins")' ./zhenxun_bot/bot.py
echo -e "已添加自定义插件目录配置"

get_arch=`arch`
if [[ $get_arch =~ "x86_64" ]];then
mv ./go-cqhttp/go-cqhttp-amd64 ./go-cqhttp/go-cqhttp
rm -f ./go-cqhttp/go-cqhttp-arm64
echo -e "检测到你的设备是amd64架构"
elif [[ $get_arch =~ "aarch64" ]];then
mv ./go-cqhttp/go-cqhttp-arm64 ./go-cqhttp/go-cqhttp
rm -f ./go-cqhttp/go-cqhttp-amd64
echo -e "检测到你的设备是arm64架构"
fi

cat > /tmp/sql.sql <<-EOF
CREATE USER uname WITH PASSWORD 'zhenxun';
CREATE DATABASE testdb OWNER uname;
CREATE ROLE root superuser PASSWORD '123456' login;
EOF

get_arch=`arch`
if [[ $get_arch =~ "x86_64" ]];then
mv /home/go-cqhttp/go-cqhttp-amd64 /home/go-cqhttp/go-cqhttp
rm -f /home/go-cqhttp/go-cqhttp-arm64
elif [[ $get_arch =~ "aarch64" ]];then
mv /home/go-cqhttp/go-cqhttp-arm64 /home/go-cqhttp/go-cqhttp
rm -f /home/go-cqhttp/go-cqhttp-amd64
fi

/etc/init.d/postgresql start
su postgres -c "psql -f /tmp/sql.sql"
echo -e "已创建数据库"

if [ -f "./zhenxun_bot/my_plugins/zhenxun.sql" ]; then
echo "检测到数据库文件,开始导入"
sleep 2s
su postgres -c "psql -U postgres testdb < ./zhenxun_bot/my_plugins/zhenxun.sql"
echo "已导入数据库"
else
echo "没有检测到数据库文件,不导入旧数据库"
fi


echo -e "已导入变量"
echo -e "已完成新容器配置,5秒后自动继续"
sleep 5s
4 changes: 2 additions & 2 deletions files/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ web-ui:
# web-ui
# USERNAME: 前端管理用户名
# PASSWORD: 前端管理密码
USERNAME: admin
USERNAME: root
PASSWORD: 123456
pix:
# PIX图库
Expand Down Expand Up @@ -304,7 +304,7 @@ search_image:
# MAX_FIND_IMAGE_COUNT: 识图返回的最大结果数
# API_KEY: Saucenao的API_KEY,通过 https://saucenao.com/user.php?page=search-api 注册获取
MAX_FIND_IMAGE_COUNT: 3
API_KEY: d16d3ef7dacc5898e79343f16e3eaf8f34371b5e
API_KEY: qqqqqq
coser:
# coser
# WITHDRAW_COS_MESSAGE: 自动撤回,参1:延迟撤回色图时间(秒),0 为关闭 | 参2:监控聊天类型,0(私聊) 1(群聊) 2(群聊+私聊)
Expand Down
8 changes: 6 additions & 2 deletions files/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#! /bin/bash
set -e

#只是判断了,没有做出回应,等一个有缘人帮我完善
if [ ! "$bot_qq" ];then
echo -e "未设置bot使用的QQ号"
Expand All @@ -12,22 +11,27 @@ if [ ! "$admin_qq" ];then
echo -e "未设置超级管理员QQ号"
fi

. ./config.sh || echo -e "不是第一次运行,不导入变量"
. ./config.sh || echo -e "不是第一次运行,不进行设置"
rm -f ./config.sh

/etc/init.d/postgresql start
echo -e "postgresql 开始运行✔"
sleep 2s

cd /home/go-cqhttp
nohup ./go-cqhttp -faststart >> gocq.log 2>&1 &
echo -e "go-cqhttp 开始运行✔,详细日志请到/home/go-cqhttp/gocq.log查看"
sleep 2s

cd /home/zhenxun_bot_webui
nohup yarn run serve >> webui.log 2>&1 &
echo -e "web-ui 开始运行✔,详细日志请到/home/zhenxun_bot_webui/webui.log查看"
sleep 2s

cd /home/zhenxun_bot
echo -e "准备启动bot"
sleep 2s

python ./bot.py

exec $@

0 comments on commit ddc4e94

Please sign in to comment.