2017-04-06 19:20:51 +00:00
|
|
|
#
|
|
|
|
# Cookbook Name:: kosmos-mastodon
|
|
|
|
# Recipe:: default
|
|
|
|
#
|
|
|
|
# Copyright 2017, Kosmos
|
|
|
|
#
|
|
|
|
# All rights reserved - Do Not Redistribute
|
|
|
|
#
|
|
|
|
|
|
|
|
include_recipe "kosmos-nodejs"
|
|
|
|
node.override['postgresql']['enable_pgdg_apt'] = false
|
|
|
|
include_recipe "postgresql::server"
|
|
|
|
include_recipe "postgresql::ruby"
|
|
|
|
unless node.chef_environment == "development"
|
|
|
|
node.override['postgresql']['config_pgtune']['db_type'] = "web"
|
|
|
|
include_recipe "postgresql::config_pgtune"
|
|
|
|
end
|
|
|
|
|
|
|
|
postgresql_database 'mastodon' do
|
|
|
|
connection(
|
|
|
|
:host => '127.0.0.1',
|
|
|
|
:port => 5432,
|
|
|
|
:username => 'postgres',
|
|
|
|
:password => node['postgresql']['password']['postgres']
|
|
|
|
)
|
|
|
|
action :create
|
|
|
|
end
|
|
|
|
|
|
|
|
mastodon_path = node["kosmos-mastodon"]["directory"]
|
|
|
|
|
|
|
|
group "mastodon" do
|
|
|
|
gid 62786
|
|
|
|
end
|
|
|
|
|
|
|
|
user "mastodon" do
|
|
|
|
comment "mastodon user"
|
|
|
|
uid 62786
|
|
|
|
gid 62786
|
|
|
|
shell "/bin/bash"
|
|
|
|
home mastodon_path
|
|
|
|
end
|
|
|
|
|
|
|
|
package %w(imagemagick ffmpeg libxml2-dev libxslt1-dev file git curl)
|
|
|
|
node_package %w(yarn)
|
|
|
|
|
|
|
|
application mastodon_path do
|
|
|
|
owner "mastodon"
|
|
|
|
group "mastodon"
|
|
|
|
|
|
|
|
git do
|
|
|
|
user "mastodon"
|
|
|
|
group "mastodon"
|
|
|
|
repository "https://github.com/67P/mastodon.git"
|
2017-04-17 14:52:59 +00:00
|
|
|
revision "kosmos"
|
2017-04-06 19:20:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
mastodon_credentials = Chef::EncryptedDataBagItem.load('credentials', 'mastodon')
|
|
|
|
|
|
|
|
template ".env.production" do
|
|
|
|
source "env.production.erb"
|
|
|
|
mode "0640"
|
|
|
|
owner "mastodon"
|
|
|
|
group "mastodon"
|
|
|
|
variables redis_db: 1,
|
|
|
|
redis_actioncable_db: 2,
|
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-17 14:12:06 +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'],
|
|
|
|
s3_region: "eu-west-1"
|
|
|
|
end
|
|
|
|
|
|
|
|
directory "#{mastodon_path}/public/.well-known" do
|
|
|
|
owner node['nginx']['user']
|
|
|
|
group node['nginx']['group']
|
|
|
|
recursive true
|
|
|
|
end
|
|
|
|
|
2017-04-17 09:40:31 +00:00
|
|
|
ruby_runtime do
|
|
|
|
provider :ruby_build
|
|
|
|
version '2.4.1'
|
|
|
|
end
|
|
|
|
|
2017-04-06 19:20:51 +00:00
|
|
|
bundle_install do
|
|
|
|
user "mastodon"
|
|
|
|
deployment true
|
|
|
|
without %w{development test}
|
|
|
|
end
|
|
|
|
|
|
|
|
npm_install do
|
|
|
|
user "mastodon"
|
|
|
|
end
|
|
|
|
|
|
|
|
rails do
|
|
|
|
migrate true
|
|
|
|
rails_env "production"
|
|
|
|
end
|
|
|
|
|
|
|
|
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"
|
|
|
|
variables user: user,
|
|
|
|
app_dir: mastodon_path,
|
2017-04-17 09:40:31 +00:00
|
|
|
port: node["kosmos-mastodon"]["puma_port"],
|
|
|
|
bundle_path: '/opt/ruby_build/builds/opt/mastodon/bin/bundle'
|
2017-04-06 19:20:51 +00:00
|
|
|
notifies :run, "execute[systemctl daemon-reload]", :delayed
|
2017-04-17 09:40:31 +00:00
|
|
|
# notifies :restart, "service[mastodon-web]", :delayed
|
2017-04-06 19:20:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
service "mastodon-web" do
|
|
|
|
action [:enable, :start]
|
|
|
|
end
|
|
|
|
|
|
|
|
# mastodon-sidekiq service
|
|
|
|
#
|
|
|
|
template "/lib/systemd/system/mastodon-sidekiq.service" do
|
|
|
|
source "mastodon-sidekiq.systemd.service.erb"
|
|
|
|
variables user: user,
|
2017-04-17 09:40:31 +00:00
|
|
|
app_dir: mastodon_path,
|
|
|
|
bundle_path: '/opt/ruby_build/builds/opt/mastodon/bin/bundle'
|
2017-04-06 19:20:51 +00:00
|
|
|
notifies :run, "execute[systemctl daemon-reload]", :delayed
|
2017-04-17 09:40:31 +00:00
|
|
|
# notifies :restart, "service[mastodon-sidekiq]", :delayed
|
2017-04-06 19:20:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
service "mastodon-sidekiq" do
|
|
|
|
action [:enable, :start]
|
|
|
|
end
|
|
|
|
|
|
|
|
# mastodon-streaming service
|
|
|
|
#
|
|
|
|
template "/lib/systemd/system/mastodon-streaming.service" do
|
|
|
|
source "mastodon-streaming.systemd.service.erb"
|
|
|
|
variables user: user,
|
|
|
|
app_dir: mastodon_path,
|
|
|
|
port: node["kosmos-mastodon"]["streaming_port"]
|
|
|
|
notifies :run, "execute[systemctl daemon-reload]", :delayed
|
2017-04-17 09:40:31 +00:00
|
|
|
# notifies :restart, "service[mastodon-streaming]", :delayed
|
2017-04-06 19:20:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
service "mastodon-streaming" do
|
|
|
|
action [:enable, :start]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-17 09:40:31 +00:00
|
|
|
# unless node.chef_environment == "development"
|
|
|
|
# # Backup the database to S3
|
|
|
|
# node.override["backup"]["postgresql"]["host"] = "localhost"
|
|
|
|
# node.override["backup"]["postgresql"]["username"] = "postgres"
|
|
|
|
# node.override["backup"]["postgresql"]["password"] = node['postgresql']['password']['postgres']
|
|
|
|
# include_recipe "backup"
|
|
|
|
# end
|