Using redis with Gitlab CI
Asked Answered
I

2

10

I am currently using serverless framework and setting up gitlab ci using shared runner.

Following is my gitlab-ci.yml:

image: node:latest

services:
  - redis

cache:
  paths:
    - node_modules/
    - java/

stages:
  - build
  - test
  - review
  - staging
  - production

build:
  stage: build
  script:
      - npm install
  artifacts:
    paths:
      - node_modules/

install:java:
  stage: build
  script:
      - apt-get update
      - apt-get install -y default-jre default-jdk openjdk-7-jre openjdk-7-jdk
      - apt-get update
      - sls dynamodb install
  artifacts:
    paths:
      - java/

connect:
  image: redis
  script:
  - redis-cli -h redis PING

unit test:
  stage: test
  script:
    - sls dynamodb start
    - babel-node ./aws/createDB.js
    - npm run unit
  dependencies:
    - build
    - install:java

unit test job requires redis and is not able to connect. Following error gets thrown, when unit test job starts:

Error while creating redis client: Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379

Can someone point out what's wrong with current config file, thanks!

Imprison answered 25/10, 2017 at 9:1 Comment(1)
Answer below is true, but if you already have taken it into accout, it is possible that you are not setting correctly your credentials to redis (example : you are passing a configuration object and the host key is mislocated). If no creds are found, most libraries default to 127.0.0.1:6379 which also explains your errorIndefatigable
W
24

The host address of the redis service is redis not 127.0.0.1 or localhost.

So make sure you set the host for the redis service to redis in all of your scripts and configuration files.

Wyly answered 25/10, 2017 at 16:30 Comment(1)
+ the doc about accessing a service: docs.gitlab.com/ce/ci/docker/…Muldon
U
6

Just to make people's life easier, I list an example .gitlab-ci.yml to configure Redis in Gitlab CI.

services:
  - redis:latest

stages:
  - test

test:
 script:
   - echo "hello world!"
 stage: test
 variables:
    REDIS_PORT: 6379
    REDIS_HOST: redis
    REDIS_URL: redis://redis:6379
Upsetting answered 12/5, 2022 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.