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

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

管道中的一些测试失败并出现错误 Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)

我的.gitlab-ci.yml文件

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

我的config/initializers/sidekiq.rb文件

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

谁能给我指出正确的方向?谢谢

Gitlab CI 使用的 Docker 中没有一个本地主机。约定是下面声明的服务名称将通过其名称可用于 docker 网络中的其他容器 - redis 在这种情况下:

services:
  - redis:latest

所以用 redis 替换 localhost 应该就足够了:

variables:
-   REDISTOGO_URL: redis://localhost:6379
+   REDISTOGO_URL: redis://redis:6379