简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM