[WORKAROUND] Setting up a REDIS cluster in pipeline

I am trying to setup a REDIS cluster as part of my drone 0.8 pipeline. I am working with cpapidas/docker-compose-redis-cluster (https://github.com/cpapidas/docker-compose-redis-cluster/blob/master/README.md). From the research I did, it seems REDIS requires IP addresses rather than hostnames when setting up the cluster. I tried assigning static IPs via a custom network and overriding the ‘drone_default’ network, but I couldn’t get either to work. Is there a way to assign static IPs to the REDIS nodes or dynamically retrieving the IP addresses from the nodes during pipeline execution? if so, could you please provide pointers? thanks!

There is a working example a redis configuration in the documentation:
http://docs.drone.io/redis-example/

I have pasted it below for convenience. Note that it works with hostnames and does not require static IP address. Hope that helps you get started.

pipeline:
  build:
    image: redis
    commands:
      - redis-cli -h redis ping
      - redis-cli -h redis set FOO bar
      - redis-cli -h redis get FOO

services:
  redis:
    image: redis

edit: sorry, I just realized that you are looking to create a redis cluster as opposed to a single redis instance. It is not currently possible to assign static IP addresses to containers.

Thanks very much for the quick reply, @bradrydzewski. I appreciate it.
I will try getting the IPs of the REDIS nodes at runtime to use as input to start the cluster; I will post results. In the meantime, is there an active feature request for enabling static IPs in drone pipelines?

Workaround

REDIS cluster solution: https://github.com/cpapidas/docker-compose-redis-cluster

The REDIS cluster solution I am working with creates a custom network and assigns static IPs to cluster nodes in drone.yml. It then hardcodes the node IPs in the REDIS cluster startup script. I removed the custom network and static IPs; I retrieve the nodes’ IP addresses at runtime and then set an environment variable for each node (all of this is done in drone.yml). Last, I updated the startup script to use the environment variables instead of the hard-coded IPs.

.drone.yml:

<snip/>

rediscluster:
  image: my-redis-cluster
  pull: true
  detach: true
  commands:
    - export REDIS1=$(getent hosts redis1 | awk '{print $1}'):7000
    - export REDIS2=$(getent hosts redis2 | awk '{print $1}'):7001
    - export REDIS3=$(getent hosts redis3 | awk '{print $1}'):7002
    - /docker-entrypoint.sh redis-cluster

REDIS cluster start-up script:

ruby /redis/src/redis-trib.rb create --replicas 0 $REDIS1 $REDIS2 $REDIS3

Hope this helps someone! Thanks!

1 Like