Generate postgres user/db for akkounts, use credentials from env
Co-authored-by: Greg Karékinian <greg@karekinian.com>
This commit is contained in:
@@ -47,7 +47,14 @@ webhooks_allowed_ips = [lndhub_host].compact.uniq.join(',')
|
||||
env = {
|
||||
primary_domain: node['akkounts']['primary_domain'],
|
||||
akkounts_domain: node['akkounts']['domain'],
|
||||
rails_serve_static_files: true
|
||||
rails_serve_static_files: true,
|
||||
db_adapter: "postgresql",
|
||||
pg_host: "pg.kosmos.local",
|
||||
pg_port: 5432,
|
||||
pg_database: "akkounts",
|
||||
pg_database_queue: "akkounts_queue",
|
||||
pg_username: credentials["postgresql"]["username"],
|
||||
pg_password: credentials["postgresql"]["password"]
|
||||
}
|
||||
|
||||
smtp_server, smtp_port = smtp_credentials[:relayhost].split(":")
|
||||
@@ -137,9 +144,9 @@ if lndhub_host
|
||||
if postgres_readonly_host
|
||||
env[:lndhub_admin_ui] = true
|
||||
env[:lndhub_pg_host] = postgres_readonly_host
|
||||
env[:lndhub_pg_database] = node['akkounts']['lndhub']['postgres_db']
|
||||
env[:lndhub_pg_username] = credentials['postgresql_username']
|
||||
env[:lndhub_pg_password] = credentials['postgresql_password']
|
||||
env[:lndhub_pg_database] = node["akkounts"]["lndhub"]["postgres_db"]
|
||||
env[:lndhub_pg_username] = credentials["postgresql"]["username"]
|
||||
env[:lndhub_pg_password] = credentials["postgresql"]["password"]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -207,7 +214,7 @@ systemd_unit "akkounts.service" do
|
||||
Type: "simple",
|
||||
User: deploy_user,
|
||||
WorkingDirectory: deploy_path,
|
||||
Environment: "RAILS_ENV=#{rails_env}",
|
||||
Environment: "RAILS_ENV=#{rails_env} SOLID_QUEUE_IN_PUMA=true",
|
||||
ExecStart: "#{bundle_path} exec puma -C config/puma.rb --pidfile #{deploy_path}/tmp/puma.pid",
|
||||
ExecStop: "#{bundle_path} exec puma -C config/puma.rb --pidfile #{deploy_path}/tmp/puma.pid stop",
|
||||
ExecReload: "#{bundle_path} exec pumactl -F config/puma.rb --pidfile #{deploy_path}/tmp/puma.pid phased-restart",
|
||||
@@ -224,36 +231,6 @@ systemd_unit "akkounts.service" do
|
||||
action [:create, :enable]
|
||||
end
|
||||
|
||||
systemd_unit "akkounts-sidekiq.service" do
|
||||
content({
|
||||
Unit: {
|
||||
Description: "Kosmos Accounts async/background jobs",
|
||||
Documentation: ["https://gitea.kosmos.org/kosmos/akkounts"],
|
||||
Requires: "redis@6379.service",
|
||||
After: "syslog.target network.target redis@6379.service"
|
||||
},
|
||||
Service: {
|
||||
Type: "notify",
|
||||
User: deploy_user,
|
||||
WorkingDirectory: deploy_path,
|
||||
Environment: "MALLOC_ARENA_MAX=2",
|
||||
ExecStart: "#{bundle_path} exec sidekiq -C #{deploy_path}/config/sidekiq.yml -e #{rails_env}",
|
||||
WatchdogSec: "10",
|
||||
Restart: "on-failure",
|
||||
RestartSec: "1",
|
||||
StandardOutput: "syslog",
|
||||
StandardError: "syslog",
|
||||
SyslogIdentifier: "sidekiq"
|
||||
},
|
||||
Install: {
|
||||
WantedBy: "multi-user.target"
|
||||
}
|
||||
})
|
||||
verify false
|
||||
triggers_reload true
|
||||
action [:create, :enable]
|
||||
end
|
||||
|
||||
deploy_env = {
|
||||
"HOME" => deploy_path,
|
||||
"PATH" => "#{ruby_path}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin",
|
||||
@@ -266,15 +243,7 @@ git deploy_path do
|
||||
revision node[app_name]["revision"]
|
||||
user deploy_user
|
||||
group deploy_group
|
||||
# Restart services on deployments
|
||||
notifies :run, "execute[restart #{app_name} services]", :delayed
|
||||
end
|
||||
|
||||
execute "restart #{app_name} services" do
|
||||
command "true"
|
||||
action :nothing
|
||||
notifies :restart, "service[#{app_name}]", :delayed
|
||||
notifies :restart, "service[#{app_name}-sidekiq]", :delayed
|
||||
end
|
||||
|
||||
file "#{deploy_path}/config/master.key" do
|
||||
@@ -282,7 +251,7 @@ file "#{deploy_path}/config/master.key" do
|
||||
mode '0400'
|
||||
owner deploy_user
|
||||
group deploy_group
|
||||
notifies :run, "execute[restart #{app_name} services]", :delayed
|
||||
notifies :restart, "service[#{app_name}]", :delayed
|
||||
end
|
||||
|
||||
template "#{deploy_path}/.env.#{rails_env}" do
|
||||
@@ -292,7 +261,7 @@ template "#{deploy_path}/.env.#{rails_env}" do
|
||||
mode 0600
|
||||
sensitive true
|
||||
variables config: env
|
||||
notifies :run, "execute[restart #{app_name} services]", :delayed
|
||||
notifies :restart, "service[#{app_name}]", :delayed
|
||||
end
|
||||
|
||||
execute "bundle install" do
|
||||
@@ -302,13 +271,6 @@ execute "bundle install" do
|
||||
command "bundle install --without development,test --deployment"
|
||||
end
|
||||
|
||||
# execute "yarn install" do
|
||||
# environment deploy_env
|
||||
# user deploy_user
|
||||
# cwd deploy_path
|
||||
# command "yarn install --pure-lockfile"
|
||||
# end
|
||||
|
||||
execute 'rake db:migrate' do
|
||||
environment deploy_env
|
||||
user deploy_user
|
||||
@@ -329,10 +291,6 @@ service "akkounts" do
|
||||
action [:enable, :start]
|
||||
end
|
||||
|
||||
service "akkounts-sidekiq" do
|
||||
action [:enable, :start]
|
||||
end
|
||||
|
||||
firewall_rule "akkounts_zerotier" do
|
||||
command :allow
|
||||
port node["akkounts"]["port"]
|
||||
|
||||
22
site-cookbooks/kosmos-akkounts/recipes/pg_db.rb
Normal file
22
site-cookbooks/kosmos-akkounts/recipes/pg_db.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# Cookbook:: kosmos-akkounts
|
||||
# Recipe:: pg_db
|
||||
#
|
||||
|
||||
credentials = data_bag_item("credentials", "akkounts")
|
||||
pg_username = credentials["postgresql"]["username"]
|
||||
pg_password = credentials["postgresql"]["password"]
|
||||
|
||||
postgresql_user pg_username do
|
||||
action :create
|
||||
password pg_password
|
||||
end
|
||||
|
||||
databases = ["akkounts", "akkounts_queue"]
|
||||
|
||||
databases.each do |database|
|
||||
postgresql_database database do
|
||||
owner pg_username
|
||||
action :create
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user