diff --git a/lib/travis/support.rb b/lib/travis/support.rb index 867a60a2..f42e7134 100644 --- a/lib/travis/support.rb +++ b/lib/travis/support.rb @@ -14,7 +14,28 @@ def logger=(logger) end def redis_pool - @redis_pool ||= ConnectionPool.new { Redis.new( url: Travis.config.redis.url ) } + @redis_pool ||= ConnectionPool.new { + Redis.new( + url: Travis.config.redis.url, + ssl: Travis.config.redis.ssl || false, + ssl_params: redis_ssl_params + ) + } end + + def redis_ssl_params + @redis_ssl_params ||= + begin + return nil unless Travis.config.redis.ssl + + value = {} + value[:ca_path] = ENV['REDIS_SSL_CA_PATH'] if ENV['REDIS_SSL_CA_PATH'] + value[:cert] = OpenSSL::X509::Certificate.new(File.read(ENV['REDIS_SSL_CERT_FILE'])) if ENV['REDIS_SSL_CERT_FILE'] + value[:key] = OpenSSL::PKEY::RSA.new(File.read(ENV['REDIS_SSL_KEY_FILE'])) if ENV['REDIS_SSL_KEY_FILE'] + value[:verify_mode] = OpenSSL::SSL::VERIFY_NONE if Travis.config.ssl_verify == false + value + end + end + end end diff --git a/lib/travis/tasks.rb b/lib/travis/tasks.rb index ebc299c1..c6d157ba 100644 --- a/lib/travis/tasks.rb +++ b/lib/travis/tasks.rb @@ -19,6 +19,20 @@ $stdout.sync = true +def redis_ssl_params + @redis_ssl_params ||= begin + return nil unless Travis.config.redis.ssl + + value = {} + value[:ca_path] = ENV['REDIS_SSL_CA_PATH'] if ENV['REDIS_SSL_CA_PATH'] + value[:cert] = OpenSSL::X509::Certificate.new(File.read(ENV['REDIS_SSL_CERT_FILE'])) if ENV['REDIS_SSL_CERT_FILE'] + value[:key] = OpenSSL::PKEY::RSA.new(File.read(ENV['REDIS_SSL_KEY_FILE'])) if ENV['REDIS_SSL_KEY_FILE'] + value[:verify_mode] = OpenSSL::SSL::VERIFY_NONE if Travis.config.ssl_verify == false + value + end +end + + if Travis.config.sentry.dsn Sentry.init do |config| config.dsn = Travis.config.sentry.dsn @@ -38,7 +52,9 @@ def call(worker, msg, queue) Sidekiq.configure_server do |config| config.redis = { - :url => Travis.config.redis.url + url: Travis.config.redis.url, + ssl: Travis.config.redis.ssl || false, + ssl_params: redis_ssl_params } config.server_middleware do |chain| chain.add Travis::Tasks::Middleware::Metriks @@ -53,7 +69,12 @@ def call(worker, msg, queue) Sidekiq.configure_client do |c| url = Travis.config.redis.url config = Travis.config.sidekiq - c.redis = { url: url, size: config[:pool_size] } + c.redis = { + url: url, + size: config[:pool_size], + ssl: Travis.config.redis.ssl || false, + ssl_params: redis_ssl_params + } end Sidekiq.default_configuration[:max_retries] = Travis.config.sidekiq.retry diff --git a/lib/travis/tasks/config.rb b/lib/travis/tasks/config.rb index db7a3b65..55211e8d 100644 --- a/lib/travis/tasks/config.rb +++ b/lib/travis/tasks/config.rb @@ -29,7 +29,7 @@ def http_basic_auth define host: "travis-ci.org", host_domain: 'travis-ci.com', github: { url: 'https://github.com' }, - redis: { url: "redis://localhost:6379" }, + redis: { url: "redis://localhost:6379", ssl: ENV['REDIS_SSL'] || false }, sentry: { }, metrics: { reporter: 'librato' }, sidekiq: { pool_size: 3, retry: 4 },