From 593b1fbaf2c8f690806a1a07fc1a173f61c1b77c Mon Sep 17 00:00:00 2001 From: Hyperling Date: Wed, 23 Jul 2025 05:55:40 -0700 Subject: [PATCH] Add an initial working configuration for LibreTranslate. --- Config/LibreTranslate/Dockerfile | 3 + Config/LibreTranslate/README.md | 30 ++++++++++ .../LibreTranslate/docker-compose.micro.yml | 55 +++++++++++++++++++ .../docker-compose.standard.yml | 55 +++++++++++++++++++ Config/LibreTranslate/env.example | 37 +++++++++++++ Config/LibreTranslate/prep.sh | 21 +++++++ 6 files changed, 201 insertions(+) create mode 100644 Config/LibreTranslate/Dockerfile create mode 100644 Config/LibreTranslate/README.md create mode 100644 Config/LibreTranslate/docker-compose.micro.yml create mode 100644 Config/LibreTranslate/docker-compose.standard.yml create mode 100644 Config/LibreTranslate/env.example create mode 100755 Config/LibreTranslate/prep.sh diff --git a/Config/LibreTranslate/Dockerfile b/Config/LibreTranslate/Dockerfile new file mode 100644 index 0000000..d85ca9c --- /dev/null +++ b/Config/LibreTranslate/Dockerfile @@ -0,0 +1,3 @@ +# Install and run LibreTranslate + +FROM libretranslate/libretranslate:latest diff --git a/Config/LibreTranslate/README.md b/Config/LibreTranslate/README.md new file mode 100644 index 0000000..9aaa2e4 --- /dev/null +++ b/Config/LibreTranslate/README.md @@ -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 +``` diff --git a/Config/LibreTranslate/docker-compose.micro.yml b/Config/LibreTranslate/docker-compose.micro.yml new file mode 100644 index 0000000..b0d439b --- /dev/null +++ b/Config/LibreTranslate/docker-compose.micro.yml @@ -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 diff --git a/Config/LibreTranslate/docker-compose.standard.yml b/Config/LibreTranslate/docker-compose.standard.yml new file mode 100644 index 0000000..8c169d0 --- /dev/null +++ b/Config/LibreTranslate/docker-compose.standard.yml @@ -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 diff --git a/Config/LibreTranslate/env.example b/Config/LibreTranslate/env.example new file mode 100644 index 0000000..f8a0141 --- /dev/null +++ b/Config/LibreTranslate/env.example @@ -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 diff --git a/Config/LibreTranslate/prep.sh b/Config/LibreTranslate/prep.sh new file mode 100755 index 0000000..bc66007 --- /dev/null +++ b/Config/LibreTranslate/prep.sh @@ -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