Commit 829e4f8e authored by Robert Speicher's avatar Robert Speicher

Merge branch '1611-geo-improve-info-rake-task' into 'master'

Geo: Added `gitlab:geo:check` and improved `gitlab:env:info` rake tasks

Closes #1611

See merge request !1120
parents 107750eb e4c3d53f
---
title: 'Geo: Added `gitlab:geo:check` and improved `gitlab:envinfo` rake tasks'
merge_request: 1120
author:
module Gitlab
class Proxy
class << self
# Try to detect possible proxies defined in the OS
# @return [Hash] of ENV variables that ends with '_proxy' case-insensitive
def detect_proxy
env.select { |k, v| /_proxy$/i =~ k }
end
private
def env
ENV
end
end
end
end
......@@ -849,6 +849,69 @@ namespace :gitlab do
end
end
namespace :geo do
desc 'GitLab | Check Geo configuration and dependencies'
task check: :environment do
warn_user_is_not_gitlab
start_checking 'Geo'
check_geo_license
check_geo_enabled
check_nodes_http_connection
finished_checking 'Geo'
end
# Checks
########################
def check_geo_license
print 'GitLab Geo is available ... '
if Gitlab::Geo.license_allows?
puts 'yes'.color(:green)
else
puts 'no'.color(:red)
try_fixing_it(
'Upload a new license that includes GitLab Geo feature'
)
for_more_information(see_geo_features_page)
end
end
def check_geo_enabled
print 'GitLab Geo is enabled ... '
if Gitlab::Geo.enabled?
puts 'yes'.color(:green)
else
puts 'no'.color(:red)
try_fixing_it(
'Follow Geo Setup instructions to configure primary and secondary nodes'
)
for_more_information(see_geo_docs)
end
end
def check_nodes_http_connection
return unless Gitlab::Geo.enabled?
if Gitlab::Geo.primary?
Gitlab::Geo.secondary_nodes.each do |node|
print "Can connect to secondary node: '#{node.url}' ... "
check_gitlab_geo_node(node)
end
end
if Gitlab::Geo.secondary?
print 'Can connect to the primary node ... '
check_gitlab_geo_node(Gitlab::Geo.primary_node)
end
end
end
# Helper methods
##########################
......@@ -879,6 +942,18 @@ namespace :gitlab do
"doc/install/installation.md in section \"#{section}\""
end
def see_geo_features_page
'https://about.gitlab.com/features/gitlab-geo/'
end
def see_geo_docs
'doc/gitlab-geo/README.md'
end
def see_custom_certificate_doc
'https://docs.gitlab.com/omnibus/common_installation_problems/README.html#using-self-signed-certificate-or-custom-certificate-authorities'
end
def sudo_gitlab(command)
"sudo -u #{gitlab_user} -H #{command}"
end
......@@ -1025,4 +1100,55 @@ namespace :gitlab do
puts "no".color(:red)
end
end
def check_gitlab_geo_node(node)
display_error = Proc.new do |e|
puts 'no'.color(:red)
puts ' Reason:'.color(:blue)
puts " #{e.message}"
end
begin
response = Net::HTTP.start(node.uri.host, node.uri.port, use_ssl: (node.uri.scheme == 'https')) do |http|
http.request(Net::HTTP::Get.new(node.uri))
end
if response.code_type == Net::HTTPFound
puts 'yes'.color(:green)
else
puts 'no'.color(:red)
end
rescue Errno::ECONNREFUSED => e
display_error.call(e)
try_fixing_it(
'Check if the machine is online and GitLab is running',
'Check your firewall rules and make sure this machine can reach the target machine',
"Make sure port and protocol are correct: '#{node.url}', or change it in Admin > Geo Nodes"
)
rescue SocketError => e
display_error.call(e)
if e.cause && e.cause.message.starts_with?('getaddrinfo')
try_fixing_it(
'Check if your machine can connect to a DNS server',
"Check if your machine can resolve DNS for: '#{node.uri.host}'",
'If machine host is incorrect, change it in Admin > Geo Nodes'
)
end
rescue OpenSSL::SSL::SSLError => e
display_error.call(e)
try_fixing_it(
'If you have a self-signed CA or certificate you need to whitelist it in Omnibus',
)
for_more_information(see_custom_certificate_doc)
try_fixing_it(
'If you have a valid certificate make sure you have the full certificate chain in the pem file'
)
rescue Exception => e
display_error.call(e)
end
end
end
......@@ -15,10 +15,13 @@ namespace :gitlab do
rake_version = run_and_match(%W(rake --version), /[\d\.]+/).try(:to_s)
# check redis version
redis_version = run_and_match(%W(redis-cli --version), /redis-cli (\d+\.\d+\.\d+)/).to_a
# check for system defined proxies
proxies = Gitlab::Proxy.detect_proxy.map{|k,v| "#{k}: #{v}"}.join("\n\t\t")
puts ""
puts "System information".color(:yellow)
puts "System:\t\t#{os_name || "unknown".color(:red)}"
puts "Proxy:\t\t#{proxies.present? ? proxies.color(:green) : "no"}"
puts "Current User:\t#{run_command(%W(whoami))}"
puts "Using RVM:\t#{rvm_version.present? ? "yes".color(:green) : "no"}"
puts "RVM Version:\t#{rvm_version}" if rvm_version.present?
......@@ -83,7 +86,6 @@ namespace :gitlab do
end
puts "Hooks:\t\t#{Gitlab.config.gitlab_shell.hooks_path}"
puts "Git:\t\t#{Gitlab.config.git.bin_path}"
end
end
end
require 'spec_helper'
describe Gitlab::Proxy do
describe '.detect_proxy' do
subject { described_class.detect_proxy }
context 'without any existing proxies' do
before do
allow(described_class).to receive(:env).and_return({})
end
it 'returns an empty array' do
expect(subject).to be_empty
end
end
context 'with existing proxies' do
before do
stubbed_env = { 'http_proxy' => 'http://proxy.example.com',
'HTTPS_PROXY' => 'https://proxy.example.com',
'http_notaproxy' => 'http://example.com' }
allow(described_class).to receive(:env).and_return(stubbed_env)
end
it 'returns a list of existing proxies' do
aggregate_failures 'list of proxies' do
expect(subject).to include('http_proxy')
expect(subject).to include('HTTPS_PROXY')
expect(subject).not_to include('http_notaproxy')
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment