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

@@ -8,6 +8,7 @@ node.default["kosmos-mastodon"]["server_name"] = "kosmos.social"
node.default["kosmos-mastodon"]["alternate_domains"] = []
node.default["kosmos-mastodon"]["redis_url"] = "redis://localhost:6379/0"
node.default["kosmos-mastodon"]["sidekiq_threads"] = 25
node.default["kosmos-mastodon"]["allowed_private_addresses"] = "127.0.0.1"
node.default["kosmos-mastodon"]["onion_address"] = nil
@@ -19,4 +20,7 @@ node.default["kosmos-mastodon"]["s3_region"] = nil
node.default["kosmos-mastodon"]["s3_bucket"] = nil
node.default["kosmos-mastodon"]["s3_alias_host"] = nil
node.default["kosmos-mastodon"]["default_locale"] = "en"
node.default["kosmos-mastodon"]["libre_translate_endpoint"] = nil
node.override["redisio"]["version"] = "6.2.6"

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

View File

@@ -35,6 +35,9 @@ SMTP_FROM_ADDRESS=<%= @smtp_from_address %>
# Serve static files (to nginx proxy)
RAILS_SERVE_STATIC_FILES=true
# Private addresses/subnets to allow outgoing HTTP requests to
ALLOWED_PRIVATE_ADDRESSES=<%= @allowed_private_addresses %>
<% if @s3_endpoint %>
# S3 (optional)
S3_ENABLED=true
@@ -46,6 +49,14 @@ AWS_ACCESS_KEY_ID=<%= @aws_access_key_id %>
AWS_SECRET_ACCESS_KEY=<%= @aws_secret_access_key %>
<% end %>
# locale
DEFAULT_LOCALE=<%= @default_locale %>
<% if @libre_translate_endpoint %>
# translate
LIBRE_TRANSLATE_ENDPOINT=<%= @libre_translate_endpoint %>
<% end %>
# Optional alias for S3 if you want to use Cloudfront or Cloudflare in front
# S3_CLOUDFRONT_HOST=