From 93bfff7b3fc30fc362b90c4d362528f6e49786e6 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 29 Mar 2013 16:00:36 -0700 Subject: [PATCH 1/6] Added remote redis support to gitlab_update.rb --- config.yml.example | 8 ++++++++ lib/gitlab_config.rb | 4 ++++ lib/gitlab_update.rb | 6 +++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config.yml.example b/config.yml.example index 6b0dbebc40..0e9a89dd98 100644 --- a/config.yml.example +++ b/config.yml.example @@ -14,3 +14,11 @@ repos_path: "/home/git/repositories" # File used as authorized_keys for gitlab user auth_file: "/home/git/.ssh/authorized_keys" + +# Redis settings used for pushing commit notices to gitlab +redis: + bin: /usr/bin/redis-cli + host: 127.0.0.1 + port: 6379 + namespace: resque:gitlab + diff --git a/lib/gitlab_config.rb b/lib/gitlab_config.rb index 6cfee5d264..ac6cc19ef9 100644 --- a/lib/gitlab_config.rb +++ b/lib/gitlab_config.rb @@ -22,4 +22,8 @@ def gitlab_url def http_settings @config['http_settings'] ||= {} end + + def redis + @config['redis'] ||= {} + end end diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb index 82828976e3..acb99cbc9b 100644 --- a/lib/gitlab_update.rb +++ b/lib/gitlab_update.rb @@ -15,6 +15,8 @@ def initialize(repo_path, key_id, refname) @oldrev = ARGV[1] @newrev = ARGV[2] + + @redis = GitlabConfig.new.redis end def exec @@ -49,7 +51,9 @@ def ssh? end def update_redis - command = "env -i redis-cli rpush 'resque:gitlab:queue:post_receive' '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1" + command = "#{@redis['bin']} -h #{@redis['host']} -p #{@redis['port']} rpush '#{@redis['namespace']}:queue:post_receive' "+ + "'{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1" + system(command) end end From 8c55d8f76c032385906a17199f53efe96e7e25cd Mon Sep 17 00:00:00 2001 From: Chr1831 Date: Fri, 29 Mar 2013 16:38:04 -0700 Subject: [PATCH 2/6] Added fallback to default to localhost if the redis configuration block is missing in config.yml --- lib/gitlab_update.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb index acb99cbc9b..93f9c41836 100644 --- a/lib/gitlab_update.rb +++ b/lib/gitlab_update.rb @@ -51,9 +51,13 @@ def ssh? end def update_redis - command = "#{@redis['bin']} -h #{@redis['host']} -p #{@redis['port']} rpush '#{@redis['namespace']}:queue:post_receive' "+ - "'{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1" + if @redis.present? + redis_command = "#{@redis['bin']} -h #{@redis['host']} -p #{@redis['port']} rpush '#{@redis['namespace']}:queue:post_receive'" + else + redis_commend = "env -i redis-cli" + end + command = "#{redis_command} '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1" system(command) end end From 20eea0c76a7aee8088b55c45b0baa252f13f7f5d Mon Sep 17 00:00:00 2001 From: Chr1831 Date: Fri, 29 Mar 2013 16:38:04 -0700 Subject: [PATCH 3/6] Added fallback to default to localhost if the redis configuration block is missing or empty in config.yml --- lib/gitlab_update.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb index acb99cbc9b..93f9c41836 100644 --- a/lib/gitlab_update.rb +++ b/lib/gitlab_update.rb @@ -51,9 +51,13 @@ def ssh? end def update_redis - command = "#{@redis['bin']} -h #{@redis['host']} -p #{@redis['port']} rpush '#{@redis['namespace']}:queue:post_receive' "+ - "'{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1" + if @redis.present? + redis_command = "#{@redis['bin']} -h #{@redis['host']} -p #{@redis['port']} rpush '#{@redis['namespace']}:queue:post_receive'" + else + redis_commend = "env -i redis-cli" + end + command = "#{redis_command} '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1" system(command) end end From 93549d9dcfaa6154550a05ce5758ed0c1d1b2934 Mon Sep 17 00:00:00 2001 From: GitLab Date: Tue, 9 Apr 2013 20:10:32 -0700 Subject: [PATCH 4/6] Added socket support to redis configuration directive per drf's request at https://github.com/gitlabhq/gitlab-shell/pull/35 --- lib/gitlab_update.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb index 93f9c41836..c222af3705 100644 --- a/lib/gitlab_update.rb +++ b/lib/gitlab_update.rb @@ -51,9 +51,12 @@ def ssh? end def update_redis - if @redis.present? + if !@redis.empty? && !@redis.has_key?("socket") redis_command = "#{@redis['bin']} -h #{@redis['host']} -p #{@redis['port']} rpush '#{@redis['namespace']}:queue:post_receive'" + elsif !@redis.empty? && @redis.has_key?("socket") + redis_command = "#{@redis['bin']} -s #{@redis['socket']} rpush '#{@redis['namespace']}:queue:post_receive'" else + # Default to old method of connecting to redis for users that haven't updated their configuration redis_commend = "env -i redis-cli" end From dec440f634a0cfb2e7e7d0477a03c22be33dd257 Mon Sep 17 00:00:00 2001 From: GitLab Date: Tue, 9 Apr 2013 20:43:06 -0700 Subject: [PATCH 5/6] Forgot to update config.yml.example with socket directive... Fixed. --- config.yml.example | 1 + 1 file changed, 1 insertion(+) diff --git a/config.yml.example b/config.yml.example index 0e9a89dd98..26aa28c895 100644 --- a/config.yml.example +++ b/config.yml.example @@ -20,5 +20,6 @@ redis: bin: /usr/bin/redis-cli host: 127.0.0.1 port: 6379 + # socket: /tmp/redis.socket # Only define this if you want to use sockets namespace: resque:gitlab From 2d98c91819bdf8f1b239fc3c421654e298e86d3c Mon Sep 17 00:00:00 2001 From: GitLab Date: Wed, 10 Apr 2013 11:05:53 -0700 Subject: [PATCH 6/6] Refactored update hook as well as fixed a typo. GitlabConfig is now only called once in the update hook. --- lib/gitlab_update.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb index c222af3705..a486ecc146 100644 --- a/lib/gitlab_update.rb +++ b/lib/gitlab_update.rb @@ -3,9 +3,11 @@ class GitlabUpdate def initialize(repo_path, key_id, refname) + config = GitlabConfig.new + @repo_path = repo_path.strip @repo_name = repo_path - @repo_name.gsub!(GitlabConfig.new.repos_path.to_s, "") + @repo_name.gsub!(config.repos_path.to_s, "") @repo_name.gsub!(/\.git$/, "") @repo_name.gsub!(/^\//, "") @@ -16,7 +18,7 @@ def initialize(repo_path, key_id, refname) @oldrev = ARGV[1] @newrev = ARGV[2] - @redis = GitlabConfig.new.redis + @redis = config.redis end def exec @@ -52,15 +54,15 @@ def ssh? def update_redis if !@redis.empty? && !@redis.has_key?("socket") - redis_command = "#{@redis['bin']} -h #{@redis['host']} -p #{@redis['port']} rpush '#{@redis['namespace']}:queue:post_receive'" + redis_command = "#{@redis['bin']} -h #{@redis['host']} -p #{@redis['port']}" elsif !@redis.empty? && @redis.has_key?("socket") - redis_command = "#{@redis['bin']} -s #{@redis['socket']} rpush '#{@redis['namespace']}:queue:post_receive'" + redis_command = "#{@redis['bin']} -s #{@redis['socket']}" else # Default to old method of connecting to redis for users that haven't updated their configuration - redis_commend = "env -i redis-cli" + redis_command = "env -i redis-cli" end - command = "#{redis_command} '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1" + command = "#{redis_command} rpush '#{@redis['namespace']}:queue:post_receive' '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1" system(command) end end