Dockerで動かせるようにする (#84)

* memory.jsonの保存先をdata以下にする

* Dockerで動くようにする

* 余計な空行を削除

* 余分なファイルをコンテナに追加しないようにする

* memory.jsonの保存先を変えられるようにする

* DockerでMeCabのインストールの有無を切り替えられるようにする
This commit is contained in:
ふるふる 2021-12-07 11:46:57 +09:00 committed by GitHub
parent a1c5dc8d56
commit 0837b63a60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 2 deletions

13
.dockerignore Normal file
View File

@ -0,0 +1,13 @@
config.json
font.ttf
ai.*
*.md
*.png
Dockerfile
docker-compose.yml
LICENSE
node_modules/
test/
data/
.vscode/

25
Dockerfile Normal file
View File

@ -0,0 +1,25 @@
FROM node:lts-bullseye
RUN apt-get update && apt-get install -y tini
ARG enable_mecab=1
RUN if [ $enable_mecab -ne 0 ]; then apt-get update \
&& apt-get install mecab libmecab-dev mecab-ipadic-utf8 make curl xz-utils file sudo --no-install-recommends -y \
&& apt-get clean \
&& rm -rf /var/lib/apt-get/lists/* \
&& cd /opt \
&& git clone --depth 1 https://github.com/neologd/mecab-ipadic-neologd.git \
&& cd /opt/mecab-ipadic-neologd \
&& ./bin/install-mecab-ipadic-neologd -n -y \
&& rm -rf /opt/mecab-ipadic-neologd \
&& echo "dicdir = /usr/lib/x86_64-linux-gnu/mecab/dic/mecab-ipadic-neologd/" > /etc/mecabrc \
&& apt-get purge git make curl xz-utils file -y; fi
COPY . /ai
WORKDIR /ai
RUN npm install && npm run build
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD npm start

View File

@ -20,11 +20,34 @@ Misskey用の日本語Botです。
"reversiEnabled": "藍とリバーシで対局できる機能を有効にする場合は true を入れる (無効にする場合は false)",
"serverMonitoring": "サーバー監視の機能を有効にする場合は true を入れる (無効にする場合は false)",
"mecab": "MeCab のインストールパス (ソースからインストールした場合、大体は /usr/local/bin/mecab)",
"mecabDic": "MeCab の辞書ファイルパス (オプション)"
"mecabDic": "MeCab の辞書ファイルパス (オプション)",
"memoryPath": "memory.jsonの保存先オプション、デフォルトは'.'(レポジトリのルートです))"
}
```
`npm install` して `npm run build` して `npm start` すれば起動できます
## Dockerで動かす
まず適当なディレクトリに `git clone` します。
次にそのディレクトリに `config.json` を作成します。中身は次のようにします:
MeCabの設定、memoryPathについては触らないでください
``` json
{
"host": "https:// + あなたのインスタンスのURL (末尾の / は除く)",
"i": "藍として動かしたいアカウントのアクセストークン",
"master": "管理者のユーザー名(オプション)",
"notingEnabled": "ランダムにノートを投稿する機能を無効にする場合は false を入れる",
"keywordEnabled": "キーワードを覚える機能 (MeCab が必要) を有効にする場合は true を入れる (無効にする場合は false)",
"chartEnabled": "チャート機能を無効化する場合は false を入れてください",
"reversiEnabled": "藍とリバーシで対局できる機能を有効にする場合は true を入れる (無効にする場合は false)",
"serverMonitoring": "サーバー監視の機能を有効にする場合は true を入れる (無効にする場合は false)",
"mecab": "/usr/bin/mecab",
"mecabDic": "/usr/lib/x86_64-linux-gnu/mecab/dic/mecab-ipadic-neologd/",
"memoryPath": "data"
}
```
`docker-compose build` して `docker-compose up` すれば起動できます。
`docker-compose.yml``enable_mecab``0` にすると、MeCabをインストールしないようにもできます。メモリが少ない環境など
## フォント
一部の機能にはフォントが必要です。藍にはフォントは同梱されていないので、ご自身でフォントをインストールディレクトリに`font.ttf`という名前で設置してください。

12
docker-compose.yml Normal file
View File

@ -0,0 +1,12 @@
version: '3'
services:
app:
build:
context: .
args:
- enable_mecab=1
volumes:
- './config.json:/ai/config.json:ro'
- './font.ttf:/ai/font.ttf:ro'
- './data:/ai/data'
restart: always

View File

@ -81,7 +81,12 @@ export default class 藍 {
this.account = account;
this.modules = modules;
const file = process.env.NODE_ENV === 'test' ? 'test.memory.json' : 'memory.json';
let memoryPath = './';
if (config.memoryPath)
{
memoryPath = config.memoryPath;
}
const file = process.env.NODE_ENV === 'test' ? `${memoryPath}/test.memory.json` : `${memoryPath}/memory.json`;
this.log(`Lodaing the memory from ${file}...`);

View File

@ -11,6 +11,7 @@ type Config = {
serverMonitoring: boolean;
mecab?: string;
mecabDic?: string;
memoryPath?: string;
};
const config = require('../config.json');