2017-04-06 19:20:51 +00:00
|
|
|
#
|
|
|
|
# Cookbook Name:: kosmos-mastodon
|
|
|
|
# Recipe:: default
|
|
|
|
#
|
2019-04-12 09:41:20 +00:00
|
|
|
# The MIT License (MIT)
|
2017-04-06 19:20:51 +00:00
|
|
|
#
|
2019-04-12 09:41:20 +00:00
|
|
|
# Copyright:: 2019, Kosmos Developers
|
2017-04-06 19:20:51 +00:00
|
|
|
#
|
2019-04-12 09:41:20 +00:00
|
|
|
# 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 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.
|
|
|
|
|
2017-04-06 19:20:51 +00:00
|
|
|
include_recipe "kosmos-nodejs"
|
2017-04-21 10:54:16 +00:00
|
|
|
include_recipe "kosmos-redis"
|
2019-04-10 09:46:50 +00:00
|
|
|
include_recipe "kosmos-postgresql"
|
2019-09-27 08:51:26 +00:00
|
|
|
include_recipe "java"
|
2017-07-27 10:07:56 +00:00
|
|
|
|
2019-09-06 15:24:31 +00:00
|
|
|
elasticsearch_user 'elasticsearch'
|
|
|
|
|
|
|
|
elasticsearch_install 'elasticsearch' do
|
|
|
|
type 'package'
|
2019-09-10 10:29:24 +00:00
|
|
|
version '6.8.2'
|
2019-09-06 15:24:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
elasticsearch_configure 'elasticsearch' do
|
2019-09-27 08:50:56 +00:00
|
|
|
allocated_memory node["kosmos-mastodon"]["elasticsearch"]["allocated_memory"]
|
2019-09-06 15:24:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
elasticsearch_service 'elasticsearch'
|
|
|
|
|
2019-04-12 09:21:37 +00:00
|
|
|
# TODO: Remove the condition once we have migrated mastodon to andromeda
|
2019-04-10 09:46:50 +00:00
|
|
|
unless platform?('ubuntu') && node[:platform_version].to_f < 18.04
|
|
|
|
postgresql_data_bag_item = data_bag_item('credentials', 'postgresql')
|
|
|
|
|
|
|
|
postgresql_user 'mastodon' do
|
|
|
|
action :create
|
|
|
|
password postgresql_data_bag_item['mastodon_user_password']
|
|
|
|
end
|
2017-04-06 19:20:51 +00:00
|
|
|
|
2019-04-10 09:46:50 +00:00
|
|
|
postgresql_database 'mastodon' do
|
|
|
|
owner 'mastodon'
|
|
|
|
action :create
|
|
|
|
end
|
2019-04-10 14:19:05 +00:00
|
|
|
else
|
|
|
|
postgresql_data_bag_item = {}
|
2017-04-06 19:20:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
mastodon_path = node["kosmos-mastodon"]["directory"]
|
|
|
|
|
2019-04-10 14:38:57 +00:00
|
|
|
mastodon_user = "mastodon"
|
|
|
|
|
|
|
|
group mastodon_user do
|
2017-04-06 19:20:51 +00:00
|
|
|
gid 62786
|
|
|
|
end
|
|
|
|
|
2019-04-10 14:38:57 +00:00
|
|
|
user mastodon_user do
|
2017-04-06 19:20:51 +00:00
|
|
|
comment "mastodon user"
|
|
|
|
uid 62786
|
|
|
|
gid 62786
|
|
|
|
shell "/bin/bash"
|
|
|
|
home mastodon_path
|
|
|
|
end
|
|
|
|
|
2017-07-27 10:07:56 +00:00
|
|
|
package %w(imagemagick ffmpeg libxml2-dev libxslt1-dev file git curl pkg-config
|
2018-03-20 15:07:55 +00:00
|
|
|
libprotobuf-dev protobuf-compiler libidn11 libidn11-dev libjemalloc1)
|
2017-07-27 10:07:56 +00:00
|
|
|
|
2018-04-17 11:19:23 +00:00
|
|
|
npm_package "yarn" do
|
2018-05-24 19:29:54 +00:00
|
|
|
version "1.6.0"
|
2017-10-28 21:35:54 +00:00
|
|
|
end
|
2017-06-02 16:30:57 +00:00
|
|
|
|
2019-04-16 11:56:37 +00:00
|
|
|
ruby_version = "2.6.1"
|
2017-04-06 19:20:51 +00:00
|
|
|
|
2019-01-08 15:55:58 +00:00
|
|
|
execute "systemctl daemon-reload" do
|
|
|
|
command "systemctl daemon-reload"
|
|
|
|
action :nothing
|
|
|
|
end
|
|
|
|
|
|
|
|
# mastodon-web service
|
|
|
|
#
|
|
|
|
template "/lib/systemd/system/mastodon-web.service" do
|
|
|
|
source "mastodon-web.systemd.service.erb"
|
2019-04-10 14:38:57 +00:00
|
|
|
variables user: mastodon_user,
|
2019-01-08 15:55:58 +00:00
|
|
|
app_dir: mastodon_path,
|
|
|
|
port: node["kosmos-mastodon"]["puma_port"],
|
|
|
|
bundle_path: "/opt/ruby_build/builds/#{ruby_version}/bin/bundle"
|
|
|
|
notifies :run, "execute[systemctl daemon-reload]", :immediately
|
|
|
|
notifies :restart, "service[mastodon-web]", :delayed
|
|
|
|
end
|
|
|
|
|
|
|
|
# mastodon-sidekiq service
|
|
|
|
#
|
|
|
|
template "/lib/systemd/system/mastodon-sidekiq.service" do
|
|
|
|
source "mastodon-sidekiq.systemd.service.erb"
|
2019-04-10 14:38:57 +00:00
|
|
|
variables user: mastodon_user,
|
2019-01-08 15:55:58 +00:00
|
|
|
app_dir: mastodon_path,
|
|
|
|
bundle_path: "/opt/ruby_build/builds/#{ruby_version}/bin/bundle",
|
|
|
|
sidekiq_threads: node["kosmos-mastodon"]["sidekiq_threads"]
|
|
|
|
notifies :run, "execute[systemctl daemon-reload]", :immediately
|
|
|
|
notifies :restart, "service[mastodon-sidekiq]", :delayed
|
|
|
|
end
|
|
|
|
|
|
|
|
# mastodon-streaming service
|
|
|
|
#
|
|
|
|
template "/lib/systemd/system/mastodon-streaming.service" do
|
|
|
|
source "mastodon-streaming.systemd.service.erb"
|
2019-04-10 14:38:57 +00:00
|
|
|
variables user: mastodon_user,
|
2019-01-08 15:55:58 +00:00
|
|
|
app_dir: mastodon_path,
|
|
|
|
port: node["kosmos-mastodon"]["streaming_port"]
|
|
|
|
notifies :run, "execute[systemctl daemon-reload]", :immediately
|
|
|
|
notifies :restart, "service[mastodon-streaming]", :delayed
|
|
|
|
end
|
|
|
|
|
2017-04-06 19:20:51 +00:00
|
|
|
application mastodon_path do
|
|
|
|
owner "mastodon"
|
|
|
|
group "mastodon"
|
|
|
|
|
2017-06-02 16:30:57 +00:00
|
|
|
environment "HOME" => mastodon_path
|
|
|
|
|
|
|
|
ruby_runtime ruby_version do
|
|
|
|
provider :ruby_build
|
|
|
|
version ruby_version
|
|
|
|
end
|
|
|
|
|
2017-04-06 19:20:51 +00:00
|
|
|
git do
|
2019-04-10 14:38:57 +00:00
|
|
|
user mastodon_user
|
|
|
|
group mastodon_user
|
2019-01-27 04:46:21 +00:00
|
|
|
repository "https://gitea.kosmos.org/kosmos/mastodon.git"
|
|
|
|
revision "production"
|
2017-04-06 19:20:51 +00:00
|
|
|
end
|
|
|
|
|
2019-04-10 09:46:50 +00:00
|
|
|
mastodon_credentials = data_bag_item('credentials', 'mastodon')
|
2017-04-06 19:20:51 +00:00
|
|
|
|
|
|
|
template ".env.production" do
|
|
|
|
source "env.production.erb"
|
|
|
|
mode "0640"
|
2019-04-10 14:38:57 +00:00
|
|
|
owner mastodon_user
|
|
|
|
group mastodon_user
|
2017-06-16 19:08:44 +00:00
|
|
|
variables redis_url: node["kosmos-mastodon"]["redis_url"],
|
2017-04-17 14:12:06 +00:00
|
|
|
domain: node["kosmos-mastodon"]["server_name"],
|
2017-04-06 19:20:51 +00:00
|
|
|
paperclip_secret: mastodon_credentials['paperclip_secret'],
|
|
|
|
secret_key_base: mastodon_credentials['secret_key_base'],
|
|
|
|
otp_secret: mastodon_credentials['otp_secret'],
|
|
|
|
smtp_login: mastodon_credentials['smtp_user_name'],
|
|
|
|
smtp_password: mastodon_credentials['smtp_password'],
|
2017-04-28 13:42:18 +00:00
|
|
|
smtp_from_address: "mail@#{node['kosmos-mastodon']['server_name']}",
|
2017-04-06 19:20:51 +00:00
|
|
|
s3_bucket: "kosmos-social",
|
|
|
|
aws_access_key_id: mastodon_credentials['aws_access_key_id'],
|
|
|
|
aws_secret_access_key: mastodon_credentials['aws_secret_access_key'],
|
2017-07-31 11:00:20 +00:00
|
|
|
s3_region: "eu-west-1",
|
|
|
|
vapid_private_key: mastodon_credentials['vapid_private_key'],
|
2019-04-10 09:46:50 +00:00
|
|
|
vapid_public_key: mastodon_credentials['vapid_public_key'],
|
|
|
|
db_pass: postgresql_data_bag_item['mastodon_user_password']
|
2017-04-06 19:20:51 +00:00
|
|
|
end
|
|
|
|
|
2019-05-08 14:58:31 +00:00
|
|
|
execute "bundle install" do
|
2019-04-10 09:48:47 +00:00
|
|
|
environment "HOME" => mastodon_path
|
2019-04-10 14:38:57 +00:00
|
|
|
user mastodon_user
|
2019-04-10 09:48:47 +00:00
|
|
|
cwd mastodon_path
|
|
|
|
command "/opt/ruby_build/builds/#{ruby_version}/bin/bundle install --without development,test --deployment"
|
2017-04-06 19:20:51 +00:00
|
|
|
end
|
|
|
|
|
2019-05-08 14:58:31 +00:00
|
|
|
execute "yarn install" do
|
2019-09-27 08:55:32 +00:00
|
|
|
environment "HOME" => mastodon_path, "NODE_ENV" => "production"
|
2019-04-10 14:38:57 +00:00
|
|
|
user mastodon_user
|
2017-07-27 10:07:56 +00:00
|
|
|
cwd mastodon_path
|
|
|
|
command "yarn install --pure-lockfile"
|
|
|
|
end
|
|
|
|
|
2017-04-06 19:20:51 +00:00
|
|
|
rails do
|
2019-04-10 09:48:47 +00:00
|
|
|
migrate false
|
2017-04-06 19:20:51 +00:00
|
|
|
rails_env "production"
|
2017-06-02 16:30:57 +00:00
|
|
|
precompile_assets false # buggy, done manually below
|
|
|
|
end
|
|
|
|
|
2019-04-10 09:48:47 +00:00
|
|
|
execute 'rake db:migrate' do
|
|
|
|
environment "RAILS_ENV" => "production", "HOME" => mastodon_path
|
2019-04-10 14:38:57 +00:00
|
|
|
user mastodon_user
|
|
|
|
group mastodon_user
|
2019-04-10 09:48:47 +00:00
|
|
|
cwd mastodon_path
|
|
|
|
command "PATH=\"/opt/ruby_build/builds/#{ruby_version}/bin:$PATH\" bundle exec rake db:migrate"
|
|
|
|
end
|
|
|
|
|
2017-06-02 16:30:57 +00:00
|
|
|
# This is the only way I could find that makes compiling the assets
|
|
|
|
# successfully for now. application_ruby's precompile_assets crashes because
|
|
|
|
# it cannot find the bundled gems
|
|
|
|
execute 'rake assets:precompile' do
|
|
|
|
environment "RAILS_ENV" => "production", "HOME" => mastodon_path
|
2019-04-10 14:38:57 +00:00
|
|
|
user mastodon_user
|
|
|
|
group mastodon_user
|
2017-06-02 16:30:57 +00:00
|
|
|
cwd mastodon_path
|
2019-04-10 09:48:47 +00:00
|
|
|
command "PATH=\"/opt/ruby_build/builds/#{ruby_version}/bin:$PATH\" bundle exec rake assets:precompile"
|
2017-04-06 19:20:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
service "mastodon-web" do
|
|
|
|
action [:enable, :start]
|
|
|
|
end
|
|
|
|
|
|
|
|
service "mastodon-sidekiq" do
|
|
|
|
action [:enable, :start]
|
|
|
|
end
|
|
|
|
|
|
|
|
service "mastodon-streaming" do
|
|
|
|
action [:enable, :start]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-08 04:54:51 +00:00
|
|
|
#
|
|
|
|
# Backup
|
|
|
|
#
|
|
|
|
|
2017-04-21 10:54:16 +00:00
|
|
|
unless node.chef_environment == "development"
|
2019-05-14 14:39:21 +00:00
|
|
|
unless node["backup"]["postgresql"]["databases"].keys.include? 'mastodon'
|
|
|
|
node.override["backup"]["postgresql"]["databases"]["mastodon"] = {
|
|
|
|
username: "mastodon",
|
|
|
|
password: postgresql_data_bag_item['mastodon_user_password']
|
|
|
|
}
|
2018-09-08 04:54:51 +00:00
|
|
|
end
|
|
|
|
|
2017-04-21 10:54:16 +00:00
|
|
|
include_recipe "backup"
|
|
|
|
end
|