Set up libretranslate for kosmos.social

This commit is contained in:
Râu Cao
2023-01-17 17:12:22 +08:00
parent 3933e4c310
commit ed0e030106
7 changed files with 89 additions and 4 deletions

View File

@@ -175,7 +175,10 @@ application mastodon_path do
vapid_private_key: mastodon_credentials['vapid_private_key'],
vapid_public_key: mastodon_credentials['vapid_public_key'],
db_pass: postgresql_data_bag_item['mastodon_user_password'],
db_host: "pg.kosmos.local"
db_host: "pg.kosmos.local",
default_locale: node["kosmos-mastodon"]["default_locale"],
allowed_private_addresses: node["kosmos-mastodon"]["allowed_private_addresses"],
libre_translate_endpoint: node["kosmos-mastodon"]["libre_translate_endpoint"]
notifies :restart, "application[#{mastodon_path}]", :delayed
end

View File

@@ -0,0 +1,64 @@
#
# Cookbook Name:: kosmos-mastodon
# Recipe:: libretranslate
#
build_essential
include_recipe "git"
version = "1.3.8"
%w{ python3 python3-pip python3-setuptools python3-dev }.each do |pkg|
apt_package pkg
end
user "libretranslate" do
shell '/bin/bash'
home "/opt/libretranslate"
manage_home true
end
bash "install_libretranslate" do
code "sudo -u libretranslate pip3 install --user --prefer-binary libretranslate==#{version}"
action :run
not_if { `sudo -u libretranslate pip3 list |grep libretranslate`.split(' ')[1] == version rescue false }
notifies :restart, "service[libretranslate]", :delayed
end
languages = `sudo -u libretranslate /opt/libretranslate/.local/bin/argospm search`
languages.each_line do |line|
lang = line.split(':').first
bash "install_lt_#{lang}" do
code "sudo -u libretranslate /opt/libretranslate/.local/bin/argospm install #{lang}"
action :nothing
end
end
systemd_unit "libretranslate.service" do
content({
Unit: {
Description: "LibreTranslate",
Documentation: ["https://github.com/LibreTranslate/LibreTranslate"],
After: "network.target"
},
Service: {
Type: "simple",
User: "libretranslate",
Group: "libretranslate",
WorkingDirectory: "/opt/libretranslate/",
ExecStart: "/opt/libretranslate/.local/bin/libretranslate --host 127.0.0.1 --port 5000 --disable-files-translation",
Restart: "always"
},
Install: {
WantedBy: "multi-user.target"
}
})
verify false
triggers_reload true
action [:create, :enable]
end
service "libretranslate" do
action [:enable, :start]
end