Skip to content

Commit eda6cbc

Browse files
Faraz32123Muhammad Faraz  Maqsood
authored andcommitted
feat: add Elasticsearch support in tutor-discovery (#89)
- As Tutor and Open edX have shifted to Meilisearch, and course-discovery still depends on Elasticsearch, running the Elasticsearch container with tutor-discovery will facilitate smoother operation for the course-discovery service. - It's related PR from tutor: overhangio/tutor#1141. Co-authored-by: Muhammad Faraz Maqsood <[email protected]>
1 parent e64a071 commit eda6cbc

12 files changed

+132
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [Feature] Add Elasticsearch support in tutor-discovery. As Tutor and Open edX have shifted to Meilisearch, and course-discovery still depends on Elasticsearch, running the Elasticsearch container with tutor-discovery will facilitate smoother operation for the course-discovery service. (by @Faraz32123)
2+
- It's related PR from tutor: https://github.com/overhangio/tutor/pull/1141.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DISCOVERY_RUN_ELASTICSEARCH = {{ DISCOVERY_RUN_ELASTICSEARCH }}

tutordiscovery/patches/k8s-deployments

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,54 @@ spec:
3232
- name: settings
3333
configMap:
3434
name: discovery-settings
35+
36+
{% if DISCOVERY_RUN_ELASTICSEARCH %}
37+
---
38+
apiVersion: apps/v1
39+
kind: Deployment
40+
metadata:
41+
name: elasticsearch
42+
labels:
43+
app.kubernetes.io/name: elasticsearch
44+
spec:
45+
selector:
46+
matchLabels:
47+
app.kubernetes.io/name: elasticsearch
48+
strategy:
49+
type: Recreate
50+
template:
51+
metadata:
52+
labels:
53+
app.kubernetes.io/name: elasticsearch
54+
spec:
55+
securityContext:
56+
runAsUser: 1000
57+
runAsGroup: 1000
58+
fsGroup: 1000
59+
fsGroupChangePolicy: "OnRootMismatch"
60+
containers:
61+
- name: elasticsearch
62+
image: {{ DISCOVERY_DOCKER_IMAGE_ELASTICSEARCH }}
63+
env:
64+
- name: cluster.name
65+
value: "openedx"
66+
- name: bootstrap.memory_lock
67+
value: "true"
68+
- name: discovery.type
69+
value: "single-node"
70+
- name: ES_JAVA_OPTS
71+
value: "-Xms{{ DISCOVERY_ELASTICSEARCH_HEAP_SIZE }} -Xmx{{ DISCOVERY_ELASTICSEARCH_HEAP_SIZE }}"
72+
- name: TAKE_FILE_OWNERSHIP
73+
value: "1"
74+
ports:
75+
- containerPort: 9200
76+
securityContext:
77+
allowPrivilegeEscalation: false
78+
volumeMounts:
79+
- mountPath: /usr/share/elasticsearch/data
80+
name: data
81+
volumes:
82+
- name: data
83+
persistentVolumeClaim:
84+
claimName: elasticsearch
85+
{% endif %}

tutordiscovery/patches/k8s-jobs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ spec:
2323
- name: settings
2424
configMap:
2525
name: discovery-settings
26-

tutordiscovery/patches/k8s-services

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,19 @@ spec:
1010
protocol: TCP
1111
selector:
1212
app.kubernetes.io/name: discovery
13+
{% if DISCOVERY_RUN_ELASTICSEARCH %}
14+
---
15+
apiVersion: v1
16+
kind: Service
17+
metadata:
18+
name: elasticsearch
19+
labels:
20+
app.kubernetes.io/name: elasticsearch
21+
spec:
22+
type: ClusterIP
23+
ports:
24+
- port: 9200
25+
protocol: TCP
26+
selector:
27+
app.kubernetes.io/name: elasticsearch
28+
{% endif %}

tutordiscovery/patches/k8s-volumes

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% if DISCOVERY_RUN_ELASTICSEARCH %}
2+
---
3+
apiVersion: v1
4+
kind: PersistentVolumeClaim
5+
metadata:
6+
name: elasticsearch
7+
labels:
8+
app.kubernetes.io/component: volume
9+
app.kubernetes.io/name: elasticsearch
10+
spec:
11+
accessModes:
12+
- ReadWriteOnce
13+
resources:
14+
requests:
15+
storage: 2Gi
16+
{% endif %}

