Optionally compile Gitea from source

This commit is contained in:
Râu Cao 2025-05-31 15:27:21 +04:00
parent 301596500d
commit 00f4c8bd31
Signed by: raucao
GPG Key ID: 37036C356E56CC51
3 changed files with 57 additions and 8 deletions

View File

@ -10,5 +10,8 @@ chef_version '>= 14.0'
depends "firewall"
depends "kosmos_openresty"
depends "kosmos_postgresql"
depends "backup"
depends "kosmos-dirsrv"
depends 'kosmos-nodejs'
depends 'git'
depends 'golang'
depends "backup"

View File

@ -0,0 +1,42 @@
#
# Cookbook:: kosmos_gitea
# Recipe:: compile_from_source
#
# Compiles/installs Gitea from source
#
include_recipe "git"
node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_20.x"
include_recipe 'kosmos-nodejs'
node.override["golang"]["version"] = "1.23.9"
include_recipe "golang"
link "/usr/local/bin/go" do
to "/usr/local/go/bin/go"
end
source_dir = "/opt/gitea"
git source_dir do
repository node["gitea"]["repo"]
revision node["gitea"]["revision"]
action :sync
notifies :run, "execute[npm_install]", :immediately
end
execute "npm_install" do
cwd source_dir
command "npm ci"
action :nothing
notifies :run, "bash[compile_gitea]", :immediately
end
bash "compile_gitea" do
cwd source_dir
environment "TAGS" => "bindata"
code "make build"
action :nothing
notifies :restart, "service[gitea]", :delayed
end

View File

@ -5,11 +5,12 @@
version = node["gitea"]["version"]
download_url = "https://dl.gitea.io/gitea/#{version}/gitea-#{version}-linux-amd64"
compile_from_source = node["gitea"]["repo"] && node["gitea"]["revision"]
working_directory = node["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_binary_path = compile_from_source ? "/opt/gitea/gitea" : "/usr/local/bin/gitea"
gitea_data_bag_item = data_bag_item("credentials", "gitea")
smtp_credentials = data_bag_item("credentials", "smtp")
smtp_addr = smtp_credentials["relayhost"].split(":")[0]
@ -18,7 +19,6 @@ 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
@ -108,12 +108,16 @@ template "#{config_directory}/app.ini" do
notifies :restart, "service[gitea]", :delayed
end
if compile_from_source
include_recipe "kosmos_gitea::compile_from_source"
else
remote_file gitea_binary_path do
source download_url
checksum node['gitea']['checksum']
mode "0755"
notifies :restart, "service[gitea]", :delayed
end
end
execute "systemctl daemon-reload" do
action :nothing