Skip to content

Commit 8aebfb1

Browse files
committed
feat: port to Typesense
Port the Meilisearch plugin from https://github.com/open-craft/tutor-contrib-meilisearch to Typesense. For now, only add support for an internally managed, single node Typesense server. Support for an external Typesense server or a clustered Typesense server group is being discussed. Also make some updates to related dev environment files: update the Makefile, add a mise.toml for convenience of setting up an virtual env, add a CI workflow, and some other small updates. Private-ref: https://tasks.opencraft.com/browse/BB-9972
1 parent 0b4c7d7 commit 8aebfb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+315
-299
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Run tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
tests:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: ['3.11', '3.12']
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: "${{ matrix.python-version }}"
23+
24+
- name: Install dependencies
25+
run: |
26+
# Shellcheck is already installed in the system by default.
27+
# Install python dependencies:
28+
make install
29+
30+
- name: Run tests
31+
run: make test

.gitignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
.DS_Store
2-
.*.swp
3-
!.gitignore
4-
TODO
51
__pycache__
62
*.egg-info/
7-
/build/
8-
/dist/

MANIFEST.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
recursive-include tutor_meili/patches *
2-
recursive-include tutor_meili/templates *
1+
recursive-include tutor_typesense/patches *
2+
recursive-include tutor_typesense/templates *

Makefile

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
.DEFAULT_GOAL := help
2-
.PHONY: docs
3-
SRC_DIRS = ./tutor_meili
4-
BLACK_OPTS = --exclude templates ${SRC_DIRS}
2+
.PHONY: test install format lint help
53

6-
# Warning: These checks are not necessarily run on every PR.
7-
test: test-lint test-types test-format # Run some static checks.
4+
test: lint ## Run all tests
85

9-
test-format: ## Run code formatting tests
10-
black --check --diff $(BLACK_OPTS)
6+
install: ## Install python dependencies (it's recommended to activate a virtualenv first)
7+
pip install -e .[dev]
8+
@which shellcheck > /dev/null || (echo "'shellcheck' is not available. Please manually install shellcheck to run tests." && exit 1)
119

12-
test-lint: ## Run code linting tests
13-
pylint --errors-only --enable=unused-import,unused-argument --ignore=templates --ignore=docs/_ext ${SRC_DIRS}
14-
15-
test-types: ## Run type checks.
16-
mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict ${SRC_DIRS}
10+
lint: ## Run code linting tests
11+
black --check --diff tutor_typesense
12+
pylint --errors-only --enable=unused-import,unused-argument --ignore=templates --ignore=docs/_ext tutor_typesense
13+
mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict tutor_typesense
14+
shellcheck tutor_typesense/templates/typesense/tasks/typesense/init.sh
1715

1816
format: ## Format code automatically
19-
black $(BLACK_OPTS)
20-
21-
isort: ## Sort imports. This target is not mandatory because the output may be incompatible with black formatting. Provided for convenience purposes.
22-
isort --skip=templates ${SRC_DIRS}
23-
24-
changelog-entry: ## Create a new changelog entry.
25-
scriv create
26-
27-
changelog: ## Collect changelog entries in the CHANGELOG.md file.
28-
scriv collect
17+
isort tutor_typesense
18+
black tutor_typesense
2919

3020
ESCAPE = 
3121
help: ## Print this help

README.rst

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,87 @@
1-
Meilisearch for Open edX (Tutor Plugin)
1+
Typesense for Open edX (Tutor Plugin)
22
=======================================
33

4-
This is a plugin for `Tutor <https://docs.tutor.edly.io>`_ 18 (Open edX "Redwood" release) that provides Meilisearch to the platform, so it can be used as a search engine to power content search.
5-
6-
⭐️ This plugin isn't needed with Tutor 19+ (Open edX Sumac+), as `Meilisearch functionality is now built in <https://github.com/overhangio/tutor/pull/1141>`_. ⭐️
4+
This is a plugin for `Tutor <https://docs.tutor.edly.io>`_ 20 (Open edX "Teak" release) that provides Typesense to the platform, so it can be used as a search engine to power content search.
75

86
Installation
97
------------
108

119
Currently, you need to clone this repo from GitHub then install it into your tutor virtual environment with::
1210

13-
pip install -e ./tutor-contrib-meilisearch
11+
pip install -e ./tutor-contrib-typesense
1412

1513
Then, to enable this plugin, run::
1614

17-
tutor plugins enable meilisearch
15+
tutor plugins enable typesense
1816

1917
If you have an already running platform, initialize this plugin with a command like the following::
2018

