From 593b1fbaf2c8f690806a1a07fc1a173f61c1b77c Mon Sep 17 00:00:00 2001 From: Hyperling Date: Wed, 23 Jul 2025 05:55:40 -0700 Subject: [PATCH 1/7] 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 From 620f3f81b20dde69e94135add661f59c75b829d0 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Wed, 23 Jul 2025 06:05:21 -0700 Subject: [PATCH 2/7] Shrink down to just 1 yml file, putting the CPU and RAM into the env file, since the only docker-compose differences were the resource configuration. --- Config/LibreTranslate/README.md | 3 +- ...e.standard.yml => docker-compose.main.yml} | 6 +- .../LibreTranslate/docker-compose.micro.yml | 55 ------------------- Config/LibreTranslate/env.example | 13 +++++ 4 files changed, 18 insertions(+), 59 deletions(-) rename Config/LibreTranslate/{docker-compose.standard.yml => docker-compose.main.yml} (93%) delete mode 100644 Config/LibreTranslate/docker-compose.micro.yml diff --git a/Config/LibreTranslate/README.md b/Config/LibreTranslate/README.md index 9aaa2e4..76bcf27 100644 --- a/Config/LibreTranslate/README.md +++ b/Config/LibreTranslate/README.md @@ -13,7 +13,7 @@ vi .env 1. Run the `prep.sh` file to create the volume mounts. ``` -$DOCKER_HOME/Config/LibreTranslate/prep.sh +./prep.sh ``` 2. If using a temporary location for `models/` such as `/tmp/`, ensure @@ -26,5 +26,6 @@ that `prep.sh` is in `root`'s crontab. 3. Start the container up as normal. ``` +cp docker-compose.main.yml docker-compose.yml docker compose up -d ``` diff --git a/Config/LibreTranslate/docker-compose.standard.yml b/Config/LibreTranslate/docker-compose.main.yml similarity index 93% rename from Config/LibreTranslate/docker-compose.standard.yml rename to Config/LibreTranslate/docker-compose.main.yml index 8c169d0..76bf908 100644 --- a/Config/LibreTranslate/docker-compose.standard.yml +++ b/Config/LibreTranslate/docker-compose.main.yml @@ -1,4 +1,4 @@ -# LibreTranslate configuration for a capable server. +# LibreTranslate configuration. # Example docker-compose.yml: # https://github.com/LibreTranslate/LibreTranslate/blob/main/docker-compose.yml @@ -51,5 +51,5 @@ services: mode: global resources: limits: - cpus: '2.00' - memory: 4G + cpus: $CPU + memory: $RAM diff --git a/Config/LibreTranslate/docker-compose.micro.yml b/Config/LibreTranslate/docker-compose.micro.yml deleted file mode 100644 index b0d439b..0000000 --- a/Config/LibreTranslate/docker-compose.micro.yml +++ /dev/null @@ -1,55 +0,0 @@ -# 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/env.example b/Config/LibreTranslate/env.example index f8a0141..f45906b 100644 --- a/Config/LibreTranslate/env.example +++ b/Config/LibreTranslate/env.example @@ -2,6 +2,19 @@ COMPOSE_BAKE=true +### Container Specs ### + +## For a small-scale server (such as 1 CPU, 1GB RAM). +CPU_MINIMAL=0.25 +RAM_MINIMAL=640M + +## For a fully capable server. +CPU_RECOMMENDED=2.00 +RAM_RECOMMENDED=4.0G + +CPU=$CPU_RECOMMENDED +RAM=$RAM_RECOMMENDED + ### Languages ### ## Check for language model updates on each run. From 16df857f08f1dd791d82f8c70feb8779916d058d Mon Sep 17 00:00:00 2001 From: Hyperling Date: Wed, 23 Jul 2025 06:05:29 -0700 Subject: [PATCH 3/7] Shrink down to just 1 yml file, putting the CPU and RAM into the env file, since the only docker-compose differences were the resource configuration. --- Config/LibreTranslate/env.example | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Config/LibreTranslate/env.example b/Config/LibreTranslate/env.example index f45906b..fd623b0 100644 --- a/Config/LibreTranslate/env.example +++ b/Config/LibreTranslate/env.example @@ -5,12 +5,12 @@ COMPOSE_BAKE=true ### Container Specs ### ## For a small-scale server (such as 1 CPU, 1GB RAM). -CPU_MINIMAL=0.25 -RAM_MINIMAL=640M +# CPU=0.25 +# RAM=640M ## For a fully capable server. -CPU_RECOMMENDED=2.00 -RAM_RECOMMENDED=4.0G +CPU=2.00 +RAM=4.0G CPU=$CPU_RECOMMENDED RAM=$RAM_RECOMMENDED From 83fdb54768e228abc7d37a411db57ef3615b8ab0 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sat, 26 Jul 2025 11:28:04 -0700 Subject: [PATCH 4/7] Move the LT_LOAD_ONLY to the value so that it can be omitted if wanting to download all languages. --- Config/LibreTranslate/docker-compose.main.yml | 2 +- Config/LibreTranslate/env.example | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Config/LibreTranslate/docker-compose.main.yml b/Config/LibreTranslate/docker-compose.main.yml index 76bf908..9da0311 100644 --- a/Config/LibreTranslate/docker-compose.main.yml +++ b/Config/LibreTranslate/docker-compose.main.yml @@ -41,7 +41,7 @@ services: - 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 + - $LANGUAGES volumes: # Store the API keys. - libretranslate_api_keys:/app/db diff --git a/Config/LibreTranslate/env.example b/Config/LibreTranslate/env.example index fd623b0..d5a9171 100644 --- a/Config/LibreTranslate/env.example +++ b/Config/LibreTranslate/env.example @@ -12,20 +12,16 @@ COMPOSE_BAKE=true CPU=2.00 RAM=4.0G -CPU=$CPU_RECOMMENDED -RAM=$RAM_RECOMMENDED - ### 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 +## Use default behavior of downloading all models. +# LANGUAGES=ALL ## Otherwise set to a comma-separated list to enable only the desired models. -LANGUAGES=en,es,fr,de +LANGUAGES='LT_LOAD_ONLY=en,es,fr,de' ### API Keys ### From 43ee8de7efa9b94f87e9200f8bf486690413b999 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sat, 26 Jul 2025 11:59:45 -0700 Subject: [PATCH 5/7] Add comments and an explicit exit. --- Config/LibreTranslate/prep.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Config/LibreTranslate/prep.sh b/Config/LibreTranslate/prep.sh index bc66007..46fa82f 100755 --- a/Config/LibreTranslate/prep.sh +++ b/Config/LibreTranslate/prep.sh @@ -10,6 +10,7 @@ source $DIR/.env ## Main ## +# Create folders. if [[ $API_KEYS_DIR == "../*" ]]; then API_KEYS_DIR="$DIR/$API_KEYS_DIR" fi @@ -19,3 +20,6 @@ if [[ $MODELS_DIR == "../*" ]]; then MODELS_DIR="$DIR/$MODELS_DIR" fi mkdir -pv $MODELS_DIR + +# Finish successfully. +exit 0 From 29d1affcd8a13d56583b180b8ac27bedbec4daf1 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sat, 26 Jul 2025 12:00:43 -0700 Subject: [PATCH 6/7] Be more specific about the docker home location, rather than accidentally promoting the use of a variable which would not work. --- Config/LibreTranslate/README.md | 2 +- Config/LibreTranslate/env.example | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Config/LibreTranslate/README.md b/Config/LibreTranslate/README.md index 76bcf27..a112d95 100644 --- a/Config/LibreTranslate/README.md +++ b/Config/LibreTranslate/README.md @@ -20,7 +20,7 @@ vi .env that `prep.sh` is in `root`'s crontab. ``` -@reboot $DOCKER_HOME/Config/LibreTranslate/prep.sh +@reboot /opt/Docker/Config/LibreTranslate/prep.sh ``` 3. Start the container up as normal. diff --git a/Config/LibreTranslate/env.example b/Config/LibreTranslate/env.example index d5a9171..2107396 100644 --- a/Config/LibreTranslate/env.example +++ b/Config/LibreTranslate/env.example @@ -40,7 +40,8 @@ MODELS_DIR=../../Volumes/LibreTranslate/models # 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` +## them from backup type locations such as Volumes/LibreTranslate/ and /var/. +## This will require a CRON entry for prepping the project dirs after a reboot. +## `@reboot /YOUR_DOCKER_HOME/Config/LibreTranslate/prep.sh` +## # MODELS_DIR=/tmp/LibreTranslate/models From 27689e25d80f99713870798012021a371c4a46c4 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sat, 26 Jul 2025 12:01:10 -0700 Subject: [PATCH 7/7] Be more specific about the docker home location, rather than accidentally promoting the use of a variable which would not work. --- Config/LibreTranslate/env.example | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Config/LibreTranslate/env.example b/Config/LibreTranslate/env.example index 2107396..2222cb6 100644 --- a/Config/LibreTranslate/env.example +++ b/Config/LibreTranslate/env.example @@ -42,6 +42,5 @@ MODELS_DIR=../../Volumes/LibreTranslate/models ## 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 dirs after a reboot. -## `@reboot /YOUR_DOCKER_HOME/Config/LibreTranslate/prep.sh` -## +## `@reboot /opt/Docker/Config/LibreTranslate/prep.sh` # MODELS_DIR=/tmp/LibreTranslate/models