149 lines
3.4 KiB
Ruby
149 lines
3.4 KiB
Ruby
#
|
|
# Cookbook:: kosmos_akaunting
|
|
# Recipe:: default
|
|
#
|
|
|
|
app_name = "akaunting"
|
|
deploy_user = node["akaunting"]["user"]
|
|
deploy_group = node["akaunting"]["group"]
|
|
deploy_path = "/opt/#{app_name}"
|
|
credentials = data_bag_item("credentials", "akaunting")
|
|
pg_host = search(:node, "role:postgresql_primary").first["knife_zero"]["host"] rescue "localhost"
|
|
|
|
env = {
|
|
app_name: "Akaunting",
|
|
app_env: "production",
|
|
app_locale: "en-US",
|
|
app_installed: "true",
|
|
app_key: credentials["app_key"],
|
|
app_debug: "true",
|
|
app_schedule_time: "\"09:00\"",
|
|
app_url: "http://akaunting.kosmos.org",
|
|
db_connection: "pgsql",
|
|
db_host: pg_host,
|
|
db_port: "5432",
|
|
db_database: credentials["pg_database"],
|
|
db_username: credentials["pg_username"],
|
|
db_password: credentials["pg_password"],
|
|
log_level: "debug"
|
|
# mail_mailer: "mail",
|
|
# mail_host: "localhost",
|
|
# mail_port: "2525",
|
|
# mail_username: "null",
|
|
# mail_password: "null",
|
|
# mail_encryption: "null",
|
|
# mail_from_name: "null",
|
|
# mail_from_address: "null",
|
|
}
|
|
|
|
%w[
|
|
unzip nginx php8.1 php8.1-cli php8.1-bcmath php8.1-ctype php8.1-curl
|
|
php8.1-dom php8.1-fileinfo php8.1-intl php8.1-fpm php8.1-gd php8.1-mbstring
|
|
php8.1-pdo php8.1-pgsql php8.1-tokenizer php8.1-xml php8.1-zip
|
|
].each do |pkg|
|
|
package pkg
|
|
end
|
|
|
|
# TODO install composer
|
|
|
|
node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_18.x"
|
|
include_recipe "kosmos-nodejs"
|
|
|
|
group deploy_group
|
|
|
|
user deploy_user do
|
|
group deploy_group
|
|
manage_home true
|
|
shell "/bin/bash"
|
|
end
|
|
|
|
directory deploy_path do
|
|
owner deploy_user
|
|
group deploy_group
|
|
mode "0775"
|
|
end
|
|
|
|
git deploy_path do
|
|
repository node[app_name]["repo"]
|
|
revision node[app_name]["revision"]
|
|
user deploy_user
|
|
group deploy_group
|
|
action :sync
|
|
notifies :run, "execute[composer_install]", :immediately
|
|
notifies :run, "execute[npm_install]", :immediately
|
|
notifies :restart, "service[php8.1-fpm]", :delayed
|
|
end
|
|
|
|
execute "composer_install" do
|
|
user deploy_user
|
|
cwd deploy_path
|
|
command "composer install"
|
|
action :nothing
|
|
end
|
|
|
|
execute "npm_install" do
|
|
user deploy_user
|
|
cwd deploy_path
|
|
command "npm install"
|
|
action :nothing
|
|
notifies :run, "execute[compile_assets]", :immediately
|
|
end
|
|
|
|
execute "compile_assets" do
|
|
user deploy_user
|
|
cwd deploy_path
|
|
command "npm run prod"
|
|
action :nothing
|
|
end
|
|
|
|
execute "set_storage_permissions" do
|
|
command "chown -R www-data:www-data #{deploy_path}/storage"
|
|
end
|
|
|
|
template "#{deploy_path}/.env" do
|
|
source 'env.erb'
|
|
owner deploy_user
|
|
group deploy_group
|
|
mode 0660
|
|
sensitive true
|
|
variables config: env
|
|
notifies :restart, "service[php8.1-fpm]", :delayed
|
|
end
|
|
|
|
template "/etc/nginx/sites-available/default" do
|
|
source 'nginx-local.conf.erb'
|
|
owner deploy_user
|
|
group deploy_group
|
|
mode 0660
|
|
variables deploy_path: deploy_path,
|
|
port: node["akaunting"]["port"]
|
|
notifies :restart, "service[nginx]", :delayed
|
|
end
|
|
|
|
# template "/etc/php/8.1/fpm/pool.d/akaunting.conf" do
|
|
# source 'php-fpm.pool.erb'
|
|
# owner deploy_user
|
|
# group deploy_group
|
|
# mode 0600
|
|
# variables user: deploy_user,
|
|
# group: deploy_group,
|
|
# chdir: deploy_path,
|
|
# port: node["akaunting"]["port"]
|
|
# notifies :restart, "service[php8.1-fpm]", :delayed
|
|
# end
|
|
|
|
service "php8.1-fpm" do
|
|
action [:enable, :start]
|
|
end
|
|
|
|
service "nginx" do
|
|
action [:enable, :start]
|
|
end
|
|
|
|
firewall_rule "akaunting_zerotier" do
|
|
command :allow
|
|
port node["akaunting"]["port"]
|
|
protocol :tcp
|
|
source "10.1.1.0/24"
|
|
end
|