Connect to the PostgreSQL primary server instead of localhost
Move the db and user creation to its own recipe Refs #186
This commit is contained in:
parent
004a6913b4
commit
4583421597
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
include_recipe "kosmos-nodejs"
|
include_recipe "kosmos-nodejs"
|
||||||
include_recipe "kosmos-redis"
|
include_recipe "kosmos-redis"
|
||||||
include_recipe "kosmos-postgresql"
|
|
||||||
include_recipe "java"
|
include_recipe "java"
|
||||||
|
|
||||||
elasticsearch_user 'elasticsearch'
|
elasticsearch_user 'elasticsearch'
|
||||||
|
@ -42,22 +41,11 @@ end
|
||||||
|
|
||||||
elasticsearch_service 'elasticsearch'
|
elasticsearch_service 'elasticsearch'
|
||||||
|
|
||||||
# TODO: Remove the condition once we have migrated mastodon to andromeda
|
postgresql_data_bag_item = data_bag_item('credentials', 'postgresql')
|
||||||
unless platform?('ubuntu') && node[:platform_version].to_f < 18.04
|
postgresql_primary_node = postgresql_primary
|
||||||
postgresql_data_bag_item = data_bag_item('credentials', 'postgresql')
|
postgresql_server = postgresql_primary_node[:ipaddress]
|
||||||
|
# PostgreSQL is on the same server, connect through localhost
|
||||||
postgresql_user 'mastodon' do
|
postgresql_server = "localhost" if postgresql_primary_node[:hostname] == node[:hostname]
|
||||||
action :create
|
|
||||||
password postgresql_data_bag_item['mastodon_user_password']
|
|
||||||
end
|
|
||||||
|
|
||||||
postgresql_database 'mastodon' do
|
|
||||||
owner 'mastodon'
|
|
||||||
action :create
|
|
||||||
end
|
|
||||||
else
|
|
||||||
postgresql_data_bag_item = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
mastodon_path = node["kosmos-mastodon"]["directory"]
|
mastodon_path = node["kosmos-mastodon"]["directory"]
|
||||||
|
|
||||||
|
@ -169,7 +157,8 @@ application mastodon_path do
|
||||||
s3_region: "eu-west-1",
|
s3_region: "eu-west-1",
|
||||||
vapid_private_key: mastodon_credentials['vapid_private_key'],
|
vapid_private_key: mastodon_credentials['vapid_private_key'],
|
||||||
vapid_public_key: mastodon_credentials['vapid_public_key'],
|
vapid_public_key: mastodon_credentials['vapid_public_key'],
|
||||||
db_pass: postgresql_data_bag_item['mastodon_user_password']
|
db_pass: postgresql_data_bag_item['mastodon_user_password'],
|
||||||
|
db_host: postgresql_server
|
||||||
end
|
end
|
||||||
|
|
||||||
execute "bundle install" do
|
execute "bundle install" do
|
||||||
|
@ -214,18 +203,3 @@ application mastodon_path do
|
||||||
action [:enable, :start]
|
action [:enable, :start]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
|
||||||
# Backup
|
|
||||||
#
|
|
||||||
|
|
||||||
unless node.chef_environment == "development"
|
|
||||||
unless node["backup"]["postgresql"]["databases"].keys.include? 'mastodon'
|
|
||||||
node.override["backup"]["postgresql"]["databases"]["mastodon"] = {
|
|
||||||
username: "mastodon",
|
|
||||||
password: postgresql_data_bag_item['mastodon_user_password']
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
include_recipe "backup"
|
|
||||||
end
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
#
|
||||||
|
# Cookbook Name:: kosmos-mastodon
|
||||||
|
# Recipe:: pg_db
|
||||||
|
#
|
||||||
|
# The MIT License (MIT)
|
||||||
|
#
|
||||||
|
# Copyright:: 2020, Kosmos Developers
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
postgresql_data_bag_item = data_bag_item('credentials', 'postgresql')
|
||||||
|
|
||||||
|
postgresql_user 'mastodon' do
|
||||||
|
action :create
|
||||||
|
password postgresql_data_bag_item['mastodon_user_password']
|
||||||
|
end
|
||||||
|
|
||||||
|
postgresql_database 'mastodon' do
|
||||||
|
owner 'mastodon'
|
||||||
|
action :create
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Backup
|
||||||
|
#
|
||||||
|
|
||||||
|
unless node.chef_environment == "development"
|
||||||
|
unless node["backup"]["postgresql"]["databases"].keys.include? 'mastodon'
|
||||||
|
node.override["backup"]["postgresql"]["databases"]["mastodon"] = {
|
||||||
|
username: "mastodon",
|
||||||
|
password: postgresql_data_bag_item['mastodon_user_password']
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
include_recipe "backup"
|
||||||
|
end
|
|
@ -1,15 +1,9 @@
|
||||||
# Service dependencies
|
# Service dependencies
|
||||||
REDIS_URL=<%= @redis_url %>
|
REDIS_URL=<%= @redis_url %>
|
||||||
DB_HOST=localhost
|
DB_HOST=<%= @db_host %>
|
||||||
DB_NAME=mastodon
|
DB_NAME=mastodon
|
||||||
# TODO: Remove the condition once we have migrated mastodon to andromeda
|
|
||||||
<% if node[:platform_version].to_f < 18.04 -%>
|
|
||||||
DB_USER=postgres
|
|
||||||
DB_PASS=<%= node['postgresql']['password']['postgres'] %>
|
|
||||||
<% else -%>
|
|
||||||
DB_USER=mastodon
|
DB_USER=mastodon
|
||||||
DB_PASS=<%= @db_pass %>
|
DB_PASS=<%= @db_pass %>
|
||||||
<% end -%>
|
|
||||||
DB_PORT=5432
|
DB_PORT=5432
|
||||||
|
|
||||||
# Federation
|
# Federation
|
||||||
|
|
Loading…
Reference in New Issue