259 lines
14 KiB
Markdown
259 lines
14 KiB
Markdown
# Terminology Portal
|
|
|
|
## Quick Overview
|
|
|
|
An opensource Terminology portal which anybody can set up (hopefully without much trouble).
|
|
|
|
The main instance is available at [https://terminoloski.slovenscina.eu](https://terminoloski.slovenscina.eu).
|
|
|
|
You can use your own instance completely independently or link it with other such instances, including the main one, and have them share dictionaries and their entries.
|
|
|
|
Likewise, the included consultancy module can use its built-in, fully featured tools for your consultants to process terminology questions (default)
|
|
or simply be linked with the one at [ISJFR, ZRC SAZU](https://isjfr.zrc-sazu.si) so that their professional consultants will answer the questions.
|
|
|
|
## Setting up your own instance of the portal
|
|
|
|
_The guide is written for Ubuntu 22.04 LTS. Adjust according to your OS._
|
|
|
|
### 1. Install external dependencies first
|
|
|
|
1. Install the [Docker Engine](https://docs.docker.com/engine/install/).
|
|
2. Install the [Term Candidate Extraction API](https://github.com/clarinsi/rsdo_luscilnik).
|
|
3. Make sure you have a SMTP server/service available, which the portal will require.
|
|
4. Install a reverse proxy (e.g. [Nginx](https://nginx.org/en/)).
|
|
|
|
### 2. Reconfigure the docker engine
|
|
|
|
By default, docker engine doesn't perform log rotation, which will eventually lead to disk exhaustion.
|
|
Search indexes will prevent all write operations at 90% full which will make many operations on the portal fail until
|
|
disk usage falls under 85% again.
|
|
|
|
Also, by default, image build process is not optimized.
|
|
|
|
To address both of the above, it is suggested to add the following to the _/etc/docker/daemon.json_ :
|
|
|
|
```
|
|
{
|
|
"log-driver": "local",
|
|
"features": {
|
|
"buildkit": true
|
|
}
|
|
}
|
|
```
|
|
|
|
Even better, set `"log-driver": "journald"` instead, so the logs get sent straight to your journald.
|
|
Alternatively, set your own preferred log aggregator as per [the official documentation](https://docs.docker.com/config/containers/logging/configure/).
|
|
|
|
**You need to restart the engine for the settings to take effect. Run:** `sudo systemctl restart docker.service`
|
|
|
|
### 3. Get and configure the portal
|
|
|
|
1. Using [git](https://git-scm.com/) transfer the portal code into desired directory with `git clone https://github.com/clarinsi/rsdo_term_portal.git <directory path>`
|
|
2. Navigate into that directory and copy the _.env_ file from the _dev_ folder one level up (into the root directory of the portal).
|
|
3. Open the copied _.env_ file in a text editor and adjust the parameters of your portal.
|
|
|
|
### 4. (Advanced/optional) Adjust data storage locations or other host-specific settings
|
|
|
|
By default, all data is stored and persisted inside Docker's [volumes](https://docs.docker.com/storage/volumes/)
|
|
on your host's root partition. If you have a setup where for any reason you want to store data
|
|
elsewhere, e.g. using [bind mounts](https://docs.docker.com/storage/bind-mounts/), or need other
|
|
host-specific tweaks (resource limits, etc.), do **not** edit docker-compose.prod.yml directly.
|
|
Instead, copy docker-compose.prod.override.example.yml to docker-compose.prod.override.yml next to
|
|
it and adjust only the keys that need to differ on this host. `./run-prod.sh` (see next step)
|
|
automatically layers this override file in when present, so it never needs to be manually re-applied
|
|
after pulling changes to docker-compose.prod.yml. docker-compose.prod.override.yml is gitignored on
|
|
purpose — it's host-specific and shouldn't be tracked or committed.
|
|
|
|
### 5. Start the portal service cluster
|
|
|
|
1. Inside the portal directory, run the following command in CLI: `./run-prod.sh --profile concordancer-manager up -d --build`
|
|
2. It's going to take some time for all the resources to get downloaded and built.
|
|
Wait for control to be returned to CLI before continuing.
|
|
|
|
### 6. First time concordancer setup
|
|
|
|
1. Open a bash session inside the _concordancer-manager_ container by running:
|
|
`docker exec -it $(docker ps --format "{{.Names}}" | grep concordancer-manager) bash`
|
|
2. In that session, run: `dotnet Rsdo.Concordancer.SystemManager.dll createMasterDb --connectionString="Host=postgres;Username=concordancer;Password=<POSTGRES_CONCORDANCER_PASSWORD>;Database=postgres"`.
|
|
Replace `<POSTGRES_CONCORDANCER_PASSWORD>` with the value you set for it in the _.env_ file.
|
|
3. After that, also in that session, run: `dotnet Rsdo.Concordancer.SystemManager.dll importSloleks --sourceFile=/sloleks/Sloleks2.0.LMF/sloleks_clarin_2.0.xml`.
|
|
This command takes a bit more time than the previous one to finish.
|
|
4. Close the session _(Ctrl + D)_
|
|
|
|
### 7. Reverse proxy setup
|
|
|
|
1. Forward the majority of trafic to the the main port,
|
|
set appropriate headers, needed for normal functioning of the webserver
|
|
and increase the maximum allowed request body size.
|
|
Example location block for Nginx config:
|
|
|
|
```
|
|
location / {
|
|
proxy_set_header X-Forwarded-Host $host:$server_port;
|
|
proxy_set_header X-Forwarded-Server $host;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
client_max_body_size 1100M;
|
|
proxy_pass http://127.0.0.1:<EXPRESS_LISTEN_PORT>;
|
|
}
|
|
```
|
|
|
|
Replace <EXPRESS_LISTEN_PORT> with whichever port you set as EXPRESS_LISTEN_PORT in the .env file,
|
|
or even change the IP address or protocol if you've done done some changes to docker-compose.prod.yml or other system wide configuration and generally know, what you're doing.
|
|
|
|
2. Forward concordancer client trafic to the _/korpus_ path
|
|
Example location block for Nginx config:
|
|
|
|
```
|
|
location /korpus/ {
|
|
proxy_pass http://127.0.0.1:<CONCORDANCER_LISTEN_PORT>/;
|
|
}
|
|
```
|
|
|
|
Same as above, except replace <CONCORDANCER_LISTEN_PORT> with the value of CONCORDANCER_LISTEN_PORT.
|
|
|
|
3. Don't forget setting up proper SSL termination, compression, ...
|
|
|
|
4. Also don't forget to make your changes take effect.
|
|
For Nginx, `sudo systemctl reload nginx.service` is usually the easiest way.
|
|
|
|
### 8. Done
|
|
|
|
Your portal should now be available at whichever address/domain your reverse proxy is set to listen to.
|
|
|
|
## Automated deployment (CI/CD)
|
|
|
|
The generic guide above builds images on the host with `up -d --build`. For a maintainer who
|
|
runs one or more long-lived environments (e.g. staging + production VPSs), there is an automated
|
|
pipeline built on **Gitea Actions** and the **Gitea container registry**. It builds the three
|
|
custom images (`express`, `opensearch`, `concordancer`) once, pushes them to the registry, and
|
|
each host **pulls** them instead of building — no more copying files around or building on the VPS.
|
|
|
|
**Flow:**
|
|
|
|
- Push to the default branch → CI builds + pushes images tagged `sha-<short>` → auto-deploys to **staging**.
|
|
- Push a version tag `vX.Y.Z` → CI **promotes** the exact staging-tested images to that tag (no
|
|
rebuild) → deploys to **production**. Pushing the tag is the deliberate human release gate.
|
|
- Rollback / ad-hoc deploy → run the **deploy-dispatch** workflow with a previous tag.
|
|
|
|
The pieces live in the repo:
|
|
|
|
- `docker-compose.prod.yml` — each built service has both an `image:` (registry ref, via
|
|
`${REGISTRY}`/`${IMAGE_TAG}`) and its `build:` block. Unset, the vars default to a local name so
|
|
the generic `up --build` path still works untouched.
|
|
- `.gitea/workflows/build-and-stage.yml`, `release-prod.yml`, `deploy-dispatch.yml`.
|
|
- `dev/ci/build.sh` (buildx build + push, registry layer cache), `dev/ci/promote.sh` (retag
|
|
without rebuild), `dev/ci/deploy.sh` (runner side: SSH the target the tag to deploy),
|
|
`dev/ci/ci-deploy-wrapper.sh` (host side: the forced command that validates the tag and runs
|
|
`git checkout` + `run-prod.sh pull` + `up -d`). The CI key is pinned to that wrapper, so a leaked
|
|
key can only ever trigger a tag deploy on one host — never an arbitrary command
|
|
(see [`dev/ci/README.md`](dev/ci/README.md#hardened-deploy-access)).
|
|
|
|
### One-time setup
|
|
|
|
1. **Enable Gitea Actions** and confirm the **container registry** is on (both are usually default
|
|
in recent Gitea).
|
|
2. **Register a runner.** On a build host — ideally a machine that is _not_ your public production
|
|
server but has Docker, disk, and internet (the concordancer build downloads a large lexicon) —
|
|
install the **Gitea Runner** (`gitea/runner`; formerly `act_runner`) and register it repo-scoped
|
|
with the `self-hosted` label the workflows target. The runner only needs outbound reachability to
|
|
Gitea and SSH reachability to the deploy hosts. Full step-by-step + smoke tests:
|
|
[`dev/ci/README.md`](dev/ci/README.md).
|
|
3. **Prepare each target host (staging, prod):**
|
|
- Create a dedicated `deploy` user (keeps automation out of your personal account and gives
|
|
clean audit/revocation); add it to the `docker` group.
|
|
- `git clone` the repo to a stable path, e.g. `/opt/termportal-staging` or `/opt/termportal-prod`.
|
|
- Put the host-only `.env` (with `REGISTRY=<gitea-host>/<owner>` set) and, if used,
|
|
`docker-compose.prod.override.yml` in that directory. Both are gitignored, so `git checkout`
|
|
during deploys never touches them.
|
|
- `docker login <gitea-host>` once with a **read-only** registry token so `pull` works.
|
|
- Install the **hardened deploy key + forced-command wrapper** — full commands in
|
|
[`dev/ci/README.md`](dev/ci/README.md#hardened-deploy-access). In short: a **dedicated** CI
|
|
keypair (never your personal key), its public half pinned in the deploy user's
|
|
`authorized_keys` with `from="<runner-ip>",restrict,command="…/ci-deploy-wrapper.sh"`, and its
|
|
private half stored as the Gitea secret below.
|
|
- Do the first-time concordancer setup (section 6 above) once, as usual.
|
|
4. **Add Gitea Actions secrets** (repo → Settings → Actions → Secrets):
|
|
`REGISTRY_TOKEN` — a Personal Access Token with `write:package` scope, used by CI to push
|
|
images (the automatic `GITEA_TOKEN` is not authorized to push packages); plus
|
|
`STAGING_SSH_HOST`, `STAGING_SSH_USER`, `STAGING_SSH_KEY` and the `PROD_*` equivalents; also
|
|
`STAGING_SSH_PORT` / `PROD_SSH_PORT` if a host's sshd doesn't listen on the default port 22
|
|
(both default to 22 when unset). (No `*_DIR` secret is needed — each host's wrapper owns its
|
|
checkout path via `ci-deploy.conf`.)
|
|
|
|
### Day-to-day
|
|
|
|
- **Deploy to staging:** `git push` to the default branch.
|
|
- **Release to production:** `git tag -a v1.2.3 -m "…" && git push origin v1.2.3` (tag a commit
|
|
already built on the default branch, so its `sha-<short>` images exist to promote). Use an
|
|
**annotated** tag (`-a`), not a lightweight one — this repo's release tags carry a tagger, date,
|
|
and message as a record of what shipped and why, which a lightweight tag (a bare pointer) doesn't
|
|
have. Both tag kinds trigger the `release-prod` workflow the same way, since it matches on the ref
|
|
name (`refs/tags/v*`); this only affects the tag's own metadata, not the deploy.
|
|
- **Rollback:** run the **deploy-dispatch** workflow with the previous `vX.Y.Z` (or `sha-…`) tag.
|
|
Note: this rolls back application code only — database/schema changes are forward-only (there is
|
|
no migration framework), so back up and treat schema changes deliberately.
|
|
|
|
### Break-glass manual deploy
|
|
|
|
If CI is unavailable, SSH into the host and run the same wrapper the pipeline triggers:
|
|
|
|
```bash
|
|
/home/deploy/ci-deploy-wrapper.sh v1.2.3 # checkout, pull, up -d for that tag
|
|
```
|
|
|
|
Or drive the steps by hand (equivalent):
|
|
|
|
```bash
|
|
cd /opt/termportal-prod
|
|
git fetch --tags origin && git checkout --force v1.2.3
|
|
export IMAGE_TAG=v1.2.3 # REGISTRY comes from this host's .env
|
|
./run-prod.sh pull
|
|
./run-prod.sh up -d
|
|
```
|
|
|
|
## Linking your instance with others
|
|
|
|
1. Using a web browser, navigate to your portal's main page.
|
|
2. In the upper right corner, change language to English.
|
|
(the instructions are written using english UI labels)
|
|
3. Log in as the portal admin user.
|
|
4. Navigate Menu -> Administration -> Links -> Add link.
|
|
5. Fill in all the fields:
|
|
|
|
- **Portal name** - your choice; it'll be displayed as the source of found entries, when the users use the portal's search tool.
|
|
|
|
- **Portal label** - a 2 letter code of your choice; same as portal name, except a shorter version.
|
|
|
|
- **URL (dictionaries sync)** - Format: <target_portal_origin>/api/v1/system/inter-instance-sync/dictionaries
|
|
|
|
Replace <target_portal_origin> with the origin of the portal, the dictionaries of which you wish to add to your portal.
|
|
|
|
To link the main instance of the portal, for example, you would enter:
|
|
https://terminoloski.slovenscina.eu/api/v1/system/inter-instance-sync/dictionaries
|
|
|
|
- **URL (dictionary entries sync)** - Format: <target_portal_origin>/api/v1/system/inter-instance-sync/dictionary/$SOURCE_ID/entries?lastSynced=$SINCE
|
|
|
|
<target_portal_origin> should be the same as for previous URL.
|
|
|
|
To link the main instance of the portal, for example, you would enter:
|
|
https://terminoloski.slovenscina.eu/api/v1/system/inter-instance-sync/dictionary/$SOURCE_ID/entries?lastSynced=$SINCE
|
|
|
|
6. Click _Add link_. You will be returned to the list of linked portals, where the newly created portal will now be listed.
|
|
7. Click _Dictionaries_ to see the list of all available dictionaries of the target portal. Enable the ones you wish to be added to your portal, click _Save_.
|
|
8. The selected dictionaries and all their entries will be automatically synchronized each night.
|
|
|
|
## Linking to ZRC SAZU Terminological counselling
|
|
|
|
If you wish professional counselors to answer your users' terminological questions,
|
|
you can do so by simply toggling a switch in the administration console.
|
|
|
|
1. As previously described, navigate to the Menu -> Administration -> Basic settings -> Consultancy.
|
|
2. Select _ZRC SAZU Terminological counselling_.
|
|
3. Click Save.
|
|
|
|
That's it.
|
|
Your questions will now be automatically forwarded to ZRC SAZU Terminological counselling
|
|
and their answers back to your portal.
|