Browse Source

wire up language tools and translator

imwald
Silberengel 2 weeks ago
parent
commit
e241b8540c
  1. 25
      PROXY_SETUP.md
  2. 23
      docker-compose.dev.yml
  3. 30
      docker-compose.prod.yml
  4. 21
      docker-compose.yml
  5. 1
      package.json
  6. 1
      scripts/build-and-push-prod.sh

25
PROXY_SETUP.md

@ -134,6 +134,29 @@ ProxyPassReverse /api/languagetool http://127.0.0.1:8010 @@ -134,6 +134,29 @@ ProxyPassReverse /api/languagetool http://127.0.0.1:8010
If `VITE_LANGUAGE_TOOL_URL` is empty, grammar hints in the lab are disabled.
### Docker sidecars (LanguageTool + LibreTranslate)
The repo defines optional Compose services on **host ports 8010** and **5000** (same targets as `vite.config.ts`). They use profile **`editor-tools`** so a plain `docker compose up` does not pull them unless you ask.
```bash
# Dev compose (with relay, etc.): start only grammar + translate
docker compose -f docker-compose.dev.yml --profile editor-tools up -d languagetool libretranslate
# Or npm alias
npm run docker:editor-tools
```
Then point Vite at the proxies (e.g. **`.env.local`**):
```
VITE_LANGUAGE_TOOL_URL=/api/languagetool
VITE_TRANSLATE_URL=/api/translate
```
**Production:** `docker compose -f docker-compose.prod.yml --profile editor-tools up -d languagetool libretranslate` publishes **127.0.0.1:8010** and **127.0.0.1:5000** (loopback-only). Proxy those paths from Apache/nginx to the SPA origin, and bake the client with `LANGUAGE_TOOL_URL=/api/languagetool` and `TRANSLATE_URL=/api/translate` when running `./scripts/build-and-push-prod.sh`.
**Notes:** LanguageTool’s JVM image often needs **~1–2GiB** RAM. LibreTranslate may **download models** on first start (can take several minutes).
## LibreTranslate (same-origin `/api/translate`)
Optional **`VITE_TRANSLATE_URL=/api/translate`** for `POST /translate` (LibreTranslate-compatible). Example Apache:
@ -145,6 +168,8 @@ ProxyPassReverse /api/translate http://127.0.0.1:5000 @@ -145,6 +168,8 @@ ProxyPassReverse /api/translate http://127.0.0.1:5000
**Local dev:** `vite.config.ts` proxies `/api/translate``http://127.0.0.1:5000` with path rewrite.
If `VITE_TRANSLATE_URL` is empty, translate actions in the advanced lab are hidden.
## Update Proxy Server's ALLOW_ORIGIN
Since users access via `https://jumble.imwald.eu`, you need to update the proxy server's `ALLOW_ORIGIN`:

23
docker-compose.dev.yml

@ -37,6 +37,29 @@ services: @@ -37,6 +37,29 @@ services:
- jumble
restart: unless-stopped
# Advanced Event Lab: grammar (LanguageTool) + machine translate (LibreTranslate).
# Matches vite.config.ts → 127.0.0.1:8010 / :5000. Start with:
# docker compose -f docker-compose.dev.yml --profile editor-tools up -d languagetool libretranslate
languagetool:
image: silviof/docker-languagetool:latest
profiles: ['editor-tools']
container_name: jumble-languagetool
ports:
- '8010:8010'
networks:
- jumble
restart: unless-stopped
libretranslate:
image: libretranslate/libretranslate:latest
profiles: ['editor-tools']
container_name: jumble-libretranslate
ports:
- '5000:5000'
networks:
- jumble
restart: unless-stopped
volumes:
relay-data:

30
docker-compose.prod.yml

@ -12,6 +12,12 @@ @@ -12,6 +12,12 @@
# NIP-66 monitor: set NIP66_MONITOR_NSEC (and optionally NIP66_MONITOR_NPUB) in the host env or .env.
# - Cron service `jumble-nip66-monitor` (Imwald NIP-66 monitor image) uses NIP66_MONITOR_NSEC to publish 30166/10166; nsec never goes to the client.
# - Set NIP66_MONITOR_NPUB (npub1... derived from the same key) so the relay info page shows the monitor's avatar and handle in the NIP-66 liveliness section.
#
# Optional editor tools (LanguageTool + LibreTranslate): profile `editor-tools`
# docker compose -f docker-compose.prod.yml --profile editor-tools up -d languagetool libretranslate
# Then Apache (or nginx) must proxy same-origin paths baked into the SPA, e.g. /api/languagetool → http://127.0.0.1:8010
# and /api/translate → http://127.0.0.1:5000. Build the app image with:
# LANGUAGE_TOOL_URL=/api/languagetool TRANSLATE_URL=/api/translate ./scripts/build-and-push-prod.sh
services:
jumble:
@ -58,3 +64,27 @@ services: @@ -58,3 +64,27 @@ services:
resources:
limits:
memory: 128M
languagetool:
image: silviof/docker-languagetool:latest
profiles: ['editor-tools']
container_name: imwald-languagetool
ports:
- '127.0.0.1:8010:8010'
restart: unless-stopped
deploy:
resources:
limits:
memory: 2048M
libretranslate:
image: libretranslate/libretranslate:latest
profiles: ['editor-tools']
container_name: imwald-libretranslate
ports:
- '127.0.0.1:5000:5000'
restart: unless-stopped
deploy:
resources:
limits:
memory: 2048M

21
docker-compose.yml

@ -24,5 +24,26 @@ services: @@ -24,5 +24,26 @@ services:
networks:
- jumble
# Optional: same as docker-compose.dev.yml — `docker compose --profile editor-tools up -d languagetool libretranslate`
languagetool:
image: silviof/docker-languagetool:latest
profiles: ['editor-tools']
container_name: jumble-languagetool
ports:
- '8010:8010'
networks:
- jumble
restart: unless-stopped
libretranslate:
image: libretranslate/libretranslate:latest
profiles: ['editor-tools']
container_name: jumble-libretranslate
ports:
- '5000:5000'
networks:
- jumble
restart: unless-stopped
networks:
jumble:

1
package.json

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
"scripts": {
"dev": "vite --host",
"dev:refresh": "rm -rf node_modules/.vite && vite --host",
"docker:editor-tools": "docker compose -f docker-compose.dev.yml --profile editor-tools up -d languagetool libretranslate",
"build": "tsc -b && vite build",
"lint": "eslint .",
"knip": "npx --yes knip@5",

1
scripts/build-and-push-prod.sh

@ -63,3 +63,4 @@ echo "Pushing tag $GIT_TAG to origin" @@ -63,3 +63,4 @@ echo "Pushing tag $GIT_TAG to origin"
git push origin "$GIT_TAG"
echo "Done. On the server: docker compose -f docker-compose.prod.yml pull && docker compose -f docker-compose.prod.yml up -d"
echo "Optional LanguageTool + LibreTranslate: docker compose -f docker-compose.prod.yml --profile editor-tools up -d languagetool libretranslate (see PROXY_SETUP.md)"

Loading…
Cancel
Save