koishijs / koishi

Cross-platform chatbot framework made with love
https://koishi.chat
MIT License
4.5k stars 247 forks source link

BUG: Official Docker image failed to start #261

Closed purerosefallen closed 2 years ago

purerosefallen commented 3 years ago

Describe the bug

As the title says.

➜  nginx docker-compose logs -f koishijs
Attaching to nginx_koishijs_1
koishijs_1               | [E] app Error: cannot resolve adapter onebot
koishijs_1               |         at loadEcosystem (/app/node_modules/koishi/lib/worker.js:100:9)
koishijs_1               |         at loadAdapter (/app/node_modules/koishi/lib/worker.js:139:3)
koishijs_1               |         at Array.forEach (<anonymous>)
koishijs_1               |         at Object.<anonymous> (/app/node_modules/koishi/lib/worker.js:144:15)
koishijs_1               |         at Module._compile (internal/modules/cjs/loader.js:1063:30)
koishijs_1               |         at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
koishijs_1               |         at Module.load (internal/modules/cjs/loader.js:928:32)
koishijs_1               |         at Function.Module._load (internal/modules/cjs/loader.js:769:14)
koishijs_1               |         at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
koishijs_1               |         at internal/main/run_main_module.js:17:47
koishijs_1               | [E] app Error: cannot resolve adapter onebot
koishijs_1               |         at loadEcosystem (/app/node_modules/koishi/lib/worker.js:100:9)
koishijs_1               |         at loadAdapter (/app/node_modules/koishi/lib/worker.js:139:3)
koishijs_1               |         at Array.forEach (<anonymous>)
koishijs_1               |         at Object.<anonymous> (/app/node_modules/koishi/lib/worker.js:144:15)
koishijs_1               |         at Module._compile (internal/modules/cjs/loader.js:1063:30)
koishijs_1               |         at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
koishijs_1               |         at Module.load (internal/modules/cjs/loader.js:928:32)
koishijs_1               |         at Function.Module._load (internal/modules/cjs/loader.js:769:14)
koishijs_1               |         at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
koishijs_1               |         at internal/main/run_main_module.js:17:47

To Reproduce

docker-compose.yml

version: '2.4'
services:
  cqhttp:
    restart: always
    image: git-registry.mycard.moe/nanahira/docker-mirai-cqhttp:novnc
    volumes:
      - ./cq/data:/usr/src/app/data
      - ./cq/config:/usr/src/app/config
      - ./cq/bots:/usr/src/app/bots
    ports:
      - 44481:8080
    environment:
      QQ_ID: 11111111
      QQ_PASS: bbbbbbb
      WS_TOKEN: aaaaaaaaaa
      WS_PORT: 80
      VNC_PASS: ccccccc
  koishijs:
    restart: always
    image: koishijs/koishi
    volumes:
      - ./koishi-plugins:/plugins:ro
      - ./koishi.config.js:/app/koishi.config.js:ro

koishi.config.js

module.exports = {
  bots: [{
    type: 'onebot:ws',
    server: 'ws://server',
    selfId: 11111111,
    token: 'aaaaaaaaaa',
  }],
  plugins: {
    // some plugins
  },
}

Expected behavior

It should start..

Screenshots

Versions

Additional context

NN708 commented 3 years ago

Hello @purerosefallen,

It seems that you are trying to use OneBot protocol. Have you installed koishi-adapter-onebot in the Koishi Docker container properly? Here is some information on Koishi website.

purerosefallen commented 3 years ago

@NN708 Yeah but I believe it should be a bug in dockerfile or something else. The docker image should be somewhere to let me install the adapter. In addition, the above documentation says nothing about adapter or how to install it.

Updated: I just saw the instruction, to let me exec in, and install the plugins and adapters. However, I don't think it's a good idea, for the adapters and plugins would be lost after another docker-compose up -d or container recreation.

purerosefallen commented 3 years ago

In addition, ´sudo npm -g install koishi-adapter-onebot´ does not work. The only way to run it in command line is, to ´koishi init´, install the adapter in, and ´npm start´.

NN708 commented 3 years ago

In addition, ´sudo npm -g install koishi-adapter-onebot´ does not work. The only way to run it in command line is, to ´koishi init´, install the adapter in, and ´npm start´.

Plugins and adapters should be installed in the same way. In Docker container, they should be installed locally in the /app directory, not globally.

I just saw the instruction, to let me exec in, and install the plugins and adapters. However, I don't think it's a good idea, for the adapters and plugins would be lost after another docker-compose up -d or container recreation.

You can use volumes for /app/node_modules to persist them. If you think the documentation is not very clear, you may help us to improve it.

purerosefallen commented 3 years ago

When I mount /app/node_modules, the following strange thing would happen. With the above docker-compose, when I:

  1. launch the container with /app/node_modules volumed.
  2. docker-compose exec koishijs npm install koishi-plugin-common koishi-adapter-onebot
  3. edit the config, and then docker-compose up restart koishijs
  4. The bot started. but...
  5. I want another plugin, for example, koishi-plugin-webui, to be installed, with additional web console ports exposed. so I docker-compose exec koishijs npm install koishi-plugin-webui
  6. edit the config, and docker-compose up -d koishijs, in which the container recreated.

It said adapter missing again. With a careful check in node_modules directory, it could be found that koishi-plugin-commonandkoishi-adapter-onebot` are missing again.

It seemed that npm would remove everything not written in package.json file.. However, if I also volume package.json it would become directory with the name package.json file.

Any better solution?

NN708 commented 3 years ago

You're right, package.json also needs to be persistent.

However, if I also volume package.json it would become directory with the name package.json file.

I think you should first place the original file on your host machine, then use docker-compose to create the containers.

shigma commented 2 years ago

close in favor of @koishijs/plugin-manager