136 lines
3.8 KiB
Ruby
136 lines
3.8 KiB
Ruby
#
|
|
# Cookbook:: kosmos_gitea
|
|
# Recipe:: default
|
|
#
|
|
|
|
include_recipe "kosmos-dirsrv::hostsfile"
|
|
|
|
working_directory = node["kosmos_gitea"]["working_directory"]
|
|
git_home_directory = "/home/git"
|
|
repository_root_directory = "#{git_home_directory}/gitea-repositories"
|
|
config_directory = "/etc/gitea"
|
|
gitea_binary_path = "/usr/local/bin/gitea"
|
|
gitea_data_bag_item = data_bag_item("credentials", "gitea")
|
|
smtp_credentials = data_bag_item("credentials", "smtp")
|
|
jwt_secret = gitea_data_bag_item["jwt_secret"]
|
|
internal_token = gitea_data_bag_item["internal_token"]
|
|
secret_key = gitea_data_bag_item["secret_key"]
|
|
|
|
# Dependency
|
|
package "git"
|
|
|
|
user "git" do
|
|
manage_home true
|
|
home "/home/git"
|
|
end
|
|
|
|
directory working_directory do
|
|
owner "git"
|
|
group "git"
|
|
mode "0750"
|
|
end
|
|
|
|
%w(custom custom/options custom/options/label custom/templates custom/templates/custom).each do |path|
|
|
directory "#{working_directory}/#{path}" do
|
|
owner "git"
|
|
group "git"
|
|
mode "0750"
|
|
end
|
|
end
|
|
|
|
# Kosmos label set
|
|
cookbook_file "#{working_directory}/custom/options/label/Kosmos" do
|
|
source "custom/options/label/Kosmos"
|
|
owner "git"
|
|
group "git"
|
|
mode "0640"
|
|
notifies :restart, "service[gitea]", :delayed
|
|
end
|
|
|
|
# Kosmos header template
|
|
cookbook_file "#{working_directory}/custom/templates/custom/header.tmpl" do
|
|
source "custom/templates/custom/header.tmpl"
|
|
owner "git"
|
|
group "git"
|
|
mode "0640"
|
|
notifies :restart, "service[gitea]", :delayed
|
|
end
|
|
|
|
directory config_directory do
|
|
owner "git"
|
|
group "git"
|
|
mode "0750"
|
|
end
|
|
|
|
nginx_proxy_ip_addresses = []
|
|
search(:node, "role:nginx_proxy").each do |node|
|
|
nginx_proxy_ip_addresses << node["knife_zero"]["host"]
|
|
end
|
|
|
|
node.default["kosmos_gitea"]["config"] = {
|
|
"webhook": {
|
|
"allowed_host_list" => "external,#{nginx_proxy_ip_addresses.join(",")}"
|
|
}
|
|
}
|
|
|
|
template "#{config_directory}/app.ini" do
|
|
source "app.ini.erb"
|
|
owner "git"
|
|
group "git"
|
|
mode "0600"
|
|
sensitive true
|
|
variables working_directory: working_directory,
|
|
git_home_directory: git_home_directory,
|
|
repository_root_directory: repository_root_directory,
|
|
config_directory: config_directory,
|
|
gitea_binary_path: gitea_binary_path,
|
|
jwt_secret: jwt_secret,
|
|
internal_token: internal_token,
|
|
secret_key: secret_key,
|
|
postgresql_host: "pg.kosmos.local:5432",
|
|
postgresql_password: gitea_data_bag_item["postgresql_password"],
|
|
smtp_host: smtp_credentials["relayhost"],
|
|
smtp_user: smtp_credentials["user_name"],
|
|
smtp_password: smtp_credentials["password"],
|
|
config: node["kosmos_gitea"]["config"]
|
|
notifies :restart, "service[gitea]", :delayed
|
|
end
|
|
|
|
remote_file gitea_binary_path do
|
|
source node['kosmos_gitea']['binary_url']
|
|
checksum node['kosmos_gitea']['binary_checksum']
|
|
mode "0755"
|
|
notifies :restart, "service[gitea]", :delayed
|
|
end
|
|
|
|
execute "systemctl daemon-reload" do
|
|
action :nothing
|
|
end
|
|
|
|
template "/etc/systemd/system/gitea.service" do
|
|
source "gitea.service.erb"
|
|
variables working_directory: working_directory,
|
|
git_home_directory: git_home_directory,
|
|
config_directory: config_directory,
|
|
gitea_binary_path: gitea_binary_path
|
|
notifies :run, "execute[systemctl daemon-reload]", :delayed
|
|
end
|
|
|
|
service "gitea" do
|
|
action [:enable, :start]
|
|
end
|
|
|
|
firewall_rule 'gitea' do
|
|
port [node["kosmos_gitea"]["port"]]
|
|
source "10.1.1.0/24" # TODO only allow nginx proxy IPs
|
|
protocol :tcp
|
|
command :allow
|
|
end
|
|
|
|
# Hack-fix until we can disable auto-generation of archives
|
|
# TODO https://gitea.kosmos.org/kosmos/chef/issues/395
|
|
cron 'delete auto-generated repo file archives' do
|
|
minute '*/15'
|
|
command 'rm -rf /var/lib/gitea/data/repo-archive/* >/dev/null 2>&1'
|
|
end
|