Replace application cookbook with git resource

This commit is contained in:
Greg Karékinian 2023-06-28 18:53:59 +02:00
parent 3cf9c3868b
commit 3a5a038f7e
4 changed files with 163 additions and 181 deletions

View File

@ -10,6 +10,5 @@ depends 'kosmos-base'
depends 'kosmos-nodejs'
depends 'kosmos-ipfs'
depends 'firewall'
depends 'application_javascript'
depends 'git'
depends 'redisio'

View File

@ -18,17 +18,14 @@ include_recipe "kosmos-hubot::_user"
include_recipe "kosmos-hubot::_nodejs"
include_recipe "kosmos-base::firewall"
application app_path do
credentials = Chef::EncryptedDataBagItem.load('credentials', app_name)
owner app_user
group app_group
git do
git app_path do
user app_user
group app_group
repository "https://gitea.kosmos.org/kosmos/botka.git"
revision "master"
notifies :restart, "systemd_unit[#{app_name}.service]", :delayed
end
file "#{app_path}/external-scripts.json" do
@ -43,26 +40,13 @@ application app_path do
].to_json
end
npm_install do
execute "npm install" do
cwd app_path
environment "HOME" => app_path
user app_user
end
execute "systemctl daemon-reload" do
command "systemctl daemon-reload"
action :nothing
end
template "/lib/systemd/system/#{app_name}.service" do
source 'nodejs.systemd.service.erb'
owner 'root'
group 'root'
mode '0644'
variables(
user: app_user,
group: app_group,
app_dir: app_path,
entry: "#{app_path}/bin/hubot -a irc",
environment: {
service_env = {
"HUBOT_LOG_LEVEL" => node.chef_environment == "development" ? "debug" : "info",
"HUBOT_IRC_USESSL" => "true",
"HUBOT_IRC_SERVER" => credentials["znc_host"],
@ -89,14 +73,31 @@ application app_path do
"VAPID_PUBLIC_KEY" => credentials['vapid_public_key'],
"VAPID_PRIVATE_KEY" => credentials['vapid_private_key']
}
)
notifies :run, "execute[systemctl daemon-reload]", :delayed
notifies :restart, "service[#{app_name}]", :delayed
end
service app_name do
action [:enable, :start]
end
systemd_unit "#{app_name}.service" do
content({
Unit: {
Description: app_name,
Requires: "redis@6379.service",
After: "redis@6379.service"
},
Service: {
ExecStart: "#{app_path}/bin/hubot -a irc",
WorkingDirectory: app_path,
User: app_user,
Group: app_group,
Environment: service_env.map { |k, v| "'#{k}=#{v}'" },
Restart: 'always'
},
Install: {
WantedBy: 'multi-user.target'
}
})
verify false
triggers_reload true
action [:create, :enable, :start]
end
firewall_rule app_name do

View File

@ -18,17 +18,14 @@ include_recipe "kosmos-hubot::_user"
include_recipe "kosmos-hubot::_nodejs"
include_recipe "kosmos-base::firewall"
application app_path do
data_bag = Chef::EncryptedDataBagItem.load('credentials', app_name)
owner app_user
group app_group
git do
git app_path do
user app_user
group app_group
repository "https://gitea.kosmos.org/kosmos/hal8000.git"
revision "master"
notifies :restart, "systemd_unit[#{app_name}.service]", :delayed
end
file "#{app_path}/external-scripts.json" do
@ -38,7 +35,9 @@ application app_path do
content node[app_name]['hubot_scripts'].to_json
end
npm_install do
execute "npm install" do
cwd app_path
environment "HOME" => app_path
user app_user
end
@ -64,22 +63,11 @@ KREDITS_WALLET_PASSWORD=#{data_bag['kredits_wallet_password']}
EOF
end
execute "systemctl daemon-reload" do
command "systemctl daemon-reload"
action :nothing
cookbook_file "#{app_path}/wallet.json" do
source "wallet.json"
end
template "/lib/systemd/system/#{app_name}.service" do
source 'nodejs.systemd.service.erb'
owner 'root'
group 'root'
mode '0644'
variables(
user: app_user,
group: app_user,
app_dir: app_path,
entry: "#{app_path}/bin/hubot -a xmpp --name hal8000",
environment: {
service_env = {
"HUBOT_LOG_LEVEL" => node.chef_environment == "development" ? "debug" : "info",
"HUBOT_XMPP_USERNAME" => "hal8000@kosmos.org/hubot",
"HUBOT_XMPP_PASSWORD" => data_bag['xmpp_password'],
@ -115,18 +103,31 @@ KREDITS_WALLET_PASSWORD=#{data_bag['kredits_wallet_password']}
"KREDITS_ZOOM_JWT" => data_bag['kredits_zoom_jwt'],
"KREDITS_ZOOM_MEETING_WHITELIST" => "414901303,82557072771"
}
)
notifies :run, "execute[systemctl daemon-reload]", :delayed
notifies :restart, "service[#{app_name}]", :delayed
end
cookbook_file "#{app_path}/wallet.json" do
source "wallet.json"
end
systemd_unit "#{app_name}.service" do
content({
Unit: {
Description: app_name,
Requires: "redis@6379.service",
After: "redis@6379.service"
},
service app_name do
action [:enable, :start]
end
Service: {
ExecStart: "#{app_path}/bin/hubot -a xmpp --name hal8000",
WorkingDirectory: app_path,
User: app_user,
Group: app_group,
Environment: service_env.map { |k, v| "'#{k}=#{v}'" },
Restart: 'always'
},
Install: {
WantedBy: 'multi-user.target'
}
})
verify false
triggers_reload true
action [:create, :enable, :start]
end
firewall_rule app_name do

View File

@ -1,19 +0,0 @@
[Unit]
Description=Start nodejs app
<% unless @without_redis %>
Requires=redis@6379.service
After=redis@6379.service
<% end %>
[Service]
ExecStart=<%= @entry %>
WorkingDirectory=<%= @app_dir %>
User=<%= @user %>
Group=<%= @group %>
<% unless @environment.empty? -%>
Environment=<% @environment.each do |key, value| -%>'<%= key %>=<%= value %>' <% end %>
<% end -%>
Restart=always
[Install]
WantedBy=multi-user.target