很少有测试在管道中失败,错误为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
任何人都能指出正确的方向吗?谢谢
答案 0 :(得分:4)
在Docker中没有一个本地主机被Gitlab CI使用。惯例是,在这种情况下,下面声明的服务名称可用于docker网络中的其他容器名称 - redis
:
services:
- redis:latest
因此,将localhost
替换为redis
就足够了:
variables:
- REDISTOGO_URL: redis://localhost:6379
+ REDISTOGO_URL: redis://redis:6379