From d5c03ab2ed7e15747c581917b867ecb729aff5e8 Mon Sep 17 00:00:00 2001 From: dev-mansonthomas Date: Thu, 24 Apr 2025 16:27:25 +0200 Subject: [PATCH 1/2] .env.example : add cluster name format build.sh : add a check to see if ports are in use create_db.sh : put the payload in a variable for debugging purpose and a confirmation message docker-compose.yml : remove version which is deprecated README.md : add instruction to launch the build --- .env.example | 1 + README.md | 6 ++++++ build.sh | 23 ++++++++++++++++++++++ create_db.sh | 48 ++++++++++++++++++++++++++++------------------ docker-compose.yml | 1 - 5 files changed, 59 insertions(+), 20 deletions(-) diff --git a/.env.example b/.env.example index db7a14e..141416e 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ IMAGE=redislabs/redis:latest RE_USERNAME=test@test.com RE_PASS=12345 +#Cluster Name field pattern: ^[-a-zA-Z0-9.]*$ RE_CLUSTER_NAME=test RE_USE_OSS_CLUSTER=false RE_DB_PORT=12000 diff --git a/README.md b/README.md index 55e1816..dbc103f 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,12 @@ export $(cat .env.credentials | xargs) ``` ### Build RE cluster ### + +```shell +./build.sh +``` +It will create the 3 nodes, have the two nodes joining the master node and create the DB + By default, RE cluster supports single endpoint and relies on DMC proxy to calculate hash slot. Multiple endpoints (OSS cluster mode) could be enabled by setting env variable `RE_USE_OSS_CLUSTER=true`. diff --git a/build.sh b/build.sh index 11d46dd..9ecbfd2 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,28 @@ #!/bin/bash +# Récupère tous les ports locaux (ceux avant le ':') dans le fichier +ports=$(grep -E '^[[:space:]]+- "[0-9]+:[0-9]+"' docker-compose.yml | sed -E 's/.*"([0-9]+):[0-9]+".*/\1/') + +# Liste des ports déjà utilisés +used_ports=() + +# Vérifie chaque port +for port in $ports; do + if lsof -iTCP:"$port" -sTCP:LISTEN -Pn > /dev/null; then + used_ports+=("$port") + fi +done + +# Affiche uniquement si au moins un est utilisé +if [ ${#used_ports[@]} -gt 0 ]; then + echo "The following ports are already in use. Stop the program that use them." + for port in "${used_ports[@]}"; do + echo " - $port" + done + exit 1 +fi + + if [[ -n "${DOCKER_ACCESS_TOKEN}" ]]; then echo $DOCKER_ACCESS_TOKEN | docker login --username=$DOCKER_USERNAME --password-stdin fi diff --git a/create_db.sh b/create_db.sh index 1352832..b11da79 100755 --- a/create_db.sh +++ b/create_db.sh @@ -1,21 +1,31 @@ #!/bin/bash -curl -u $RE_USERNAME:$RE_PASS -H "Content-type: application/json" \ - -d '{ - "name": "db", - "port": '$RE_DB_PORT', - "memory_size": 1273741824, - "replication": false, - "eviction_policy": "volatile-lru", - "sharding": true, "shards_count": 3, - "module_list": [ - {"module_args": "","module_name": "ReJSON"}, - {"module_args": "", "module_name": "search"}, - {"module_args": "", "module_name": "timeseries"}, - {"module_args": "", "module_name": "redisgears_2"}, - {"module_args": "", "module_name": "bf"}], - "oss_cluster": '$RE_USE_OSS_CLUSTER', - "proxy_policy": "all-nodes", - "shards_placement": "sparse", - "shard_key_regex": [{"regex": ".*\\{(?.*)\\}.*"},{"regex": "(?.*)"}]}' \ - -k -X POST -f https://localhost:9443/v1/bdbs \ No newline at end of file +# {"module_args": "", "module_name": "redisgears_2"}, +payload='{ + "name": "db", + "port": '"$RE_DB_PORT"', + "memory_size": 1273741824, + "replication": false, + "eviction_policy": "volatile-lru", + "sharding": true, "shards_count": 3, + "module_list": [ + {"module_args": "", "module_name": "ReJSON"}, + {"module_args": "", "module_name": "search"}, + {"module_args": "", "module_name": "timeseries"}, + {"module_args": "", "module_name": "bf"}], + "oss_cluster": '"$RE_USE_OSS_CLUSTER"', + "proxy_policy": "all-nodes", + "shards_placement": "sparse", + "shard_key_regex": [{"regex": ".*\\{(?.*)\\}.*"}, {"regex": "(?.*)"}]}' + + +curl -u $RE_USERNAME:$RE_PASS \ + -H "Content-type: application/json" \ + -d "$payload" \ + -k -sS -X POST \ + -f https://localhost:9443/v1/bdbs || { + echo "Database creation failed" + exit 1 +} + +echo "Database creation... ok" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index b3e570b..e66b6e2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: "3.9" services: master-node: image: "${IMAGE}" From fa3fae77d625f0a786988dd9c08577b95a13fd6c Mon Sep 17 00:00:00 2001 From: dev-mansonthomas Date: Tue, 14 Oct 2025 19:37:58 +0200 Subject: [PATCH 2/2] build.sh : add clean up / force pull before 'compose up' --- README.md | 5 ++++- build.sh | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dbc103f..b824bf8 100644 --- a/README.md +++ b/README.md @@ -31,4 +31,7 @@ All standard RE ports available from your local network: In DMC mode only 12000 port is available, with OSS Cluster API you can connect to each node. - `6372-6374, 6379` - Additional ports accessible from local network. - `9443 - 9445` - REST API connections -- `8443 - 8445` - RE Cluster management UI's \ No newline at end of file +- `8443 - 8445` - RE Cluster management UI's + +Web UI : +https://localhost:8443 \ No newline at end of file diff --git a/build.sh b/build.sh index 9ecbfd2..623605a 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,7 @@ #!/bin/bash +docker compose down --rmi all --volumes --remove-orphans + # Récupère tous les ports locaux (ceux avant le ':') dans le fichier ports=$(grep -E '^[[:space:]]+- "[0-9]+:[0-9]+"' docker-compose.yml | sed -E 's/.*"([0-9]+):[0-9]+".*/\1/') @@ -27,8 +29,12 @@ if [[ -n "${DOCKER_ACCESS_TOKEN}" ]]; then echo $DOCKER_ACCESS_TOKEN | docker login --username=$DOCKER_USERNAME --password-stdin fi + + +docker compose pull + ## Build infrastructure ## -docker compose up -d +docker compose up -d --force-recreate --renew-anon-volumes ## Create cluster ## docker compose exec -T master-node "/opt/setup_cluster.sh"