tutordiscovery/patches/local-docker-compose-dev-services

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ discovery:
1515
default:
1616
aliases:
1717
- "{{ DISCOVERY_HOST }}"
18+
19+
{% if DISCOVERY_RUN_ELASTICSEARCH and is_docker_rootless() %}
20+
elasticsearch:
21+
ulimits:
22+
memlock:
23+
# Fixes error setting rlimits for ready process in rootless docker
24+
soft: 0 # zero means "unset" in the memlock context
25+
hard: 0
26+
{% endif %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% if DISCOVERY_RUN_ELASTICSEARCH %}setowner 1000 /mounts/elasticsearch{% endif %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% if DISCOVERY_RUN_ELASTICSEARCH %}- ../../data/elasticsearch:/mounts/elasticsearch{% endif %}

tutordiscovery/patches/local-docker-compose-services

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,28 @@ discovery:
66
volumes:
77
- ../plugins/discovery/apps/settings/tutor:/openedx/discovery/course_discovery/settings/tutor:ro
88
- ../../data/discovery/media:/openedx/discovery/course_discovery/media
9+
{% if DISCOVERY_RUN_ELASTICSEARCH %}- ../../data/elasticsearch:/mounts/elasticsearch{% endif %}
910
depends_on:
1011
- lms
1112
{% if RUN_MYSQL %}- mysql{% endif %}
12-
{% if RUN_ELASTICSEARCH %}- elasticsearch{% endif %}
13+
{% if DISCOVERY_RUN_ELASTICSEARCH %}- elasticsearch{% endif %}
14+
15+
{% if DISCOVERY_RUN_ELASTICSEARCH -%}
16+
elasticsearch:
17+
image: {{ DISCOVERY_DOCKER_IMAGE_ELASTICSEARCH }}
18+
environment:
19+
- cluster.name=openedx
20+
- bootstrap.memory_lock=true
21+
- discovery.type=single-node
22+
- "ES_JAVA_OPTS=-Xms{{ DISCOVERY_ELASTICSEARCH_HEAP_SIZE }} -Xmx{{ DISCOVERY_ELASTICSEARCH_HEAP_SIZE }}"
23+
ulimits:
24+
memlock:
25+
soft: -1
26+
hard: -1
27+
restart: unless-stopped
28+
user: "1000:1000"
29+
volumes:
30+
- ../../data/elasticsearch:/usr/share/elasticsearch/data
31+
depends_on:
32+
- permissions
33+
{%- endif %}

tutordiscovery/plugin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
"EXTRA_PIP_REQUIREMENTS": [],
3737
"REPOSITORY": "https://github.com/openedx/course-discovery.git",
3838
"REPOSITORY_VERSION": "{{ OPENEDX_COMMON_VERSION }}",
39+
"RUN_ELASTICSEARCH": True,
40+
"DOCKER_IMAGE_ELASTICSEARCH": "docker.io/elasticsearch:7.17.13",
41+
"ELASTICSEARCH_HOST": "elasticsearch",
42+
"ELASTICSEARCH_PORT": 9200,
43+
"ELASTICSEARCH_SCHEME": "http",
44+
"ELASTICSEARCH_HEAP_SIZE": "1g",
3945
},
4046
"unique": {
4147
"MYSQL_PASSWORD": "{{ 8|random_string }}",

tutordiscovery/templates/discovery/apps/settings/partials/common.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@
2020
}
2121
}
2222

23+
DISCOVERY_DOCKER_IMAGE_ELASTICSEARCH = "{{ DISCOVERY_DOCKER_IMAGE_ELASTICSEARCH }}"
24+
DISCOVERY_ELASTICSEARCH_HOST = "{{ DISCOVERY_ELASTICSEARCH_HOST }}"
25+
DISCOVERY_ELASTICSEARCH_PORT = "{{ DISCOVERY_ELASTICSEARCH_PORT }}"
26+
DISCOVERY_ELASTICSEARCH_SCHEME = "{{ DISCOVERY_ELASTICSEARCH_SCHEME }}"
27+
DISCOVERY_ELASTICSEARCH_HEAP_SIZE = "{{ DISCOVERY_ELASTICSEARCH_HEAP_SIZE }}"
28+
2329
ELASTICSEARCH_DSL['default'].update({
24-
'hosts': "{{ ELASTICSEARCH_SCHEME }}://{{ ELASTICSEARCH_HOST }}:{{ ELASTICSEARCH_PORT }}/"
30+
'hosts': "{{ DISCOVERY_ELASTICSEARCH_SCHEME }}://{{ DISCOVERY_ELASTICSEARCH_HOST }}:{{ DISCOVERY_ELASTICSEARCH_PORT }}/"
2531
})
2632

2733
{% for name, index in DISCOVERY_INDEX_OVERRIDES.items() %}

0 commit comments

Comments
 (0)