mirror of
https://github.com/simon987/od-database.git
synced 2025-04-10 14:06:45 +00:00
docker-compose setup (wip)
This commit is contained in:
parent
df8ab7727b
commit
7f121d2ac0
4
app.py
4
app.py
@ -1,6 +1,3 @@
|
|||||||
import time
|
|
||||||
time.sleep(60)
|
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
||||||
import api
|
import api
|
||||||
@ -12,7 +9,6 @@ app = Flask(__name__)
|
|||||||
app.secret_key = config.FLASK_SECRET
|
app.secret_key = config.FLASK_SECRET
|
||||||
template_filters.setup_template_filters(app)
|
template_filters.setup_template_filters(app)
|
||||||
|
|
||||||
|
|
||||||
views.setup_views(app)
|
views.setup_views(app)
|
||||||
api.setup_api(app)
|
api.setup_api(app)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
version: "3"
|
version: "2.1"
|
||||||
services:
|
services:
|
||||||
oddb:
|
oddb:
|
||||||
image: simon987/od-database
|
image: simon987/od-database
|
||||||
@ -23,9 +23,14 @@ services:
|
|||||||
- "RECRAWL_POOL_SIZE=10000"
|
- "RECRAWL_POOL_SIZE=10000"
|
||||||
- "INDEXER_THREADS=2"
|
- "INDEXER_THREADS=2"
|
||||||
depends_on:
|
depends_on:
|
||||||
- wsb
|
wsb:
|
||||||
- tt
|
condition: service_started
|
||||||
- es
|
tt:
|
||||||
|
condition: service_started
|
||||||
|
oddb_db:
|
||||||
|
condition: service_healthy
|
||||||
|
es:
|
||||||
|
condition: service_healthy
|
||||||
restart: always
|
restart: always
|
||||||
oddb_db:
|
oddb_db:
|
||||||
image: postgres
|
image: postgres
|
||||||
@ -71,22 +76,20 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- 3010:80
|
- 3010:80
|
||||||
depends_on:
|
depends_on:
|
||||||
- tt_db
|
tt_db:
|
||||||
|
condition: service_healthy
|
||||||
es:
|
es:
|
||||||
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.2
|
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.2
|
||||||
environment:
|
environment:
|
||||||
# - bootstrap.memory_lock=true
|
|
||||||
- discovery.type=single-node
|
- discovery.type=single-node
|
||||||
# - index.number_of_shards=50
|
- "ES_JAVA_OPTS=-Xms1G -Xmx10G"
|
||||||
# - index.number_of_replicas=0
|
|
||||||
# - "ES_JAVA_OPTS=-Xms1G -Xmx10G"
|
|
||||||
volumes:
|
volumes:
|
||||||
- /usr/share/elasticsearch/data
|
- /usr/share/elasticsearch/data
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
|
test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
|
||||||
interval: 30s
|
interval: 5s
|
||||||
timeout: 30s
|
timeout: 5s
|
||||||
retries: 3
|
retries: 5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,9 +2,8 @@ import os
|
|||||||
import time
|
import time
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
import ujson
|
|
||||||
|
|
||||||
import elasticsearch
|
import elasticsearch
|
||||||
|
import ujson
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
from elasticsearch import helpers
|
from elasticsearch import helpers
|
||||||
|
|
||||||
@ -49,28 +48,29 @@ class ElasticSearchEngine:
|
|||||||
logger.info("Elasticsearch first time setup")
|
logger.info("Elasticsearch first time setup")
|
||||||
if self.es.indices.exists(self.index_name):
|
if self.es.indices.exists(self.index_name):
|
||||||
self.es.indices.delete(index=self.index_name)
|
self.es.indices.delete(index=self.index_name)
|
||||||
self.es.indices.create(index=self.index_name)
|
self.es.indices.create(index=self.index_name, body={
|
||||||
self.es.indices.close(index=self.index_name)
|
"settings": {
|
||||||
|
"index": {
|
||||||
# Index settings
|
"number_of_shards": 50,
|
||||||
self.es.indices.put_settings(body={
|
"number_of_replicas": 0,
|
||||||
"index": {
|
"refresh_interval": "30s",
|
||||||
"refresh_interval": "30s",
|
"codec": "best_compression"
|
||||||
"codec": "best_compression"
|
|
||||||
},
|
|
||||||
"analysis": {
|
|
||||||
"analyzer": {
|
|
||||||
"my_nGram": {
|
|
||||||
"tokenizer": "my_nGram_tokenizer",
|
|
||||||
"filter": ["lowercase", "asciifolding"]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"tokenizer": {
|
"analysis": {
|
||||||
"my_nGram_tokenizer": {
|
"analyzer": {
|
||||||
"type": "nGram", "min_gram": 3, "max_gram": 3
|
"my_nGram": {
|
||||||
|
"tokenizer": "my_nGram_tokenizer",
|
||||||
|
"filter": ["lowercase", "asciifolding"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tokenizer": {
|
||||||
|
"my_nGram_tokenizer": {
|
||||||
|
"type": "nGram", "min_gram": 3, "max_gram": 3
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}, index=self.index_name)
|
}
|
||||||
|
})
|
||||||
|
|
||||||
# Index Mappings
|
# Index Mappings
|
||||||
self.es.indices.put_mapping(body={
|
self.es.indices.put_mapping(body={
|
||||||
|
@ -26,12 +26,8 @@
|
|||||||
<form action="/search" id="sfrm">
|
<form action="/search" id="sfrm">
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="col-md-11">
|
<input class="form-control" style="max-width: calc(100% - 80px);" name="q" id="q" placeholder="Query">
|
||||||
<input class="form-control" name="q" id="q" placeholder="Query">
|
<input class="btn btn-primary btn-shadow" type="submit" value="Search" style="margin-left: 3px">
|
||||||
</div>
|
|
||||||
<div class="col-md-1">
|
|
||||||
<input class="btn btn-primary btn-shadow" type="submit" value="Search">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{% if show_captcha %}
|
{% if show_captcha %}
|
||||||
{{ captcha.get_code()|safe }}
|
{{ captcha.get_code()|safe }}
|
||||||
|
14
views.py
14
views.py
@ -3,19 +3,24 @@ import os
|
|||||||
from multiprocessing.pool import Pool
|
from multiprocessing.pool import Pool
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from flask import render_template, redirect, request, flash, abort, Response, session
|
||||||
|
from flask_caching import Cache
|
||||||
|
|
||||||
import captcha
|
import captcha
|
||||||
import config
|
import config
|
||||||
import od_util
|
import od_util
|
||||||
from common import db, taskManager, searchEngine, logger, require_role
|
from common import db, taskManager, searchEngine, logger, require_role
|
||||||
from database import Website
|
from database import Website
|
||||||
from flask import render_template, redirect, request, flash, abort, Response, session
|
|
||||||
from flask_caching import Cache
|
|
||||||
from search.search import InvalidQueryException
|
from search.search import InvalidQueryException
|
||||||
from tasks import Task
|
from tasks import Task
|
||||||
|
|
||||||
|
|
||||||
def setup_views(app):
|
def setup_views(app):
|
||||||
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
|
cache = Cache(app, config={
|
||||||
|
"CACHE_TYPE": "redis",
|
||||||
|
"CACHE_REDIS_HOST": config.REDIS_HOST,
|
||||||
|
"CACHE_REDIS_PORT": config.REDIS_PORT,
|
||||||
|
})
|
||||||
|
|
||||||
@app.route("/dl")
|
@app.route("/dl")
|
||||||
@cache.cached(120)
|
@cache.cached(120)
|
||||||
@ -207,7 +212,8 @@ def setup_views(app):
|
|||||||
flash("Query failed, this could mean that the search server is overloaded or is not reachable. "
|
flash("Query failed, this could mean that the search server is overloaded or is not reachable. "
|
||||||
"Please try again later", "danger")
|
"Please try again later", "danger")
|
||||||
|
|
||||||
results = hits["hits"]["total"]["value"] if not isinstance(hits["hits"]["total"], int) else hits["hits"]["total"] if hits else -1
|
results = hits["hits"]["total"]["value"] if not isinstance(hits["hits"]["total"], int) else \
|
||||||
|
hits["hits"]["total"] if hits else -1
|
||||||
took = hits["took"] if hits else -1
|
took = hits["took"] if hits else -1
|
||||||
forwarded_for = request.headers["X-Forwarded-For"] if "X-Forwarded-For" in request.headers else None
|
forwarded_for = request.headers["X-Forwarded-For"] if "X-Forwarded-For" in request.headers else None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user