diff --git a/site-cookbooks/kosmos_gitea/metadata.rb b/site-cookbooks/kosmos_gitea/metadata.rb index f842b03..d643f62 100644 --- a/site-cookbooks/kosmos_gitea/metadata.rb +++ b/site-cookbooks/kosmos_gitea/metadata.rb @@ -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" diff --git a/site-cookbooks/kosmos_gitea/recipes/compile_from_source.rb b/site-cookbooks/kosmos_gitea/recipes/compile_from_source.rb new file mode 100644 index 0000000..488d8cc --- /dev/null +++ b/site-cookbooks/kosmos_gitea/recipes/compile_from_source.rb @@ -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 diff --git a/site-cookbooks/kosmos_gitea/recipes/default.rb b/site-cookbooks/kosmos_gitea/recipes/default.rb index afae849..ce1bc41 100644 --- a/site-cookbooks/kosmos_gitea/recipes/default.rb +++ b/site-cookbooks/kosmos_gitea/recipes/default.rb @@ -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,11 +108,15 @@ template "#{config_directory}/app.ini" do notifies :restart, "service[gitea]", :delayed end -remote_file gitea_binary_path do - source download_url - checksum node['gitea']['checksum'] - mode "0755" - notifies :restart, "service[gitea]", :delayed +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