Add LibreTranslate #5

Merged
me merged 7 commits from dev into main 2025-07-26 12:02:51 -07:00
6 changed files with 201 additions and 0 deletions
Showing only changes of commit 593b1fbaf2 - Show all commits

View File

@@ -0,0 +1,3 @@
# Install and run LibreTranslate
FROM libretranslate/libretranslate:latest

View File

@@ -0,0 +1,30 @@
# Libreranslate Configuration
## Install
0. Copy `env.example` to `.env` and adjust the values as necessary.
```
cd $DOCKER_HOME/Config/LibreTranslate
cp env.example .env
vi .env
```
1. Run the `prep.sh` file to create the volume mounts.
```
$DOCKER_HOME/Config/LibreTranslate/prep.sh
```
2. If using a temporary location for `models/` such as `/tmp/`, ensure
that `prep.sh` is in `root`'s crontab.
```
@reboot $DOCKER_HOME/Config/LibreTranslate/prep.sh
```
3. Start the container up as normal.
```
docker compose up -d
```

View File

@@ -0,0 +1,55 @@
# LibreTranslate configuration for a small-scale server (1 CPU, 1GB RAM).
# Example docker-compose.yml:
# https://github.com/LibreTranslate/LibreTranslate/blob/main/docker-compose.yml
# Named volumes ensure that the container user gets the correct permissions.
volumes:
libretranslate_api_keys:
driver: local
driver_opts:
type: none
device: $API_KEYS_DIR
o: bind
libretranslate_models:
driver: local
driver_opts:
type: none
device: $MODELS_DIR
o: bind
services:
## Main ##
lt-app:
container_name: lt-app
build:
context: ./
network: host
restart: always
ports:
- "5000:5000"
# Uncomment this for logging in docker compose logs
tty: true
healthcheck:
test: ['CMD-SHELL', './venv/bin/python scripts/healthcheck.py']
command: --req-limit 100 --char-limit 2000
environment:
# Allow the saving of API Keys. Requires volume libretranslate_api_keys.
- LT_API_KEYS=true
- LT_API_KEYS_DB_PATH=/app/db/api_keys.db
# Optimize loading time. Requires volume libretranslate_models.
- LT_UPDATE_MODELS=$UPDATE_MODELS
- LT_LOAD_ONLY=$LANGUAGES
volumes:
# Store the API keys.
- libretranslate_api_keys:/app/db
# Avoid re-downloading language models every reboot.
- libretranslate_models:/home/libretranslate/.local:rw
deploy:
mode: global
resources:
limits:
cpus: '0.25'
memory: 640M

View File

@@ -0,0 +1,55 @@
# LibreTranslate configuration for a capable server.
# Example docker-compose.yml:
# https://github.com/LibreTranslate/LibreTranslate/blob/main/docker-compose.yml
# Named volumes ensure that the container user gets the correct permissions.
volumes:
libretranslate_api_keys:
driver: local
driver_opts:
type: none
device: $API_KEYS_DIR
o: bind
libretranslate_models:
driver: local
driver_opts:
type: none
device: $MODELS_DIR
o: bind
services:
## Main ##
lt-app:
container_name: lt-app
build:
context: ./
network: host
restart: always
ports:
- "5000:5000"
# Uncomment this for logging in docker compose logs
tty: true
healthcheck:
test: ['CMD-SHELL', './venv/bin/python scripts/healthcheck.py']
command: --req-limit 100 --char-limit 2000
environment:
# Allow the saving of API Keys. Requires volume libretranslate_api_keys.
- LT_API_KEYS=true
- LT_API_KEYS_DB_PATH=/app/db/api_keys.db
# Optimize loading time. Requires volume libretranslate_models.
- LT_UPDATE_MODELS=$UPDATE_MODELS
- LT_LOAD_ONLY=$LANGUAGES
volumes:
# Store the API keys.
- libretranslate_api_keys:/app/db
# Avoid re-downloading language models every reboot.
- libretranslate_models:/home/libretranslate/.local:rw
deploy:
mode: global
resources:
limits:
cpus: '2.00'
memory: 4G

View File

@@ -0,0 +1,37 @@
# This file should be renamed '.env' and have any private values modified.
COMPOSE_BAKE=true
### Languages ###
## Check for language model updates on each run.
UPDATE_MODELS=true
## Leave commented, blank, or set to "All" for default behavior.
# LANGUAGES=
# LANGUAGES=All
## Otherwise set to a comma-separated list to enable only the desired models.
LANGUAGES=en,es,fr,de
### API Keys ###
API_KEYS=true
API_KEYS_DB_PATH=/app/db/api_keys.db
API_KEYS_DIR=../../Volumes/LibreTranslate/api_keys
### Models ###
## Storing models prevents them from needing downloaded each run.
## Placing them under Volumes means they will increase backup sizes.
MODELS_DIR=../../Volumes/LibreTranslate/models
## Not providing any location puts them in the default Docker /var/ location.
# MODELS_DIR=
## Storing them in /tmp/ will cause them to get reset after reboots, but hides
## them from backup type locations such as Volumes/LibreTranslate and /var/.
## This will require a CRON entry for prepping the project after a reboot.
## `@reboot $DOCKER_HOME/Config/LibreTranslate/prep.sh`
# MODELS_DIR=/tmp/LibreTranslate/models

21
Config/LibreTranslate/prep.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# 2025-07-22 Hyperling
# Create the necessary folders for LibreTranslate's volumes to work.
# This must be run before the container will start properly.
## Setup ##
DIR="$(dirname -- "${BASH_SOURCE[0]}")"
source $DIR/.env
## Main ##
if [[ $API_KEYS_DIR == "../*" ]]; then
API_KEYS_DIR="$DIR/$API_KEYS_DIR"
fi
mkdir -pv $API_KEYS_DIR
if [[ $MODELS_DIR == "../*" ]]; then
MODELS_DIR="$DIR/$MODELS_DIR"
fi
mkdir -pv $MODELS_DIR