diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bca5d61 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM node:10.17.0-jessie + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y libodbc1 && npm install -g pm2 \ + && mkdir /data && cd /data \ + && wget -q --no-check-certificate https://repo.mongodb.org/apt/debian/dists/jessie/mongodb-org/3.2/main/binary-amd64/mongodb-org-server_3.2.10_amd64.deb \ + && wget -q --no-check-certificate https://sphinxsearch.com/files/sphinxsearch_2.3.2-beta-1~jessie_amd64.deb \ + && dpkg -i *.deb && rm -f *.deb \ + && sed -i 's/127.0.0.1/0.0.0.0/' /etc/mongod.conf + +ADD . /ssbc +WORKDIR /ssbc + +RUN chmod a+x /ssbc/entrypoint.sh \ + && cd spider && npm install && cd .. \ + && cd web && npm install && npm run build && cd .. \ + && mkdir -p /data/bt/index/db /data/bt/index/binlog + + +VOLUME ["/var/lib/mongodb"] +EXPOSE 27017 3001 6881/udp + +ENTRYPOINT ["/ssbc/entrypoint.sh"] + diff --git a/README.md b/README.md index 6439f20..2a69d33 100644 --- a/README.md +++ b/README.md @@ -89,11 +89,11 @@ mkdir -p /data/bt/index/db /data/bt/index/binlog 3. 初始化索引 -`` +``` cd spider indexer -c sphinx.conf hash searchd -c sphinx.conf -`` +``` ## 网站说明 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..0cf2172 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +/usr/bin/mongod --quiet --config /etc/mongod.conf --fork + +sleep 6 + +cd /ssbc/spider && pm2 start ecosystem.config.js && cd .. + +cd web && pm2 start ecosystem.config.js && cd .. + +trap 'kill $(pgrep searchd) 2>/dev/null; pm2 kill; kill $(pgrep mongod); exit 0' SIGINT SIGTERM + +sleep 3 & +wait + +cd spider +if [ ! -e /data/.inited ]; then + indexer -c sphinx.conf hash & + wait + echo 1 >/data/.inited +fi +searchd -c sphinx.conf && cd .. + +sleep infinity & +wait + diff --git a/spider/dump.js b/spider/dump.js index c16e91a..ff3fa3e 100644 --- a/spider/dump.js +++ b/spider/dump.js @@ -1,7 +1,7 @@ const MongoClient = require('mongodb').MongoClient const crc32 = require('buffer-crc32') -MongoClient.connect('mongodb://localhost:27017/admin', {useNewUrlParser: true}, (err, mconn) => { +MongoClient.connect('mongodb://localhost:27017/admin', {useNewUrlParser: true, useUnifiedTopology: true}, (err, mconn) => { if(err) { console.error(err) process.exit(1) diff --git a/web/ecosystem.config.js b/web/ecosystem.config.js index f165f47..d0aa9e9 100644 --- a/web/ecosystem.config.js +++ b/web/ecosystem.config.js @@ -4,6 +4,7 @@ module.exports = { script : "./server", env: { NODE_ENV: 'production', + HOST: '0.0.0.0', PORT: 3001, BASE_URL: 'http://127.0.0.1:3000' }