-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·76 lines (62 loc) · 1.95 KB
/
deploy.sh
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
#!/bin/bash
source ~/.bashrc
HEADER='\033[95m'
OKBLUE='\033[94m'
OKCYAN='\033[96m'
OKGREEN='\033[92m'
WARNING='\033[93m'
FAIL='\033[91m'
ENDC='\033[0m'
BOLD='\033[1m'
UNDERLINE='\033[4m'
SLATE='\033[38;2;112;128;144m'
GRAY='\033[38;2;128;128;128m'
DARK_GRAY='\033[38;2;68;68;68m'
PINK='\033[38;2;255;20;147m'
echo -e "${HEADER}Deploying the stuff...${ENDC}"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm use 18
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
echo -e "${OKCYAN}cd into $SCRIPT_DIR ...${ENDC}"
cd $SCRIPT_DIR
echo -e "${OKGREEN}Sourcing .env ...${ENDC}"
source $SCRIPT_DIR/.env
# Checkout to main branch
git checkout main
# Pull the latest code
echo -e "${OKBLUE}Pulling the latest code...${ENDC}"
git fetch && OUTPUT=$(git pull origin main)
# Check if pnpm is installed
echo -e "${GRAY}Checking if pnpm is installed and install if not...${ENDC}"
if ! command -v pnpm &> /dev/null; then
echo -e "${WARNING}pnpm not found! Installing...${ENDC}"
sudo npm install -g pnpm
if [ $? -ne 0 ]; then
echo -e "${FAIL}Failed to install pnpm. Exiting.${ENDC}"
exit 1
fi
echo -e "${OKGREEN}pnpm installed successfully.${ENDC}"
else
echo -e "${OKGREEN}pnpm is already installed.${ENDC}"
fi
# Install dependencies
echo -e "${PINK}Installing dependencies...${ENDC}"
pnpm install
# Check if there were changes
if [[ $OUTPUT != *"Already up to date."* ]]; then
echo -e "${OKBLUE}Restarting server...${ENDC}"
cd $HOME && pm2 restart ecosystem.config.js --only metagame-api
# Sleep for a few seconds to give the server time to start
sleep 5
# Check server status
if pm2 list | grep "metagame-api" | grep -q "online"; then
echo -e "${OKGREEN}Server restarted successfully.${ENDC}"
else
echo -e "${FAIL}Server failed to start.${ENDC}"
fi
else
echo -e "${OKGREEN}No changes detected. Server restart not required.${ENDC}"
fi
# Exit
echo -e "${OKGREEN}Done.${ENDC}"