This is a docker-compose configuration to be used only for development purpose.
This project adheres to openZIM TCP-UDP-ports-for-development convention. Its port range is 376xx.
- Dev UI (hot reloading): http://localhost:37600
- Backend (hot reloading): http://localhost:37601
- DB: postgresdb://localhost:37602
- Compiled UI: http://localhost:37603
This container is a backend web server, linked to its database.
This container is simply a Python stack with all backend requirements but no web server. Context is setup with appropriate environment variables for tests (i.e. it uses the test DB). Useful to run tests locally. Also useful to generate Alembic revisions, apply them is backend is down, ...
This container is a PostgreSQL DB. DB data is kept in a volume, persistent across containers restarts.
This container hosts the UI application with hot-reload enabled.
This container hosts the statically compiled UI.
This container hosts the background tasks which are expected to run once in a while.
First start the Docker-Compose stack:
cd dev
docker compose -p cms up -dThis sets up the containers, runs the migrations.
Note that to run tests, we use a separate DB with the backend-tests container
NOTE: All the setup scripts create entries in the DB with a prefix of dev_. This
allows you to retain prod entries in your DB (if you have imported production DB dump) when wiping the database with the wipe.py setup script.
As a consequence, you should avoid performing operations that entangle these prod DB
entries with the ones created by the setup scripts. For example, you shouldn't move
a book from the prod DB to a collection created by the setup script. Doing this will
cause the wipe.py script to fail in deleting it's entries.
Before using the shuttle service for file operations, you need to initialize the warehouse paths in the database:
docker exec cms_shuttle python /scripts/setup_warehouses.pyThis script will:
- Create warehouse directories in
dev/warehouses/ - Create corresponding database records (Warehouse)
- Print the LOCAL_WAREHOUSE_PATHS configuration (already configured in docker-compose.yml)
Current warehouse configuration:
- dev_hidden: 2 paths (
quarantine,staging) - dev_prod: 1 path (
other,wikipedia) - dev_client1: 1 path (
all) - dev_backup: 1 path (
backup)
To modify warehouse configuration, edit the WAREHOUSES_CONFIG dict in scripts/setup_warehouses.py and re-run the script.
After setting up warehouses, you can create sample collections:
docker exec cms_mill python /scripts/setup_collections.pyCurrently two collections are configured: dev_prod (associated with dev_prod warehouse) and dev_client1 (associated with dev_client1 warehouse)
To modify collections configuration, edit the COLLECTIONS_CONFIG list in scripts/setup_collections.py and re-run the script.
Once created, collection catalogs are accessible at:
http://localhost:37601/v1/collections/dev_prod/catalog.xmlorhttp://localhost:37601/v1/collections/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/catalog.xmlhttp://localhost:37601/v1/collections/dev_client1/catalog.xmlorhttp://localhost:37601/v1/collections/bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb/catalog.xml
After setting up warehouses and collections, you can create sample titles with their collections, maturity and path associations:
docker exec cms_mill python /scripts/setup_titles.pyTo modify title configuration, edit the TITLES_CONFIG list in scripts/setup_titles.py and re-run the script.
After setting up warehouses, collections and titles, you can create sample zimfarm notifications for testing the mill processor:
docker exec cms_shuttle python /scripts/setup_notifications.pyThis script will:
- Create ZimfarmNotification records with status "pending"
- Create "fake" ZIMs in quarantine folder and subfolders
After creating notifications, the mill will process them into books. And the shuttle will move files to proper target folder when appropriate.
To modify notification configuration, edit the NOTIFICATIONS_CONFIG list in scripts/setup_notifications.py and re-run the script.
To delete all data from the database and all ZIM files from warehouses:
docker exec cms_shuttle python /scripts/wipe.pyThis is useful when you need to reset everything to a clean state before re-running setup scripts.
If you have access to a production DB dump, you can restore it locally.
Mount you dump at /data/cms in PG container.
Drop and recreate the cms database:
docker exec -it cms_postgresdb bash -c \
'psql -U cms -d postgres -c "DROP DATABASE cms WITH (FORCE);" -c "CREATE DATABASE cms;"'
Restore DB dump (assuming it is mounted in /data/cms)
docker exec -it cms_postgresdb bash -c \
'pg_restore -U cms -d cms /data/cms'
Delete admin user so that it is recreated by API startup with admin/admin_pass credentials:
docker exec -it cms_postgresdb bash -c \
"psql -U cms -d cms -c \"DELETE FROM account WHERE username='admin';\""
Restart the API:
docker restart cms_api
Create missing ZIM files locally so that shuttle operations works fine (it will create empty files with touch).
docker exec cms_mill python /scripts/setup_books.pyThe backend might typically fail if the DB schema is not up-to-date, or if you create some nasty bug while modifying the code.
Restart it with:
docker restart cms_backendOther containers can be restarted the same way.
Run all tests in the backend-tests container.
docker exec -it cms_backend-tests python -m pytestYou can select one specific set of tests by path.
docker exec -it cms_backend-tests python -m pytest tests/routes/test_account.pyOr just one specific test function.
docker exec -it cms_backend-tests python -m pytest tests/routes/test_account.py -k test_list_accounts_no_authThis is normally not needed, but you might end-up in a situation where test DB gets corrupted. You can recreate test DB.
docker exec -it cms_postgresdb dropdb -e -U cms cmstest
docker exec -it cms_postgresdb psql -e -U cms -c "CREATE DATABASE cmstest;"
docker exec -it cms_postgresdb psql -e -d cmstest -U cms -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";'To run the CMS along with Zimfarm, you will need to use the zimfarm profile
docker compose -p cms --profile zimfarm up -dOn initial set up, you will need to populate the CMS database with offliner definitions.
./contrib/create_offliners.shTo register a worker account
cd contrib
./create_worker.shTo run with a zimfarm worker for processing manually uploaded ZIMs from the CMS, you will
need to run with the zimfarm-worker profile
docker compose -p cms --profile zimfarm --profile zimfarm-worker up -d