-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
128 lines (114 loc) Β· 3.56 KB
/
Copy pathsetup.sh
File metadata and controls
128 lines (114 loc) Β· 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
set -e # Exit on error
echo "π Setting up the environment for Scaling Node.js with Kubernetes..."
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# 1οΈβ£ Install Docker
if command_exists docker; then
echo "β
Docker is already installed."
else
echo "π¦ Installing Docker..."
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install --cask docker
open /Applications/Docker.app
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt update
sudo apt install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
fi
echo "β
Docker installed successfully!"
fi
# 2οΈβ£ Install Kubernetes CLI (kubectl)
if command_exists kubectl; then
echo "β
kubectl is already installed."
else
echo "π¦ Installing kubectl..."
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install kubectl
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt update
sudo apt install -y kubectl
fi
echo "β
kubectl installed successfully!"
fi
# 3οΈβ£ Install Minikube
if command_exists minikube; then
echo "β
Minikube is already installed."
else
echo "π¦ Installing Minikube..."
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install minikube
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
fi
echo "β
Minikube installed successfully!"
fi
# 4οΈβ£ Install Node.js & NPM
if command_exists node; then
echo "β
Node.js is already installed."
else
echo "π¦ Installing Node.js..."
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install node
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt update
sudo apt install -y nodejs npm
fi
echo "β
Node.js installed successfully!"
fi
# 5οΈβ£ Install PostgreSQL
if command_exists psql; then
echo "β
PostgreSQL is already installed."
else
echo "π¦ Installing PostgreSQL..."
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install postgresql
brew services start postgresql
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt update
sudo apt install -y postgresql postgresql-contrib
sudo systemctl start postgresql
fi
echo "β
PostgreSQL installed successfully!"
fi
# 6οΈβ£ Install Redis
if command_exists redis-cli; then
echo "β
Redis is already installed."
else
echo "π¦ Installing Redis..."
if [[ "$OSTYPE" == "darwin"* ]]; then
brew install redis
brew services start redis
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt update
sudo apt install -y redis-server
sudo systemctl start redis
fi
echo "β
Redis installed successfully!"
fi
# 7οΈβ£ Install Project Dependencies
echo "π¦ Installing project dependencies..."
npm install
# 8οΈβ£ Setup Environment Variables
echo "π¦ Setting up environment variables..."
cat > .env <<EOL
DB_HOST=127.0.0.1
DB_USER=postgres
DB_PASS=password
DB_NAME=node_scaling
DB_PORT=5432
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
EOL
echo "β
.env file created."
# 9οΈβ£ Run Database Migrations (if necessary)
echo "π¦ Creating PostgreSQL database..."
psql -U postgres -c "CREATE DATABASE node_scaling;" || echo "Database already exists."
# 1οΈβ£0οΈβ£ Start the API
echo "π Starting the Fastify API..."
npm start &
echo "β
Setup complete! Your API is running. You can now access it at http://localhost:3000"