21-
tutor [local|dev|k8s] do init --limit=meilisearch
19+
tutor [local|dev|k8s] do init --limit=typesense
2220

2321
Or use ``tutor [local|dev|k8s] launch -I`` to re-launch the platform (takes much longer).
2422

2523
Configuration
2624
-------------
2725

28-
- ``MEILISEARCH_INDEX_PREFIX`` (default: ``"tutor_"``)
29-
- ``MEILISEARCH_PUBLIC_HOST`` (default: ``"meilisearch.{{ LMS_HOST }}"``)
30-
- ``MEILISEARCH_DOCKER_IMAGE`` (default: ``"docker.io/getmeili/meilisearch:v1.8``)
31-
- ``MEILISEARCH_MASTER_KEY`` The master key. Only required to generate the API key (default: auto-generated).
32-
- ``MEILISEARCH_API_KEY`` The API key (or tenant key) to use for this Open edX instance (default: auto-generated using the master key).
26+
- ``TYPESENSE_COLLECTION_PREFIX`` (default: ``"tutor_"``)
27+
- ``TYPESENSE_PUBLIC_HOST`` (default: ``"typesense.{{ LMS_HOST }}"``)
28+
- ``TYPESENSE_DOCKER_IMAGE`` (default: ``"docker.io/typesense/typesense:29.0"``)
29+
- ``TYPESENSE_BOOTSTRAP_API_KEY`` The initial admin API key to use when bootstrapping the Typesense server and to generate an api key for Open edX (default: auto-generated).
30+
- ``TYPESENSE_API_KEY`` The API key used by Open edX (default: auto-generated).
3331

3432
These values can be modified with ``tutor config save --set PARAM_NAME=VALUE`` commands.
3533

34+
Limitations
35+
-----------
36+
37+
It's not recommended to run high availability (clustered) Typesense on Kubernetes. See `typesense/typesense#465 <https://github.com/typesense/typesense/issues/465>` and `typesense/typesense#2049 <https://github.com/typesense/typesense/issues/2049>` for more information.
38+
39+
This plugin does not support deploying a clustered Typesense server.
40+
3641
Upgrading
3742
---------
38-
If you upgrade this plugin or change the ``MEILISEARCH_DOCKER_IMAGE`` setting, you may get a new version of Meilisearch.
39-
In that case, the ``meilisearch`` Docker service will fail to start because the index format is from an older version.
40-
For large instances, you can follow the `Meilisearch update procedure <https://www.meilisearch.com/docs/learn/update_and_migration/updating#updating-a-self-hosted-meilisearch-instance>`_
41-
(basically, dump the index contents to a file, upgrade it, then restore from the data dump file). For development and
42-
smaller installations, the easier way is to follow this procedure::
43+
If you upgrade this plugin or change the ``TYPESENSE_DOCKER_IMAGE`` setting, you may get a new version of Typesense.
44+
According to `Typesense docs on updating <https://typesense.org/docs/guide/updating-typesense.html#typesense-self-hosted>`_,
45+
this upgrade happens automatically, and no manual actions are required.
4346

44-
tutor [local|dev] stop meilisearch
45-
cd "$(tutor config printroot)/data/meilisearch"
46-
mv data.ms "data.ms.$(date +%Y-%m-%d)"
47-
tutor config save
48-
tutor [local|dev] start -d meilisearch
49-
tutor [local|dev] do init --limit=meilisearch
47+
DNS records
48+
-----------
5049

51-
TODO
52-
----
50+
For production use, it is assumed that the ``TYPESENSE_PUBLIC_HOST`` DNS record points to your server.
5351

54-
Currently, this plugin always deploys a new instance of Meilisearch. It should be modified to support using an existing external instance if desired.
52+
In development mode, Typesense is available at http://typesense.local.openedx.io:8108.
5553

56-
DNS records
54+
Troubleshooting
55+
---------------
56+
57+
TBD
58+
59+
Development
5760
-----------
5861

59-
For production use, it is assumed that the ``MEILISEARCH_PUBLIC_HOST`` DNS record points to your server.
62+
Set up a python virtual environment, then you can install dependencies and run the tests like:
6063

61-
In development mode, Meilisearch is available at http://meilisearch.local.edly.io:7700.
64+
make install
65+
make test
6266

63-
Web UI
64-
------
67+
After making some changes, you can run the auto formatter over the code for consistency:
6568

66-
The Meilisearch web UI can be accessed at http(s)://<MEILISEARCH_PUBLIC_HOST>. For development, this is usually http://meilisearch.local.edly.io:7700/
69+
make format
6770

68-
An API key for accessing the UI can be obtained with::
6971

70-
tutor config printvalue MEILISEARCH_API_KEY
72+
Open edX integration
73+
--------------------
7174

72-
Troubleshooting
73-
---------------
75+
This plugin provides the following settings to Open edX components for integration:
7476

75-
TBD
77+
- (common) ``TYPESENSE_ENABLED: bool = True`` - whether the Typesense backend is enabled
78+
- (common) ``TYPESENSE_COLLECTION_PREFIX: str = "the_configured_collection_prefix"`` - a prefix that the backend should use for all collections (the API key is scoped to this prefix)
79+
- (cms, lms) ``TYPESENSE_URL: str = "http://typesense:8108"`` - the internal url for accessing the Typesense API
80+
- (cms, lms) ``TYPESENSE_PUBLIC_URL: str = "http://(depends on TYPESENSE_PUBLIC_HOST)"`` - the public url to the Typesense API (for user searches on the frontend)
81+
- (cms, lms) ``TYPESENSE_API_KEY: str = "the api key"`` - an api key for the Open edX backend to make updates to Typesense collections
82+
- (lms) ``MFE_CONFIG["TYPESENSE_ENABLED"]: bool = True`` - for MFE's to know when to use Typesense logic
7683

7784
License
7885
-------
7986

80-
This work is licensed under the terms of the `GNU Affero General Public License (AGPL) <https://github.com/open-craft/tutor-contrib-meilisearch/blob/master/LICENSE.txt>`_.
87+
This work is licensed under the terms of the `GNU Affero General Public License (AGPL) <https://github.com/open-craft/tutor-contrib-typesense/blob/master/LICENSE.txt>`_.

mise.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[env]
2+
# --seed instructs uv to include pip, setuptools, and wheel in the resulting venv
3+
# useful for compatibility with other scripts that call pip
4+
_.python.venv = { path = "venv", create = true, uv_create_args = ['--seed'] }
5+
6+
[tools]
7+
python = "3.11"

pyproject.toml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
[project]
2-
name = "tutor-meilisearch"
2+
name = "tutor-typesense"
33
dynamic = ["version"]
4-
description = "A Tutor plugin for search using Meilisearch"
4+
description = "A Tutor plugin for search using Typesense"
55
readme = "README.rst"
66
license = { file = "LICENSE.txt" }
7-
requires-python = ">=3.8"
7+
requires-python = ">=3.11"
88
authors = [
9-
{ name = "Braden MacDonald", email = "braden@opencraft.com" },
10-
{ name = "Overhang.IO", email = "contact@overhang.io" },
119
]
1210
maintainers = [
13-
{ name = "Braden MacDonald", email = "braden@opencraft.com" },
1411
]
1512
classifiers = [
1613
"Development Status :: 3 - Alpha",
@@ -25,23 +22,34 @@ classifiers = [
2522
"Programming Language :: Python :: 3.12",
2623
]
2724
dependencies = [
28-
"tutor>=17.0.0,<19.0.0",
25+
"tutor>=20.0.0,<21.0.0", # teak
2926
]
3027

3128
[project.optional-dependencies]
3229
dev = [
33-
"tutor[dev]>=17.0.0,<19.0.0",
30+
"tutor[dev]>=20.0.0,<21.0.0", # teak
31+
"black",
32+
"isort",
33+
"pylint",
3434
]
3535

3636
[project.entry-points."tutor.plugin.v1"]
37-
meilisearch = "tutor_meili.plugin"
37+
typesense = "tutor_typesense.plugin"
3838

3939
[project.urls]
40-
Code = "https://github.com/open-craft/tutor-contrib-meilisearch"
40+
Code = "https://github.com/open-craft/tutor-contrib-typesense"
4141
Community = "https://discuss.openedx.org"
4242
Documentation = "https://docs.tutor.edly.io/"
4343
Homepage = "https://docs.tutor.edly.io/"
44-
"Issue tracker" = "https://github.com/open-craft/tutor-contrib-meilisearch/issues"
44+
"Issue tracker" = "https://github.com/open-craft/tutor-contrib-typesense/issues"
4545

4646
[tool.setuptools.dynamic]
47-
version = {attr = "tutor_meili.__about__.__version__"}
47+
version = {attr = "tutor_typesense.__about__.__version__"}
48+
49+
[tool.isort]
50+
profile = "black"
51+
src_paths = ["tutor_typesense"]
52+
extend_skip = ["templates"]
53+
54+
[tool.black]
55+
exclude = "templates"

tutor_meili/__about__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

tutor_meili/patches/caddyfile

Lines changed: 0 additions & 4 deletions
This file was deleted.

tutor_meili/patches/k8s-deployments

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)