eScriptorium / htr2hpc

eScriptorium is an open-source handwritten text recognition (HTR) application. CDH runs a customized instance that integrates with Princeton’s HPC clusters via the htr2hpc package.

Deploying

The eScriptorium application, including the htr2hpc package, is deployed to staging or production with the escriptorium playbook. Staging is the default; pass -e runtime_env=production for production.

Two variables control what gets deployed:

  • escriptorium_gitref: the eScriptorium git ref (release tag). Set in inventory/group_vars/htr/vars.yml; it is the same for staging and production and overrides the cdh-ansible default gitref for each environment.

  • htr2hpc_gitref: the htr2hpc git ref (branch or release tag). Uses ref if specified; otherwise defaults to develop on staging and main on production.

Development versions of eScriptorium include Django migrations which modify the database schema and are difficult to roll back. The ref variable only controls the htr2hpc version; the playbook always deploys the eScriptorium version specified by escriptorium_gitref.

Example staging deploy:

ansible-playbook playbooks/escriptorium.yml -e ref=develop

To install a different version of eScriptorium you must update escriptorium_gitref. If you are testing a new version on staging that includes database migrations, you will likely need to restore the database from a backup if you need to deploy an older version of eScriptorium.

To deploy a new htr2hpc release to production, set ref to the release tag (release tags have no v prefix):

ansible-playbook playbooks/escriptorium.yml -e runtime_env=production -e ref=0.9.0

Updating htr2hpc

There is no separate step for updating htr2hpc: every run of the playbook reinstalls the htr2hpc package from htr2hpc_gitref, even if the version string has not changed (pip is run with --force-reinstall --no-deps, because pip compares version strings, not commit SHAs). To pick up new commits on a branch, or to deploy a new release, run the playbook again.

  • --no-deps means new htr2hpc dependencies are not installed automatically; add them to the playbook configuration before deploying a release that needs them.

  • On staging, the exact htr2hpc commit that was installed is written to the eScriptorium local settings as HTR2HPC_GITREF. Production leaves it unset, so htr2hpc uses its own release tag.

  • Celery, nginx, and Django Channels are restarted to pick up the new code.

Upgrading eScriptorium

The eScriptorium version is set by escriptorium_gitref in inventory/group_vars/htr/vars.yml (python_app_version follows it). To upgrade:

  1. Set escriptorium_gitref to the new eScriptorium release tag.

  2. Check python_version and nodejs_version in the same file against the new version’s requirements. python_version should also match the version htr2hpc is developed and tested with.

  3. Check the “Customize eScriptorium” tasks in roles/escriptorium_setup/tasks/main.yml. They edit eScriptorium’s source with regular expressions (the training task renames and import in apps/core/tasks.py, the model accuracy fields in apps/api/serializers.py, the nullable user email, and the legacy UI field on the profile form). ansible.builtin.replace does not fail when its pattern no longer matches, so look at each file in the new version, or check the result on a deployed server, to make sure every change still applies.

  4. Check the MIDDLEWARE override in roles/django/templates/escriptorium_settings.py.j2 against the new version’s settings; it replaces the whole list, so new upstream middleware won’t be picked up automatically.

  5. Remove any temporary patches that the new version includes upstream. For example, the ESC-2026 security patch was removed when upgrading to v1.0.1.

  6. Deploy to staging first (see Deploying), then production.

On the htr2hpc side, the tested eScriptorium version, the base.html template copy and the dependency versions also need updating; see Upgrading eScriptorium in the htr2hpc developer notes.

Wagtail content management

CDH’s instance uses htr2hpc’s optional Wagtail content management features. The python_extra_packages setting in inventory/group_vars/htr/vars.yml installs htr2hpc with the all optional dependency group (htr2hpc[all]), which includes Wagtail, so no extra step is needed to install it.

First deploy of a new instance

After deploying a new instance for the first time, load the content fixture to pre-populate the Wagtail admin with the default page snippets (the homepage heading and the profile page HPC instructions):

manage.py loaddata cdh_snippets

For other initial setup after a new deployment, see Configure Site domain in the htr2hpc README.