From c25d04e7f2e852a5880a2ea32f89bec96a6f459f Mon Sep 17 00:00:00 2001 From: "chris.ditcher" Date: Fri, 12 Jul 2024 16:15:24 -0700 Subject: [PATCH 1/3] Adding preliminary scripts for devs local environment --- local-dev/.gitignore | 1 + local-dev/docker-compose.yml | 44 ++++++++++++++++++++++++++++++++++++ local-dev/init-local-dev.sh | 36 +++++++++++++++++++++++++++++ local-dev/readme.md | 26 +++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 local-dev/.gitignore create mode 100644 local-dev/docker-compose.yml create mode 100644 local-dev/init-local-dev.sh create mode 100644 local-dev/readme.md 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..13f1e66 --- /dev/null +++ b/local-dev/readme.md @@ -0,0 +1,26 @@ +# 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: + WSL2 Ubuntu 24xx installed + After installing, a few things to make life easier, set up your linux environment + 1. ensure bash + `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` + Docker Desktop version > v4.32.0 + Ensure certain features are enabled: + Go to Settings / Resources / WSL integrations and ensure your WSL2 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 director (remember your windows drives can be found under /mnt) + 3. Run the init-local-dev.sh script: `sudo ./init-local-dev.sh` + + From 2f7c336a13cd1173d448a5e86efc380ed5c76a70 Mon Sep 17 00:00:00 2001 From: "chris.ditcher" Date: Mon, 15 Jul 2024 11:40:34 -0700 Subject: [PATCH 2/3] Updated readme --- local-dev/readme.md | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/local-dev/readme.md b/local-dev/readme.md index 13f1e66..eb79412 100644 --- a/local-dev/readme.md +++ b/local-dev/readme.md @@ -1,26 +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. +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: - WSL2 Ubuntu 24xx installed - After installing, a few things to make life easier, set up your linux environment - 1. ensure bash - `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` - Docker Desktop version > v4.32.0 - Ensure certain features are enabled: - Go to Settings / Resources / WSL integrations and ensure your WSL2 integration is selected - Go to Settings / Features in development / Enable host networking +### 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 director (remember your windows drives can be found under /mnt) - 3. Run the init-local-dev.sh script: `sudo ./init-local-dev.sh` +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. From e14de98bf6b2a1ae195bb2d56bd9b513a6b76241 Mon Sep 17 00:00:00 2001 From: "chris.ditcher" Date: Mon, 15 Jul 2024 11:43:50 -0700 Subject: [PATCH 3/3] Updated readme again --- local-dev/readme.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/local-dev/readme.md b/local-dev/readme.md index eb79412..7b12200 100644 --- a/local-dev/readme.md +++ b/local-dev/readme.md @@ -8,23 +8,23 @@ In order to use the scripts in this directory, it will require: **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 +1. ensure bash is your default shell\ `chsh -s /bin/bash` -2. install docker compose +2. install docker compose\ `sudo apt install docker-compose` -3. enable docker without sudo -`sudo groupadd docker` +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 +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` +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.