Skip to content

Instantly share code, notes, and snippets.

@dmontagu
Last active October 12, 2021 03:33
Show Gist options
  • Save dmontagu/f7bb7db40e63f5bc6304ceba54604c89 to your computer and use it in GitHub Desktop.
Save dmontagu/f7bb7db40e63f5bc6304ceba54604c89 to your computer and use it in GitHub Desktop.
Elasticsearch config files for use with FastAPI generated project
version: '3.3'
services:
db:
volumes:
- app-db-data:/var/lib/postgresql/data/pgdata
deploy:
placement:
constraints:
- node.labels.${STACK_NAME}.app-db-data == true
es01:
volumes:
- app-es-data-01:/usr/share/elasticsearch/data
deploy:
placement:
constraints:
- node.labels.${STACK_NAME}.app-es-data-01 == true
es02:
volumes:
- app-es-data-02:/usr/share/elasticsearch/data
deploy:
placement:
constraints:
- node.labels.${STACK_NAME}.app-es-data-02 == true
proxy:
deploy:
placement:
constraints:
- node.role == manager
volumes:
app-db-data:
app-es-data-01:
driver: local
app-es-data-02:
driver: local
version: '3.3'
services:
db:
image: postgres:11
es01:
image: elasticsearch:7.0.1
es02:
image: elasticsearch:7.0.1
version: '3.3'
services:
backend:
depends_on:
- db
- es01
- es02
version: '3.3'
services:
db:
env_file:
- env-postgres.env
environment:
- PGDATA=/var/lib/postgresql/data/pgdata
es01:
environment:
- node.name=es01
- cluster.initial_master_nodes=es01,es02
- discovery.seed_hosts=es02
env_file:
- env-elasticsearch.env
ulimits:
memlock:
soft: -1
hard: -1
es02:
environment:
- node.name=es02
- cluster.initial_master_nodes=es01,es02
- discovery.seed_hosts=es01
env_file:
- env-elasticsearch.env
ulimits:
memlock:
soft: -1
hard: -1
backend:
env_file:
- env-postgres.env
- env-backend.env
- env-elasticsearch.env
environment:
- SERVER_NAME=${DOMAIN}
- SERVER_HOST=https://${DOMAIN}
from elasticsearch import Elasticsearch
from elasticsearch_async import AsyncElasticsearch
from app.core import config
ES_HOST = f"{config.elasticsearch_server}:{config.elasticsearch_port}"
def get_elasticsearch() -> Elasticsearch:
return Elasticsearch(hosts=[ES_HOST])
def get_async_elasticsearch(loop=None) -> AsyncElasticsearch:
return AsyncElasticsearch(hosts=[ES_HOST], loop=loop)
# Used by elasticsearch service
cluster.name=docker-cluster
bootstrap.memory_lock=true
"ES_JAVA_OPTS=-Xms512m -Xmx512m"
# Used by backend service
ELASTICSEARCH_SERVER=es01
ELASTICSEARCH_PORT=9200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment