diff --git a/config/projects/gitlab.rb b/config/projects/gitlab.rb index 242e245818900d295c39c35cda8dd27aff2e01a0..d20df16d5e0ab96dc2e0b14ce0586dfc18e57791 100644 --- a/config/projects/gitlab.rb +++ b/config/projects/gitlab.rb @@ -76,6 +76,7 @@ dependency "gitlab-selinux" dependency "gitlab-scripts" dependency "gitlab-config-template" dependency "mattermost" +dependency "hubot" # version manifest file dependency "version-manifest" diff --git a/config/software/hubot.rb b/config/software/hubot.rb new file mode 100644 index 0000000000000000000000000000000000000000..b83bfc92ee117e661a072dfc557e6e1a12c6fe8b --- /dev/null +++ b/config/software/hubot.rb @@ -0,0 +1,25 @@ +# +## Copyright:: Copyright (c) 2015 GitLab B.V. +## License:: Apache License, Version 2.0 +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## +# + +name "hubot" +default_version "v2.17.0" + +build do + command 'npm install -g npm@2' + command "npm install -g coffee-script hubot@#{version}" +end diff --git a/files/gitlab-config-template/gitlab.rb.template b/files/gitlab-config-template/gitlab.rb.template index 0c258732fc867dc173a56dadc3bedc55240b9e40..8e23672150f32a2deb9a53e495b1ff39d376c27c 100644 --- a/files/gitlab-config-template/gitlab.rb.template +++ b/files/gitlab-config-template/gitlab.rb.template @@ -816,4 +816,20 @@ external_url 'GENERATED_EXTERNAL_URL' # mattermost_nginx['gzip_proxied'] = "any" # mattermost_nginx['gzip_types'] = [ "text/plain", "text/css", "application/x-javascript", "text/xml", "application/xml", "application/xml+rss", "text/javascript", "application/json" ] # mattermost_nginx['keepalive_timeout'] = 65 -# mattermost_nginx['cache_max_size'] = '5000m' \ No newline at end of file +# mattermost_nginx['cache_max_size'] = '5000m' + +################ +# GitLab Hubot # +################ + +# hubot['enable'] = false +# hubot['username'] = 'hubot' +# hubot['group'] = 'hubot' +# hubot['home'] = '/var/opt/gitlab/hubot' + +# hubot['log_file_directory'] = '/var/log/gitlab/hubot' + +# hubot['name'] = 'hubot' +# hubot['adapter'] = 'mattermost' +# hubot['adapter_config'] = {} +# hubot['scripts'] = [] diff --git a/files/gitlab-cookbooks/gitlab/attributes/default.rb b/files/gitlab-cookbooks/gitlab/attributes/default.rb index 00b83187602caf3261dbbc66dca65b0af618d6f0..bb0e5e49ca95b4de5f073dc82e6b0fd88393630b 100644 --- a/files/gitlab-cookbooks/gitlab/attributes/default.rb +++ b/files/gitlab-cookbooks/gitlab/attributes/default.rb @@ -678,3 +678,19 @@ default['gitlab']['mattermost']['gitlab_user_api_endpoint'] = nil #### default['gitlab']['mattermost-nginx'] = default['gitlab']['nginx'].dup default['gitlab']['mattermost-nginx']['enable'] = false + +#### +# Hubot +#### + +default['gitlab']['hubot']['enable'] = true +default['gitlab']['hubot']['username'] = 'hubot' +default['gitlab']['hubot']['group'] = 'hubot' +default['gitlab']['hubot']['home'] = '/var/opt/gitlab/hubot' + +default['gitlab']['hubot']['log_file_directory'] = '/var/log/gitlab/hubot' + +default['gitlab']['hubot']['name'] = 'hubot' +default['gitlab']['hubot']['adapter'] = 'mattermost' +default['gitlab']['hubot']['adapter_config'] = {} +default['gitlab']['hubot']['scripts'] = [] diff --git a/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb b/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb index 033766d17cb5793edc2d01e773f8fcfad9adebaf..371efac8e5b9c09b0617d860623f54b8495f930b 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb @@ -65,6 +65,7 @@ module Gitlab ci_external_url nil mattermost_external_url nil git_data_dir nil + hubot Mash.new class << self @@ -420,7 +421,8 @@ module Gitlab "mattermost", "external_url", "ci_external_url", - "mattermost_external_url" + "mattermost_external_url", + "hubot" ].each do |key| rkey = key.gsub('_', '-') results['gitlab'][rkey] = Gitlab[key] diff --git a/files/gitlab-cookbooks/gitlab/recipes/default.rb b/files/gitlab-cookbooks/gitlab/recipes/default.rb index 6ea2e8d4e1035a7759b2212511194407563207cf..4aec4b16bab058011640a6e7979330995adef424 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/default.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/default.rb @@ -37,7 +37,7 @@ end node.consume_attributes(Gitlab.generate_config(node['fqdn'])) if File.exists?("/var/opt/gitlab/bootstrapped") - node.set['gitlab']['bootstrap']['enable'] = false + node.set['gitlab']['bootstrap']['enable'] = false end directory "/var/opt/gitlab" do @@ -103,7 +103,8 @@ include_recipe "runit" "remote-syslog", "logrotate", "bootstrap", - "mattermost" + "mattermost", + "hubot" ].each do |service| if node["gitlab"][service]["enable"] include_recipe "gitlab::#{service}" diff --git a/files/gitlab-cookbooks/gitlab/recipes/hubot.rb b/files/gitlab-cookbooks/gitlab/recipes/hubot.rb new file mode 100644 index 0000000000000000000000000000000000000000..934d2e464b13d3e2371cdf4626ab21d40e54bb26 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/recipes/hubot.rb @@ -0,0 +1,73 @@ +# +# Copyright:: Copyright (c) 2012 Opscode, Inc. +# Copyright:: Copyright (c) 2015 GitLab B.V. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +gitlab = node['gitlab'] +hubot = gitlab['hubot'] +hubot_user = hubot['username'] +hubot_group = hubot['group'] +hubot_home = hubot['home'] +hubot_log_dir = gitlab['hubot']['log_file_directory'] +hubot_adapter = hubot['adapter'] +hubot_scripts = hubot['scripts'] + +### +# Create group and user that will be running Hubot +### +account "Hubot user and group" do + username hubot_user + ugid hubot_group + groupname hubot_group + shell '/bin/sh' + home hubot_home + manage node['gitlab']['manage-accounts']['enable'] +end + +### +# Create required directories +### +[ + hubot_home, + hubot_log_dir +].compact.each do |dir| + directory dir do + owner hubot_user + recursive true + end +end + +### +# Install Hubot dependencies +### +execute "Hubot adapter" do + command "npm install -g hubot-#{hubot_adapter}" +end + +hubot_scripts.each do |script| + execute "Hubot script #{script}" do + command "npm install -g #{script}" + end +end + +### +# Hubot control service +### +runit_service "hubot" do + options({ + :log_directory => hubot_log_dir + }.merge(params)) + log_options gitlab['logging'].to_hash.merge(hubot.to_hash) +end diff --git a/files/gitlab-cookbooks/gitlab/recipes/hubot_disable.rb b/files/gitlab-cookbooks/gitlab/recipes/hubot_disable.rb new file mode 100644 index 0000000000000000000000000000000000000000..01a2a7031c49651cb4e4a472469ce8cdd6f204ce --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/recipes/hubot_disable.rb @@ -0,0 +1,20 @@ +# +# Copyright:: Copyright (c) 2015 GitLab B.V. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +runit_service "hubot" do + action :disable +end diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-hubot-log-config.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-hubot-log-config.erb new file mode 100644 index 0000000000000000000000000000000000000000..890209786071651bc340b7938d5b2430ea4c9799 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-hubot-log-config.erb @@ -0,0 +1,6 @@ +<%= "s#@svlogd_size" if @svlogd_size %> +<%= "n#@svlogd_num" if @svlogd_num %> +<%= "t#@svlogd_timeout" if @svlogd_timeout %> +<%= "!#@svlogd_filter" if @svlogd_filter %> +<%= "u#@svlogd_udp" if @svlogd_udp %> +<%= "p#@svlogd_prefix" if @svlogd_prefix %> diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-hubot-log-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-hubot-log-run.erb new file mode 100644 index 0000000000000000000000000000000000000000..c8ab3e301da5fb64cada0b768bdc7e3db11b2faa --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-hubot-log-run.erb @@ -0,0 +1,2 @@ +#!/bin/sh +exec svlogd -tt <%= @options[:log_directory] %> diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-hubot-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-hubot-run.erb new file mode 100644 index 0000000000000000000000000000000000000000..af061ebe375d4a26febb38c5e93d341bc67ff1dd --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-hubot-run.erb @@ -0,0 +1,11 @@ +#!/bin/sh +exec 2>&1 + +export HUBOT_ADAPTER=<%= node['gitlab']['hubot']['adapter'] %> +export HUBOT_NAME=<%= node['gitlab']['hubot']['name'] %> + +<% node['gitlab']['hubot']['adapter_config'].each do |key, value| %> +export <%= key.upcase %>=<%= value %> +<% end %> + +exec chpst -P -U <%= node['gitlab']['hubot']['username'] %> -u <%= node['gitlab']['hubot']['username'] %> /opt/gitlab/embedded/bin/hubot