Skip to content

Commit

Permalink
build(root): Update Jarvis to run docker infra instead of through brew (
Browse files Browse the repository at this point in the history
#5659)

* 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.

* 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.

* 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.

* 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.

* 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.

* 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.

* 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.

* 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.
  • Loading branch information
Cliftonz authored Jun 6, 2024
1 parent cac9cba commit 662c761
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 83 deletions.
4 changes: 3 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,9 @@
"whatsappbusiness",
"xkeysib",
"zulip",
"zwnj"
"zwnj",
"prepush",
"xcodebuild"
],
"flagWords": [],
"patterns": [
Expand Down
165 changes: 83 additions & 82 deletions scripts/dev-environment-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -99,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 () {
Expand All @@ -147,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
Expand Down Expand Up @@ -208,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
Expand Down Expand Up @@ -383,61 +388,55 @@ install_aws_cli () {
fi
}

install_databases () {
SKIP="$(check_homebrew)"

if [[ -z "$SKIP" ]]; then
installing_dependency "Databases"

brew tap mongodb/brew

DATABASES=(
mongodb-community@5.0
redis
)
brew install "${DATABASES[@]}"

echo "Run the services in the background"

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

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
}

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
start_database() {
# 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"
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
}

check_git () {
Expand All @@ -448,6 +447,9 @@ check_git () {
echo "⛔️ Git is a hard dependency to clone the monorepo"
exit 1
fi

already_installed_message "git"

}

clone_monorepo () {
Expand Down Expand Up @@ -489,9 +491,8 @@ install_novu_tools () {
install_node
install_pnpm
install_docker
install_databases
install_aws_cli
create_local_dev_domain
start_database
}

install_os_dependencies () {
Expand Down

0 comments on commit 662c761

Please sign in to comment.