first commit

This commit is contained in:
meaz 2023-10-08 20:28:47 +02:00
commit 686726798a
Signed by: meaz
GPG key ID: CD7A47B2F1ED43B4
12 changed files with 226 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.vagrant

19
LICENSE Normal file
View file

@ -0,0 +1,19 @@
MIT License Copyright (c) 2021 "Stichting Disroot.org"
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,9 @@
---
- hosts: libretranslate
roles:
- nginx
- libretranslate
vars_files:
- ../defaults/main.yml

27
README.md Normal file
View file

@ -0,0 +1,27 @@
# Libretranslate - Ansible Role
This role covers deployment, configuration and software updates of Libretranslate. This role is released under MIT Licence and we give no warranty for this piece of software. Currently supported OS - Debian.
You can deploy test instance using `Vagrantfile` attached to the role.
`vagrant up`
`ansible-playbook -b Playbooks/libretranslate.yml`
Then you can access Roundcube from your computer on http://192.168.33.56
## Playbook
The playbook includes nginx role and deploys entire stack needed to run Libretranslate. Additional role is also available in the Ansible roles repos in git.
## Server configuration
You should have at least:
- 3GB RAM
- 25GB disk size
On the first run, the role downloads all packages, so be aware that it can be a bit long at this is about 15GB to be downloaded!
Then, when you first lauch libretranslate, it downloads all languages packages (around 7GB)
## CHANGELOG
- **08.10.2023** - Create the role

18
Vagrantfile vendored Normal file
View file

@ -0,0 +1,18 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
#config.ssh.insert_key = false
config.vm.define "libretranslate" do |libretranslate|
libretranslate.vm.box = "generic/debian11"
libretranslate.vm.provider :libvirt do |libvirt|
libvirt.memory = 256
end
libretranslate.vm.network "private_network", ip: "192.168.33.56"
config.vm.provision "shell", inline: "apt install acl"
end
end

63
defaults/main.yml Normal file
View file

@ -0,0 +1,63 @@
---
libretranslate_user: 'libretranslate'
libretranslate_group: 'libretranslate'
libretranslate_venv_path: '/home/{{ libretranslate_user }}/libretranslate_venv'
libretranslate_pkg:
- python3-pip
- virtualenv
- python3-venv
libretranslate_pip_pkgs:
- setuptools
- wheel
- pip
- pyyaml
libretranslate_environment:
## The following need to be uncommented and parameters to be set
- 'LT_HOST=127.0.0.1'
- 'LT_PORT=5000'
#- 'LT_CHAR_LIMIT='
#- 'LT_REQ_LIMIT='
#- 'LT_BATCH_LIMIT='
- 'LT_FRONTEND_LANGUAGE_SOURCE=auto'
- 'LT_FRONTEND_LANGUAGE_TARGET=local'
- 'LT_FRONTEND_TIMEOUT=500'
#- 'LT_LOAD_ONLY='
- 'LT_THREADS=4'
#- 'LT_URL_PREFIX='
## The following just need to be uncommented, it doesn't need parameters
#- 'LT_DEBUG'
#- 'LT_SSL'
#- 'LT_SUGGESTIONS'
#- 'LT_DISABLE_FILES_TRANSLATION'
#- 'LT_DISABLE_WEB_UI'
#- 'LT_METRICS'
#nginx vhosts
nginx_default_vhost: 'libretranslate'
nginx_default_vhost_ssl: 'libretranslate'
nginx_gen_dh: 'false'
ssl_src_path: '/etc/letsencrypt/live'
nginx_vhosts:
- name: 'libretranslate'
template: 'proxy'
upstream_proto: 'http'
upstream_port: '5000'
upstream_name: '127.0.0.1'
proto: 'http'
listen: '80'
#ssl_name: 'libretranslate.localhost'
secure_site: 'true'
secure_cookie: 'true'
#header_sameorigin: 'true'
use_error_log: 'true'
nginx_error_log_level: 'warn'
use_access_log: 'false'
redirect_https: 'false'
letsencrypt: 'false'
nginx_HSTS_policy: 'true'
state: 'enable'

17
tasks/installapp.yml Normal file
View file

@ -0,0 +1,17 @@
---
- name: '[INSTALL] - Create the initial virtualenv, install and update pip and setuptools'
pip:
name: "{{ libretranslate_pip_pkgs }}"
virtualenv: '{{ libretranslate_venv_path }}/'
virtualenv_site_packages: yes
become: yes
become_user: '{{libretranslate_user }}'
- name: '[INSTALL] - Install libretranslate'
pip:
name: libretranslate
virtualenv: '{{ libretranslate_venv_path }}'
state: "latest"
become: yes
become_user: '{{ libretranslate_user }}'

6
tasks/installdeps.yml Normal file
View file

@ -0,0 +1,6 @@
---
- name: '[INSTALLDEP] - Install Dependencies'
apt:
name: "{{ libretranslate_pkg }}"
update_cache: yes

14
tasks/main.yml Normal file
View file

@ -0,0 +1,14 @@
---
- name: Add user
include_tasks: user.yml
- name: Install dependencies
include_tasks: installdeps.yml
- name: Install the app
include_tasks: installapp.yml
- name: Deploy systemd
include_tasks: systemd.yml
tags: systemd

20
tasks/systemd.yml Normal file
View file

@ -0,0 +1,20 @@
---
- name: "[SYSTEMD] - Deploy Systemd config"
template:
src: etc/systemd/system/libretranslate.service.j2
dest: /etc/systemd/system/libretranslate.service
owner: root
group: root
mode: 0644
register: libretranslate
tags: systemd
- name: "[SYSTEMD] - Enable systemd"
service:
name: libretranslate
state: restarted
enabled: yes
daemon_reload: true
when: libretranslate.changed
tags: systemd

12
tasks/user.yml Normal file
View file

@ -0,0 +1,12 @@
---
- name: "[USER] - Add group"
group:
name: '{{ libretranslate_group }}'
state: present
- name: "[USER] - Add user libretranslate"
user:
name: '{{ libretranslate_user }}'
shell: /bin/bash
group: '{{ libretranslate_group }}'

View file

@ -0,0 +1,20 @@
[Unit]
Description=Libretranslate to translate words, sentences and files
Documentation=https://github.com/LibreTranslate/LibreTranslate
Requires=network.target
After=network.target
[Service]
{% for item in libretranslate_environment %}
Environment="{{ item }}"
{% endfor %}
Type=simple
User={{ libretranslate_user }}
ExecStart={{ libretranslate_venv_path }}/bin/python3 libretranslate
WorkingDirectory={{ libretranslate_venv_path }}/bin
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target