From f72e9f2a48b6f24500ca42e653005bd7e5d378ce Mon Sep 17 00:00:00 2001
From: Zac Clifton <43915749+Cliftonz@users.noreply.github.com>
Date: Fri, 31 May 2024 16:05:10 -0400
Subject: [PATCH 1/8] Refactor database setup to utilize Docker

The previous code that checked homebrew and installed databases if not found has been modified. Now, the script checks if MongoDB and Redis are installed, and if they aren't, it starts Docker Compose to run the databases. It also copies the example environment file to a specified location and starts up the Docker Compose. This improves the local dev environment setup by using Docker for database management.
---
 scripts/dev-environment-setup.sh | 56 +++++++++++++-------------------
 1 file changed, 23 insertions(+), 33 deletions(-)

diff --git a/scripts/dev-environment-setup.sh b/scripts/dev-environment-setup.sh
index 63fa2d3702b..4b402e39656 100755
--- a/scripts/dev-environment-setup.sh
+++ b/scripts/dev-environment-setup.sh
@@ -383,43 +383,33 @@ install_aws_cli () {
     fi
 }
 
-install_databases () {
-    SKIP="$(check_homebrew)"
-
-    if [[ -z "$SKIP" ]]; then
-        installing_dependency "Databases"
+start_database() {
+  # Check if mongodb is installed
+  brew ls --versions mongodb > /dev/null
+  if [ $? -eq 0 ]; then
+    echo "Error: MongoDB is already installed via brew. Please uninstall it first."
+    exit 1
+  fi
+
+   # Check if redis is installed
+   brew ls --versions redis > /dev/null
+   if [ $? -eq 0 ]; then
+     echo "Error: Redis is already installed via brew. Please uninstall it first."
+     exit 1
+   fi
 
-        brew tap mongodb/brew
+   # If neither mongodb nor redis is installed
+   echo "Starting up Docker Compose as MongoDB and Redis are not installed..."
 
-        DATABASES=(
-            mongodb-community@5.0
-            redis
-        )
-        brew install "${DATABASES[@]}"
+   echo "Mongodb or Redis is not installed. Starting Docker Compose..."
 
-        echo "Run the services in the background"
+   # Copy the example env file
+   cp ../docker/.env.example ../docker/local/deployment/.env
 
-        TEST_REDIS_CMD=$(execute_command_without_error_print "redis-cli --version")
-        if [[ -z "$TEST_REDIS_CMD" ]] || [[ "$TEST_REDIS_CMD" == "zsh: command not found: redis-cli" ]]; then
-            error_message "Redis"
-        else
-            echo "Run Redis service in the background"
-    	    brew services restart redis
-            success_message "MongoDB"
-        fi
+   # Start Docker Compose
+   docker-compose -f ../docker/local/deployment/docker-compose.yml up
 
-        TEST_MONGO_CMD=$(execute_command_without_error_print "mongosh --version")
-        if [[ -z "$TEST_MONGO_CMD" ]] || [[ "$TEST_MONGO_CMD" == "zsh: command not found: mongosh" ]]; then
-            error_message "MongoDB"
-        else
-            echo "Run MongoDB service in the background"
-    	    brew services start mongodb/brew/mongodb-community@5.0
-            success_message "MongoDB"
-        fi
-    else
-        skip_message "Databases"
-        echo "$SKIP"
-    fi
+   echo "Started databases in docker"
 }
 
 create_local_dev_domain () {
@@ -489,8 +479,8 @@ install_novu_tools () {
     install_node
     install_pnpm
     install_docker
-    install_databases
     install_aws_cli
+    start_database
     create_local_dev_domain
 }
 

From 4be06d737c673a52e1b3974b2bc4f32256195468 Mon Sep 17 00:00:00 2001
From: Zac Clifton <43915749+Cliftonz@users.noreply.github.com>
Date: Fri, 31 May 2024 18:12:56 -0400
Subject: [PATCH 2/8] Refactor dev environment setup script

The script for setting up the development environment has been updated for better readability and organization. Changes include removing redundant messages, moving Docker start-up into a designated function, and changing the Docker Compose command to start in detached mode. The script also includes success messages after starting Docker and verifying git installation.
---
 scripts/dev-environment-setup.sh | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/scripts/dev-environment-setup.sh b/scripts/dev-environment-setup.sh
index 4b402e39656..f5cf3bdd2cc 100755
--- a/scripts/dev-environment-setup.sh
+++ b/scripts/dev-environment-setup.sh
@@ -28,6 +28,12 @@ success_message () {
     echo " "
 }
 
+start_success_message () {
+    echo " "
+    echo "✅ $1 has been started"
+    echo " "
+}
+
 already_installed_message () {
     echo " "
     echo "✅ $1 is already installed"
@@ -398,18 +404,14 @@ start_database() {
      exit 1
    fi
 
-   # If neither mongodb nor redis is installed
-   echo "Starting up Docker Compose as MongoDB and Redis are not installed..."
-
-   echo "Mongodb or Redis is not installed. Starting Docker Compose..."
-
    # Copy the example env file
-   cp ../docker/.env.example ../docker/local/deployment/.env
+   cp ./docker/.env.example ./docker/local/development/.env
 
-   # Start Docker Compose
-   docker-compose -f ../docker/local/deployment/docker-compose.yml up
+   # Start Docker Compose detached
+   docker-compose -f ./docker/local/development/docker-compose.yml up -d
 
-   echo "Started databases in docker"
+   start_success_message "Docker Infrastructure"
+   echo "Note: To manually start go to /docker in the project"
 }
 
 create_local_dev_domain () {
@@ -438,6 +440,9 @@ check_git () {
         echo "⛔️ Git is a hard dependency to clone the monorepo"
         exit 1
     fi
+
+    already_installed_message "git"
+
 }
 
 clone_monorepo () {

From 192e7347d970eb908b2418c08355ea4476e0fd5c Mon Sep 17 00:00:00 2001
From: Zac Clifton <43915749+Cliftonz@users.noreply.github.com>
Date: Mon, 3 Jun 2024 08:53:06 -0400
Subject: [PATCH 3/8] Update dev environment setup script for MongoDB and Redis
 checks

The development environment setup script has been updated to handle scenarios where MongoDB and Redis have already been installed. Rather than exiting, it now sets a flag and proceeds if both services aren't installed already, copying the environment file and starting Docker Compose accordingly.
---
 scripts/dev-environment-setup.sh | 34 +++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/scripts/dev-environment-setup.sh b/scripts/dev-environment-setup.sh
index f5cf3bdd2cc..904683ba09d 100755
--- a/scripts/dev-environment-setup.sh
+++ b/scripts/dev-environment-setup.sh
@@ -390,28 +390,34 @@ install_aws_cli () {
 }
 
 start_database() {
-  # Check if mongodb is installed
-  brew ls --versions mongodb > /dev/null
-  if [ $? -eq 0 ]; then
-    echo "Error: MongoDB is already installed via brew. Please uninstall it first."
-    exit 1
-  fi
+   # Initialize flag
+   already_installed=0
+
+   # Check if mongodb is installed
+   brew ls --versions mongodb > /dev/null
+   if [ $? -eq 0 ]; then
+     echo "Warning: MongoDB is already installed via brew. Please uninstall it first."
+     already_installed=1
+   fi
 
    # Check if redis is installed
    brew ls --versions redis > /dev/null
    if [ $? -eq 0 ]; then
-     echo "Error: Redis is already installed via brew. Please uninstall it first."
-     exit 1
+     echo "Warning: Redis is already installed via brew. Please uninstall it first."
+     already_installed=1
    fi
 
-   # Copy the example env file
-   cp ./docker/.env.example ./docker/local/development/.env
+   # Only copy the example env file and start Docker Compose if both MongoDB and Redis are not already installed
+   if [ $already_installed -ne 1 ]; then
+     # Copy the example env file
+     cp ./docker/.env.example ./docker/local/development/.env
 
-   # Start Docker Compose detached
-   docker-compose -f ./docker/local/development/docker-compose.yml up -d
+     # Start Docker Compose detached
+     docker-compose -f ./docker/local/development/docker-compose.yml up -d
 
-   start_success_message "Docker Infrastructure"
-   echo "Note: To manually start go to /docker in the project"
+     start_success_message "Docker Infrastructure"
+     echo "Note: To manually start go to /docker in the project"
+   fi
 }
 
 create_local_dev_domain () {

From 89d94e38c132f0695a6ce4d5749eb3c03e4d96be Mon Sep 17 00:00:00 2001
From: Zac Clifton <43915749+Cliftonz@users.noreply.github.com>
Date: Mon, 3 Jun 2024 09:01:59 -0400
Subject: [PATCH 4/8] Add brew installation check before starting database

The updated developer environment setup script now checks for availability of the brew command before trying to start the database. This provides cleaner handling for environments where brew is not available. If brew command is not found, the script checks the default ports for MongoDB and Redis instead.
---
 scripts/dev-environment-setup.sh | 74 ++++++++++++++++++++------------
 1 file changed, 46 insertions(+), 28 deletions(-)

diff --git a/scripts/dev-environment-setup.sh b/scripts/dev-environment-setup.sh
index 904683ba09d..b101fdfd078 100755
--- a/scripts/dev-environment-setup.sh
+++ b/scripts/dev-environment-setup.sh
@@ -390,34 +390,52 @@ install_aws_cli () {
 }
 
 start_database() {
-   # Initialize flag
-   already_installed=0
-
-   # Check if mongodb is installed
-   brew ls --versions mongodb > /dev/null
-   if [ $? -eq 0 ]; then
-     echo "Warning: MongoDB is already installed via brew. Please uninstall it first."
-     already_installed=1
-   fi
-
-   # Check if redis is installed
-   brew ls --versions redis > /dev/null
-   if [ $? -eq 0 ]; then
-     echo "Warning: Redis is already installed via brew. Please uninstall it first."
-     already_installed=1
-   fi
-
-   # Only copy the example env file and start Docker Compose if both MongoDB and Redis are not already installed
-   if [ $already_installed -ne 1 ]; then
-     # Copy the example env file
-     cp ./docker/.env.example ./docker/local/development/.env
-
-     # Start Docker Compose detached
-     docker-compose -f ./docker/local/development/docker-compose.yml up -d
-
-     start_success_message "Docker Infrastructure"
-     echo "Note: To manually start go to /docker in the project"
-   fi
+  # Check if brew is installed
+  command -v brew > /dev/null 2>&1
+
+  # Initialize flag
+  already_installed=0
+
+  if [ $? -eq 0 ]; then
+
+
+      # Check if mongodb is installed
+      brew ls --versions mongodb > /dev/null
+      if [ $? -eq 0 ]; then
+        echo "Warning: MongoDB is already installed via brew. Please uninstall it first."
+        already_installed=1
+      fi
+
+      # Check if redis is installed
+      brew ls --versions redis > /dev/null
+      if [ $? -eq 0 ]; then
+        echo "Warning: Redis is already installed via brew. Please uninstall it first."
+        already_installed=1
+      fi
+  else
+      echo "brew is not installed, checking default ports for MongoDB and Redis"
+      # Check MongoDB (port 27017) and Redis (port 6379)
+      if lsof -Pi :27017 -sTCP:LISTEN -t >/dev/null ; then
+        echo "Warning: MongoDB is running on port 27017. Please stop it first."
+        already_installed=1
+      fi
+      if lsof -Pi :6379 -sTCP:LISTEN -t >/dev/null ; then
+        echo "Warning: Redis is running on port 6379. Please stop it first."
+        already_installed=1
+      fi
+  fi
+
+  # Only copy the example env file and start Docker Compose if both MongoDB and Redis are not already installed
+  if [ $already_installed -ne 1 ]; then
+      # Copy the example env file
+      cp ./docker/.env.example ./docker/local/development/.env
+
+      # Start Docker Compose detached
+      docker-compose -f ./docker/local/development/docker-compose.yml up -d
+
+      start_success_message "Docker Infrastructure"
+      echo "Note: To manually start go to /docker in the project"
+  fi
 }
 
 create_local_dev_domain () {

From c3f60ea07a6b242985a0fe04681445c944a61ebf Mon Sep 17 00:00:00 2001
From: Zac Clifton <43915749+Cliftonz@users.noreply.github.com>
Date: Mon, 3 Jun 2024 09:03:11 -0400
Subject: [PATCH 5/8] Add brew installation check before starting database

The updated developer environment setup script now checks for availability of the brew command before trying to start the database. This provides cleaner handling for environments where brew is not available. If brew command is not found, the script checks the default ports for MongoDB and Redis instead.
---
 .cspell.json | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.cspell.json b/.cspell.json
index a6aa0e92ed3..b6ab86c423d 100644
--- a/.cspell.json
+++ b/.cspell.json
@@ -599,7 +599,8 @@
     "xkeysib",
     "zulip",
     "zwnj",
-    "prepush"
+    "prepush",
+    "xcodebuild"
   ],
   "flagWords": [],
   "patterns": [

From 6c428eb88279a2ca1dd2c5703ef0a1a8655c4a8d Mon Sep 17 00:00:00 2001
From: Zac Clifton <43915749+Cliftonz@users.noreply.github.com>
Date: Thu, 6 Jun 2024 11:20:32 -0400
Subject: [PATCH 6/8] Update dev-environment-setup.sh to add messaging for
 manual database start

Updated the dev-environment-setup.sh script to include messages for manual database start. This includes a recommendation for removing mongodb and redis databases from brew and instructions on how to manually start the containerized databases in the project.
---
 scripts/dev-environment-setup.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/dev-environment-setup.sh b/scripts/dev-environment-setup.sh
index b101fdfd078..750d502b577 100755
--- a/scripts/dev-environment-setup.sh
+++ b/scripts/dev-environment-setup.sh
@@ -153,7 +153,7 @@ install_os_dependencies () {
     if [[ "$OSTYPE" == "linux-gnu"* ]]; then
         installing_dependency "Linux dependencies"
         echo "//TODO"
-	install_novu_tools
+	  install_novu_tools
     elif [[ "$OSTYPE" == "darwin"* ]]; then
         installing_dependency "MacOsx dependencies"
         install_macosx_dependencies
@@ -434,7 +434,9 @@ start_database() {
       docker-compose -f ./docker/local/development/docker-compose.yml up -d
 
       start_success_message "Docker Infrastructure"
-      echo "Note: To manually start go to /docker in the project"
+  else
+      echo "We recommend removing mongodb and redis databases from brew with 'brew remove <package_name>'."
+      echo "To manually start the containerized databases by going to /docker in the novu project"
   fi
 }
 

From e1fcd7d6976df405eaa8b326ea348012e63dbb4f Mon Sep 17 00:00:00 2001
From: Zac Clifton <43915749+Cliftonz@users.noreply.github.com>
Date: Thu, 6 Jun 2024 11:26:53 -0400
Subject: [PATCH 7/8] Remove local dev domain setup from dev environment script

This commit removes the function create_local_dev_domain from the development environment setup script. It was no longer necessary as it was causing conflicts with other processes. This would ensure the script runs smoother and cause less conflicts while setting up the development environment.
---
 scripts/dev-environment-setup.sh | 19 -------------------
 1 file changed, 19 deletions(-)

diff --git a/scripts/dev-environment-setup.sh b/scripts/dev-environment-setup.sh
index 750d502b577..3574c4e20bd 100755
--- a/scripts/dev-environment-setup.sh
+++ b/scripts/dev-environment-setup.sh
@@ -440,24 +440,6 @@ start_database() {
   fi
 }
 
-create_local_dev_domain () {
-    FILENAME="/etc/hosts"
-    HOST="local.novu.co"
-    IP="127.0.0.1"
-    ENTRY="$IP\t$HOST"
-
-    CMD=$(execute_command_without_error_print "grep -R $HOST $FILENAME")
-
-    if [[ -z $CMD ]]; then
-        echo "$ENTRY" | sudo tee -a $FILENAME
-        success_message "Local DEV domain"
-    elif [[ $CMD == *"$HOST"* ]]; then
-        already_installed_message "Local DEV domain"
-    else
-        error_message "Local DEV domain"
-    fi
-}
-
 check_git () {
     TEST_GIT_CMD=$(execute_command_without_error_print "git --version")
 
@@ -512,7 +494,6 @@ install_novu_tools () {
     install_docker
     install_aws_cli
     start_database
-    create_local_dev_domain
 }
 
 install_os_dependencies () {

From a78d8d54944f6ef6e81d01229ed84053f5a0f6c0 Mon Sep 17 00:00:00 2001
From: Zac Clifton <43915749+Cliftonz@users.noreply.github.com>
Date: Thu, 6 Jun 2024 11:36:28 -0400
Subject: [PATCH 8/8] Reformatted code and updated Homebrew upgrade command

The code in the dev-environment-setup.sh script has been reformatted for more readability and consistency. Additionally, the command for upgrading Homebrew has been simplified. The previous version was tapping into Homebrew cask unnecessarily before updating, this step has now been removed.
---
 scripts/dev-environment-setup.sh | 47 ++++++++++++++++----------------
 1 file changed, 23 insertions(+), 24 deletions(-)

diff --git a/scripts/dev-environment-setup.sh b/scripts/dev-environment-setup.sh
index 3574c4e20bd..9664ff763ea 100755
--- a/scripts/dev-environment-setup.sh
+++ b/scripts/dev-environment-setup.sh
@@ -105,36 +105,36 @@ install_apple_chip_dependencies () {
 }
 
 install_xcode () {
-    echo ""
-    echo "❓ Do you want to install Xcode? ($POSITIVE_RESPONSE / $NEGATIVE_RESPONSE)"
+  echo ""
+  echo "❓ Do you want to install Xcode? ($POSITIVE_RESPONSE / $NEGATIVE_RESPONSE)"
+  read -p " > " RESPONSE
+  echo ""
+
+  if [[ "$RESPONSE" == "$POSITIVE_RESPONSE" ]]; then
+	  installing_dependency "Xcode"
+	  xcode-select --install &
+	  PID=$!
+	  wait $PID
+	  sudo xcode-select --switch /Library/Developer/CommandLineTools
+	  sudo xcodebuild -license accept
+	  xcodebuild -runFirstLaunch
+	  success_message "Xcode"
+  fi
+
+  if [[ "$RESPONSE" == "$NEGATIVE_RESPONSE" ]]; then
+	  echo ""
+	  echo "❓ Do you want to update Xcode? ($POSITIVE_RESPONSE / $NEGATIVE_RESPONSE)"
     read -p " > " RESPONSE
-    echo ""
+	  echo ""
 
     if [[ "$RESPONSE" == "$POSITIVE_RESPONSE" ]]; then
-	installing_dependency "Xcode"
-	xcode-select --install &
-	PID=$!
-	wait $PID
-	sudo xcode-select --switch /Library/Developer/CommandLineTools
-	sudo xcodebuild -license accept
-	xcodebuild -runFirstLaunch
-	success_message "Xcode"
-    fi
-
-    if [[ "$RESPONSE" == "$NEGATIVE_RESPONSE" ]]; then
-	echo ""
-	echo "❓ Do you want to update Xcode? ($POSITIVE_RESPONSE / $NEGATIVE_RESPONSE)"
-        read -p " > " RESPONSE
-	echo ""
-
-        if [[ "$RESPONSE" == "$POSITIVE_RESPONSE" ]]; then
 	    updating_dependency "Xcode"
-            softwareupdate --install --verbose Xcode &
+      softwareupdate --install --verbose Xcode &
 	    PID=$!
 	    wait $PID
 	    success_message "Xcode"
-        fi
     fi
+  fi
 }
 
 set_macosx_generics () {
@@ -214,8 +214,7 @@ install_homebrew_recipes () {
 
     if [[ -z "$SKIP" ]]; then
         # Update Homebrew recipes
-        echo "Tap, update and upgrade Homebrew"
-        brew tap homebrew/cask
+        echo "Update and Upgrade Homebrew"
         brew update
         brew upgrade
     else