I am trying to set up Gitlab CI for my Rails project and for this I need Redis. I have added redis to the config file but I am getting an error
Redis::CannotConnectError:
Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
I am using JWTSession
for token-based authentication and this relies on Redis. This is my setup.
.gitlab-ci.yml
image: ruby:2.5.1
services:
- postgres:10.1
- redis:latest
variables:
BUNDLE_PATH: vendor/bundle
DISABLE_SPRING: 1
DB_HOST: postgres
REDIS_URL: redis
before_script:
- apt-get update -qq && apt-get install nodejs -y
- bundle check || bundle install --jobs $(nproc)
- cp config/database.yml.ci config/database.yml
- bundle exec rails db:create RAILS_ENV=test
- bundle exec rails db:schema:load RAILS_ENV=test
stages:
- test
Tests:
stage: test
script:
- bundle exec rspec spec/
only:
- merge_requests
config/initializers/redis.rb
require 'redis'
$redis = Redis.new(url: 'redis://redis:6379/0')
config/initializers/jwt_sessions.rb
JWTSessions.encryption_key = Rails.application.credentials.secret_jwt_encryption_key
JWTSessions.token_store = :redis, {
redis_url: 'redis://localhost:6379',
token_prefix: 'jwt_'
}
I can't seem to figure out how to get this to work. Any hint will be appreciated. Thank you!
UPDATE
I've just tried the connect
block, but got this error:
connect:
# Connect to PostgreSQL database as user postgres, without password
image: redis
script:
- redis-cli -h redis PING
Redis::CannotConnectError:
Error connecting to Redis on localhost:6379 (Errno::EADDRNOTAVAIL)
--- Caused by: ---
# Errno::EADDRNOTAVAIL:
# Cannot assign requested address - connect(2) for [::1]:6379