Skip to content

Commit

Permalink
Merge pull request #4 from t-sagara/develop
Browse files Browse the repository at this point in the history
Merge Develop
  • Loading branch information
t-sagara committed Mar 27, 2024
2 parents 35e8f2f + d35d27f commit 61e3561
Show file tree
Hide file tree
Showing 13 changed files with 658 additions and 476 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Expand Up @@ -17,7 +17,7 @@
"module": "flask",
"env": {
"FLASK_APP": "app.py",
"FLASK_DEBUG": "1"
"FLASK_DEBUG": "1",
},
"args": [
"run",
Expand Down
49 changes: 30 additions & 19 deletions README.md
Expand Up @@ -14,48 +14,51 @@

# 利用手順

- [GitHub](https://github.com/t-sagara/jageocoder-server) から最新の
コードを clone, または ZIP ファイルをダウンロードしてください。
- [GitHub](https://github.com/t-sagara/jageocoder-server) から
最新のコードを clone, または ZIP ファイルをダウンロードしてください。
- 任意の場所に展開し、ターミナル (Windows の場合は PowerShell) で
この README.md ファイルがあるディレクトリを開いてください。
この README.md ファイルがあるディレクトリを開いてください。

## Docker を利用する場合

- [Docker Engine](https://docs.docker.com/engine/) または
[Docker Desktop](https://www.docker.com/products/docker-desktop/) が必要です。
[Docker Desktop](https://www.docker.com/products/docker-desktop/) が必要です。

- インストールする辞書をセットします。

- [データファイル一覧](https://www.info-proto.com/static/jageocoder/latest/v2/)
からダウンロードし、`data/` に配置してください。
- data ディレクトリには他の zip ファイルは置かないでください。
からダウンロードし、`data/` に配置してください。

- サーバ設定
- data ディレクトリの zip ファイルの中で、更新日時が最も新しいものがインストールされます。

`docker-compose.yml``environment:` 以下の行で
サーバの設定を行うことができます。
- サーバ設定の設定を確認します。

`docker-compose.yml``environment:` 以下の行でサーバの設定を行うことができます。

- `SITE_MESSAGE`: サーバに表示する文字列を設定できます。

- `LAN_MODE`: 1 にすると、地図表示のために地理院地図サーバに
アクセスするといった外部ネットワークへの通信を行いません。
アクセスするといった外部ネットワークへの通信を行いません。

- `BUILD_RTREE`: 1 にすると、リバースジオコーディング機能に
必要なインデックスを初回起動時に構築します。
必要なインデックスを初回起動時に構築します。

- 以下の手順でコンテナを作成し、実行します。

$ docker compose build
$ docker compose up -d

初回インストール時には辞書のインストールを行います。
初回起動時、または新しい辞書ファイルが配置された場合には、
自動的に辞書のインストールを行います。

所要時間は辞書のサイズやコンピュータの性能にもよりますが、
たとえば全国の住居表示レベルの場合は 1 分間程度かかります。

`BUILD_RTREE` を 1 にした場合、リバースジオコーディング用の
R-tree インデックスも構築します。こちらは 10 分間以上かかります。

`data/init.log` に進捗状況が出力されますので、 `All done.`
表示されるまでのんびりお待ちください
`data/init.log` に進捗状況が出力されますので、
`Starting server process...` と表示されるまでのんびりお待ちください

- ブラウザで `http://localhost:5000/` にアクセスしてご利用ください。

Expand All @@ -68,9 +71,16 @@

$ docker compose up -d

- 辞書を更新するには、 `data/` に新しい辞書ファイルを置いてから、
コンテナを再起動してください。

$ docker compose down
$ docker compose up -d

- もう利用しない場合はアンインストールしてください。

完全にアンインストールするには Volume も削除してください。
完全にアンインストールするには `-v` オプションを指定して
辞書がインストールされている Volume も削除します。

$ docker compose down -v
$ docker system prune
Expand All @@ -95,18 +105,19 @@
辞書がインストールされているディレクトリを環境変数 `JAGEOCODER_DB2_DIR`
セットしてください。

インストールされていない場合は [データファイル一覧](https://www.info-proto.com/static/jageocoder/latest/v2/)
インストールされていない場合や新しい辞書に更新したい場合は
[データファイル一覧](https://www.info-proto.com/static/jageocoder/latest/v2/)
から適切なデータファイルをダウンロードして、次のコマンドでインストールしてください。

$ python -m jageocoder install-dictionary <データファイルzip>
$ jageocoder install-dictionary <データファイルzip>
(例)
$ python -m jageocoder install-dictionary jukyo_all_v20.zip
$ jageocoder install-dictionary jukyo_all_v20.zip

リバースジオコーディング機能を利用したい場合は、
R-tree インデックスを構築しておく必要があります。
以下のコマンドを実行してインデックスを構築してください。

$ python -m jageocoder reverse 140.0 35.0
$ jageocoder reverse 140.0 35.0

サーバを起動中に R-tree インデックスを構築した場合、
一度サーバを Ctrl+C で停止して、再度起動してください。
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
@@ -1,5 +1,3 @@
version: "3.9"

services:
jageocoder-server:
container_name: jageocoder-server
Expand Down
48 changes: 40 additions & 8 deletions entrypoint.sh
@@ -1,15 +1,47 @@
#!/bin/sh
#!/bin/bash

logfile="/data/init.log"
echo "Checking jageocoder dictionary..." > ${logfile}

# Search the most recent dictionary file
dicfile=$(ls -t /data/*.zip | head -n1)

# Check if jageocoder dictionary is installed
if [ ! -e "/opt/db2/address.trie" ]; then
echo "Initialize..." > /data/init.log
echo "Installing dictionary..." >> /data/init.log
jageocoder install-dictionary /data/*.zip >> /data/init.log 2>&1
do_install=false
triefile="/opt/db2/address.trie"
if [ ! -e "${triefile}" ]; then
echo " No dictionary is installed." >> ${logfile}
do_install=true
elif [ ! -z "${dicfile}" ] && [ "${dicfile}" -nt "${triefile}" ]; then
echo " The dictionary file is newer than the installed dictionary." >> ${logfile}
do_install=true
fi

if ${do_install} = true; then
if [ -z "${dicfile}" ]; then
echo "[NG] Please place the jageocoder dictionary file in the data directory." >> ${logfile}
exit 1
fi

echo " Installing dictionary from '${dicfile}'..." >> ${logfile}
jageocoder install-dictionary -y ${dicfile} >> ${logfile} 2>&1
if [ $? -ne 0 ]; then
echo "[NG] Dictionary installation failed." >> ${logfile}
exit 1
fi

if [ ${BUILD_RTREE} -ne 0 ] ; then
echo "Building R-tree for reverse geocoding..." >> /data/init.log
jageocoder reverse 140.0 35.0 >> /data/init.log 2>&1
echo " Building R-tree for reverse geocoding..." >> ${logfile}
jageocoder reverse 140.0 35.0 >> ${logfile} 2>&1
if [ $? -ne 0 ]; then
echo "[NG] R-tree build failed." >> ${logfile}
exit 1
fi
fi
echo "All done." >> /data/init.log
echo "[OK] The dictionary is installed successfully." >> ${logfile}
else
echo "[OK] The dictionary is already installed." >> ${logfile}
fi

echo "Starting server process..." >> ${logfile}
python run_waitress.py

0 comments on commit 61e3561

Please sign in to comment.