diff --git a/local-dev/.gitignore b/local-dev/.gitignore new file mode 100644 index 0000000..74b362f --- /dev/null +++ b/local-dev/.gitignore @@ -0,0 +1 @@ +redis \ No newline at end of file diff --git a/local-dev/docker-compose.yml b/local-dev/docker-compose.yml new file mode 100644 index 0000000..eec3b6c --- /dev/null +++ b/local-dev/docker-compose.yml @@ -0,0 +1,44 @@ +version: "3" +services: + redis-1: + image: redis + command: ["redis-server","/etc/redis/redis.conf"] + volumes: + - ./redis/node-1/data:/data + - ./redis/node-1/conf/redis.conf:/etc/redis/redis.conf + network_mode: "host" + redis-2: + image: redis + command: ["redis-server", "/etc/redis/redis.conf"] + volumes: + - ./redis/node-2/data:/data + - ./redis/node-2/conf/redis.conf:/etc/redis/redis.conf + network_mode: "host" + redis-3: + image: redis + command: ["redis-server", "/etc/redis/redis.conf"] + volumes: + - ./redis/node-3/data:/data + - ./redis/node-3/conf/redis.conf:/etc/redis/redis.conf + network_mode: "host" + redis-4: + image: redis + command: ["redis-server", "/etc/redis/redis.conf"] + volumes: + - ./redis/node-4/data:/data + - ./redis/node-4/conf/redis.conf:/etc/redis/redis.conf + network_mode: "host" + redis-5: + image: redis + command: ["redis-server", "/etc/redis/redis.conf"] + volumes: + - ./redis/node-5/data:/data + - ./redis/node-5/conf/redis.conf:/etc/redis/redis.conf + network_mode: "host" + redis-6: + image: redis + command: ["redis-server", "/etc/redis/redis.conf"] + volumes: + - ./redis/node-6/data:/data + - ./redis/node-6/conf/redis.conf:/etc/redis/redis.conf + network_mode: "host" \ No newline at end of file diff --git a/local-dev/init-local-dev.sh b/local-dev/init-local-dev.sh new file mode 100644 index 0000000..5c1f712 --- /dev/null +++ b/local-dev/init-local-dev.sh @@ -0,0 +1,36 @@ +#!/bin/bash +PROJECT_NAME=grad-support +# set up redis +REDIS_MASTER_NODE_NAME=redis-1-1 +# first clean up, remove artifacts +if [ -d redis ]; then + rm -r redis +fi +# create dirs for cluster +mkdir redis; +for i in $(seq 0 5); +do + mkdir -p redis/node-$((i+1))/{conf,data}; + echo "port 700$i +cluster-require-full-coverage no +cluster-migration-barrier 1 +protected-mode no +cluster-enabled yes +cluster-config-file nodes.conf +cluster-node-timeout 5000 +appendonly yes +requirepass secret +masterauth secret" > redis/node-$((i+1))/conf/redis.conf +done +# fire up docker +docker compose --project-name "$PROJECT_NAME" up -d +CONTAINER_ID=$(docker ps --all --filter name="$PROJECT_NAME-$REDIS_MASTER_NODE_NAME" --format="{{.ID}}" | head -n 1) +CONTAINER_STATUS=$(docker inspect --format "{{json .State.Status }}" "$CONTAINER_ID") +until [ "$CONTAINER_STATUS" = '"running"' ] +do + echo "Waiting for container to start..." + sleep 1 +done +echo "Container up, initiating cluster..." +docker exec "$CONTAINER_ID" redis-cli -a secret --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1 --cluster-yes + diff --git a/local-dev/readme.md b/local-dev/readme.md new file mode 100644 index 0000000..7b12200 --- /dev/null +++ b/local-dev/readme.md @@ -0,0 +1,31 @@ +# Local development support tools for GRAD +Most GRAD apis rely on the support of services like nats and redis in order to function correctly. This directory contains scripts that provision dockerized support for developers local environments. +### Prerequisites +In order to use the scripts in this directory, it will require: + +### Windows + +**Install Ubuntu 24.xx.xx using WSL2**. Information can be found [here](https://learn.microsoft.com/en-us/windows/wsl/install) + +After Ubuntu install, a few things to make life easier, set up your linux environment +1. ensure bash is your default shell\ +`chsh -s /bin/bash` +2. install docker compose\ +`sudo apt install docker-compose` +3. enable docker without sudo\ +`sudo groupadd docker`\ +`sudo usermod -aG docker $USER` + +**Install Docker Desktop version > v4.32.0** +Ensure the following features are enabled:\ +Go to *Settings / Resources / WSL integrations* and ensure your WSL2 Ubuntu 24.xx.xx integration is selected\ +Go to *Settings / Features in development / Enable host networking* + +### Running the setup +1. Ensure docker desktop is running +2. Open your WSL linux distro and navigate to this directory (remember your windows drives can be found under /mnt) +3. Run the init-local-dev.sh script:\ `sudo ./init-local-dev.sh` + +The script will provision the necessary volume structure and set up the necessary docker containers etc. + + diff --git a/redis/redis-ha.dc.yaml b/redis/redis-ha.dc.yaml index e2f789f..ef4b857 100644 --- a/redis/redis-ha.dc.yaml +++ b/redis/redis-ha.dc.yaml @@ -34,6 +34,7 @@ objects: appendonly yes protected-mode no requirepass ${REDIS_PASSWORD} + masterauth ${REDIS_PASSWORD} - kind: Secret apiVersion: v1 metadata: @@ -153,4 +154,4 @@ parameters: description: Password for the Redis connection user. generate: expression from: '[a-zA-Z0-9]{16}' - required: true \ No newline at end of file + required: true