diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 2a74da8..80171cc 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -13,6 +13,13 @@ echo "export CODESPACE_BACKEND_URL=\"${CODESPACE_BACKEND_URL}\"" >> ~/.bashrc echo "export ENGINE_WILCO_AI_URL=\"${ENGINE_WILCO_AI_CONFIG}\"" >> ~/.bashrc echo "export CODESPACE_WDS_SOCKET_PORT=443" >> ~/.bashrc +# Install the Atlas CLI +curl -fsSL https://pgp.mongodb.com/server-7.0.asc | \ +sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mongodb-server-7.0.gpg && +echo "deb [ arch=amd64,arm64 signed=/etc/apt/trusted.gpg.d/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list && +sudo apt-get update && +sudo apt-get install -y mongodb-atlas-cli + # Export welcome prompt in bash: echo "printf \"\n\n☁️☁️☁️️ Anythink: Develop in the Cloud ☁️☁️☁️\n\"" >> ~/.bashrc echo "printf \"\n\x1b[31m \x1b[1m👉 Type: \\\`docker compose up\\\` to run the project. 👈\n\n\"" >> ~/.bashrc diff --git a/wilco_mongo_setup.sh b/wilco_mongo_setup.sh new file mode 100755 index 0000000..ffccd96 --- /dev/null +++ b/wilco_mongo_setup.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +echo "Wilco: Hi, Welcome to Wilco MongoDB Atlas Cluster Setup!" +echo "We'll guide you through the process of setting up a MongoDB Atlas cluster." + +# Step 1: Register or authenticate the user +echo "Wilco: Please register or authenticate using MongoDB Atlas." +echo "Wilco: If you already have an account, please click login and paste your CLI Key." +atlas auth register --noBrowser +if [ $? -ne 0 ]; then + echo "Wilco: Something went wrong with atlas command 'auth register', please contact Wilco support." + exit 1 +fi + +# Step 2: Create a new organization and capture the Organization ID +echo "Wilco: Creating a new organization named 'WilcoOrg'." +org_output=$(atlas organizations create WilcoOrg) +if [ $? -ne 0 ]; then + echo "Wilco: Something went wrong with atlas command 'organizations create'. Please contact Wilco support." + exit 1 +fi + +# Extract the Organization ID from the output using awk +org_id=$(echo "$org_output" | awk -F"'" '/Organization / {print $2}') + +if [ -z "$org_id" ]; then + echo "Wilco: Failed to create organization or capture the Organization ID. Exiting. Please contact Wilco support." + exit 1 +fi + +echo "Wilco: A new Organization created with ID $org_id" + +# Step 3: Create a new project and capture the Project ID +echo "Wilco: Creating a new project named 'WilcoMongo'." +project_output=$(atlas projects create WilcoMongo --orgId $org_id) +if [ $? -ne 0 ]; then + echo "Wilco: Something went wrong with atlas command 'projects create'. Please contact Wilco support." + exit 1 +fi + +# Extract the Project ID from the output using awk +project_id=$(echo "$project_output" | awk -F"'" '/Project / {print $2}') + +if [ -z "$project_id" ]; then + echo "Wilco: Failed to create project or capture the Project ID. Exiting. Please contact Wilco support." + exit 1 +fi + +echo "Wilco: Project created with ID $project_id" + +# Step 4: Add access list entry +echo "Wilco: Adding access list entry for IP address 0.0.0.0 so Wilco can connect to it!" +atlas accessList create 0.0.0.0 --type ipAddress --projectId $project_id +if [ $? -ne 0 ]; then + echo "Wilco: Something went wrong with atlas command 'accessList create'. Please contact Wilco support." + exit 1 +fi + +# Step 5: Create a cluster in the newly created project +echo "Wilco: Creating a MongoDB cluster in the project 'WilcoMongo' for your Wilco application." +atlas cluster create WilcoMongo --projectId $project_id --provider AWS --region US_EAST_1 --tier M0 --watch +if [ $? -ne 0 ]; then + echo "Wilco: Something went wrong with atlas command 'cluster create'. Please contact Wilco support." + exit 1 +fi + +# Step 6: Create a database user +echo "Wilco: Creating a database user 'WilcoDbUser' for your Wilco application." +atlas dbusers create atlasAdmin --username WilcoDbUser --password Wilco12345678 --projectId $project_id +if [ $? -ne 0 ]; then + echo "Wilco: Something went wrong with atlas command 'dbusers create'. Please contact Wilco support." + exit 1 +fi + +# Initialize variables to capture specific outputs +matched_string="" +full_connection_string="" +cleaned_connection_string="" + +# Output the captured values with labels inside an ASCII square +echo "┌─────────────────── Wilco MongoDB Details ────────────────────────────────────────────────────┐" +echo "| Your Wilco MongoDB Atlas Cluster is being created. |" +echo "| This may take a few minutes. Once done you'll see your details below |" +echo "| Wilco DB User: WilcoDbUser |" +echo "| Wilco DB Password: Wilco12345678 |" +echo "| Your cluster name: WilcoMongo" +sleep 5 +full_connection_string=$(atlas clusters connectionStrings describe WilcoMongo --projectId $project_id | grep -A 1 "mongodb+srv" | tail -n 1) +if [ $? -ne 0 ]; then + echo "Wilco: Something went wrong with atlas command 'clusters connectionStrings describe'. Please contact Wilco support." + exit 1 +fi + +cleaned_connection_string=${full_connection_string#mongodb+srv://} + +connection_string="mongodb+srv://WilcoDbUser:Wilco12345678@$cleaned_connection_string" + +echo "| Your connection string: $connection_string |" +echo "└─────────────────── Wilco MongoDB Details ────────────────────────────────────────────────────┘"