Add LibreTranslate #5
							
								
								
									
										3
									
								
								Config/LibreTranslate/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								Config/LibreTranslate/Dockerfile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
# Install and run LibreTranslate
 | 
			
		||||
 | 
			
		||||
FROM libretranslate/libretranslate:latest
 | 
			
		||||
							
								
								
									
										31
									
								
								Config/LibreTranslate/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								Config/LibreTranslate/README.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
# 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.
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
./prep.sh
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
2. If using  a temporary location for `models/` such as `/tmp/`, ensure
 | 
			
		||||
that `prep.sh` is in `root`'s crontab.
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
@reboot /opt/Docker/Config/LibreTranslate/prep.sh
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
3. Start the container up as normal.
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
cp docker-compose.main.yml docker-compose.yml
 | 
			
		||||
docker compose up -d
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										55
									
								
								Config/LibreTranslate/docker-compose.main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								Config/LibreTranslate/docker-compose.main.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
# LibreTranslate configuration.
 | 
			
		||||
# 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
 | 
			
		||||
      - $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: $CPU
 | 
			
		||||
          memory: $RAM
 | 
			
		||||
							
								
								
									
										46
									
								
								Config/LibreTranslate/env.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								Config/LibreTranslate/env.example
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
# This file should be renamed '.env' and have any private values modified.
 | 
			
		||||
 | 
			
		||||
COMPOSE_BAKE=true
 | 
			
		||||
 | 
			
		||||
### Container Specs ###
 | 
			
		||||
 | 
			
		||||
## For a small-scale server (such as 1 CPU, 1GB RAM).
 | 
			
		||||
# CPU=0.25
 | 
			
		||||
# RAM=640M
 | 
			
		||||
 | 
			
		||||
## For a fully capable server.
 | 
			
		||||
CPU=2.00
 | 
			
		||||
RAM=4.0G
 | 
			
		||||
 | 
			
		||||
### Languages ###
 | 
			
		||||
 | 
			
		||||
## Check for language model updates on each run.
 | 
			
		||||
UPDATE_MODELS=true
 | 
			
		||||
 | 
			
		||||
## Use default behavior of downloading all models.
 | 
			
		||||
# LANGUAGES=ALL
 | 
			
		||||
 | 
			
		||||
## Otherwise set to a comma-separated list to enable only the desired models.
 | 
			
		||||
LANGUAGES='LT_LOAD_ONLY=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 dirs after a reboot.
 | 
			
		||||
## `@reboot /opt/Docker/Config/LibreTranslate/prep.sh`
 | 
			
		||||
# MODELS_DIR=/tmp/LibreTranslate/models
 | 
			
		||||
							
								
								
									
										25
									
								
								Config/LibreTranslate/prep.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										25
									
								
								Config/LibreTranslate/prep.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
#!/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 ##
 | 
			
		||||
 | 
			
		||||
# Create folders.
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
# Finish successfully.
 | 
			
		||||
exit 0
 | 
			
		||||
		Reference in New Issue
	
	Block a user