Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GiLab CI - Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379

Few tests are failing in pipeline with error Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED).

My .gitlab-ci.yml file

image: starefossen/ruby-node:latest

services:
  - mongo:latest
  - redis:latest

variables:
  MONGODB_URI: mongodb://mongo:27017/db_test
  REDISTOGO_URL: redis://localhost:6379

before_script:
  - bundle install --path=cache/bundler
  - cp config/mongoid.yml.gitlab config/mongoid.yml
  - RAILS_ENV=test bundle exec rake db:create db:migrate

test:
  script:
   - bundle exec rake test

my config/initializers/sidekiq.rb file

require 'sidekiq'
require 'sidekiq-status'

Sidekiq.configure_client do |config|
  config.redis = { size: 5, url: ENV['REDISTOGO_URL'] }
end

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    chain.add Sidekiq::Throttler, storage: :redis
  end
  config.redis = { size: 10, url: ENV['REDISTOGO_URL'] }
end

can anyone point me the right direction? Thank you

like image 911
Tony Vincent Avatar asked Mar 22 '18 07:03

Tony Vincent


1 Answers

There's no one single localhost in Docker which is used by Gitlab CI. The convention is that the service name declared below will be available for other containers in the docker network by it's name - redis in that case:

services:
  - redis:latest

So replacing localhost with redis should be enough:

variables:
-   REDISTOGO_URL: redis://localhost:6379
+   REDISTOGO_URL: redis://redis:6379
like image 93
nattfodd Avatar answered Nov 14 '22 23:11

nattfodd