114 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			114 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
#
 | 
						|
# Cookbook:: kosmos-akkounts
 | 
						|
# Recipe:: default
 | 
						|
#
 | 
						|
# The MIT License (MIT)
 | 
						|
#
 | 
						|
# Copyright:: 2019, 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.
 | 
						|
 | 
						|
include_recipe 'kosmos-nodejs'
 | 
						|
 | 
						|
app_name     = "akkounts-api"
 | 
						|
deploy_user  = "deploy"
 | 
						|
deploy_group = "deploy"
 | 
						|
credentials  = Chef::EncryptedDataBagItem.load('credentials', app_name)
 | 
						|
 | 
						|
group deploy_group
 | 
						|
 | 
						|
user deploy_user do
 | 
						|
  group       deploy_group
 | 
						|
  manage_home true
 | 
						|
  shell       "/bin/bash"
 | 
						|
  comment     "deploy user"
 | 
						|
end
 | 
						|
 | 
						|
path_to_deploy = "/opt/#{app_name}"
 | 
						|
application path_to_deploy do
 | 
						|
  owner deploy_user
 | 
						|
  group deploy_group
 | 
						|
 | 
						|
  # Take care of application restarts manually, in the git resource
 | 
						|
  action_on_update false
 | 
						|
 | 
						|
  git do
 | 
						|
    user  deploy_user
 | 
						|
    group deploy_group
 | 
						|
    repository "https://github.com/67P/#{app_name}.git"
 | 
						|
    revision   node[app_name]['revision']
 | 
						|
    # Restart service on deployments
 | 
						|
    notifies :restart, "application[#{path_to_deploy}]", :delayed
 | 
						|
  end
 | 
						|
 | 
						|
  npm_install do
 | 
						|
    user deploy_user
 | 
						|
  end
 | 
						|
 | 
						|
  execute "systemctl daemon-reload" do
 | 
						|
    command "systemctl daemon-reload"
 | 
						|
    action :nothing
 | 
						|
  end
 | 
						|
 | 
						|
  smtp_credentials = Chef::EncryptedDataBagItem.load('credentials', 'smtp')
 | 
						|
 | 
						|
  template "#{path_to_deploy}/.env" do
 | 
						|
    source "dotenv.erb"
 | 
						|
    sensitive true
 | 
						|
    owner deploy_user
 | 
						|
    group deploy_group
 | 
						|
    variables btcpay_url: "https://btcpay.kosmos.org",
 | 
						|
              btcpay_privkey: credentials["btcpay_privkey"],
 | 
						|
              btcpay_merchant: credentials["btcpay_merchant"],
 | 
						|
              btcpay_store_id: credentials["btcpay_store_id"],
 | 
						|
              btcpay_webhook_host: "https://#{node[app_name]["server_name"]}",
 | 
						|
              btcpay_webhook_token: credentials["btcpay_webhook_token"],
 | 
						|
              smtp_host: "smtp.mailgun.org",
 | 
						|
              smtp_use_tls: true,
 | 
						|
              smtp_username: smtp_credentials['user_name'],
 | 
						|
              smtp_password: smtp_credentials['password'],
 | 
						|
              mastodon_host: "https://#{node["kosmos-mastodon"]["server_name"]}",
 | 
						|
              mastodon_auth_token: credentials["mastodon_auth_token"]
 | 
						|
    mode '0440'
 | 
						|
    # Restart service when the config changes
 | 
						|
    notifies :restart, "application[#{path_to_deploy}]", :delayed
 | 
						|
  end
 | 
						|
 | 
						|
  template "/lib/systemd/system/#{app_name}.service" do
 | 
						|
    source 'nodejs.systemd.service.erb'
 | 
						|
    owner 'root'
 | 
						|
    group 'root'
 | 
						|
    mode '0640'
 | 
						|
    variables(
 | 
						|
      user: deploy_user,
 | 
						|
      group: deploy_group,
 | 
						|
      app_dir: path_to_deploy,
 | 
						|
      entry: "/usr/bin/env node release/index.js"
 | 
						|
    )
 | 
						|
    notifies :run, "execute[systemctl daemon-reload]", :delayed
 | 
						|
    notifies :restart, "service[#{app_name}]", :delayed
 | 
						|
  end
 | 
						|
 | 
						|
  service app_name do
 | 
						|
    action [:enable, :start]
 | 
						|
  end
 | 
						|
end
 | 
						|
 | 
						|
include_recipe 'kosmos-akkounts::nginx'
 |