-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup-dev-workspace
executable file
·117 lines (101 loc) · 3.1 KB
/
setup-dev-workspace
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
#!/usr/bin/env bash
ul="=================================="
should_start_api=false
while getopts ":b:h" opt; do
case $opt in
b)
should_start_api=true
;;
h)
echo "Usage: setup-dev-workspace.sh [-b] true"
echo " -b: Start spring-boot backend server"
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
should_proceed=true
check_program() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "❌ '$1'"
should_proceed=false
else
echo "✅ '$1'"
fi
}
echo -e "\e[36mChecking program status\e[m"
echo $ul
check_program "git"
check_program "yarn"
check_program "java"
check_program "docker"
if ! $should_proceed; then
echo -e "\e[31m⁉️ Required programs are missing or not installed\e[m"
echo -e "\e[31m🔴 Please install the missing programs\e[m"
exit 1
fi
echo -e "\n"
echo -e "\e[36mSetting up Dev workspace\e[m"
echo $ul
if $should_start_api; then
echo -e "\n\e[35m>> Option selected : Run with backend <<"
echo -e "Spring boot app will run in the background after DB initialization\e[m"
fi
echo -e "\n"
echo -e "\e[33m:: Setting up git hooks ::\n\e[m"
if [ -f ~/.huskyrc ]; then
cat ~/.huskyrc | grep "exec < /dev/tty" >/dev/null
if [ $? -eq 0 ]; then
echo -e "✅ Husky is already configured\n"
else
echo -e "🐕 Configuring husky\n"
echo "exec < /dev/tty" >>~/.huskyrc
fi
else
echo -e "🐕 Configuring husky\n"
echo "exec < /dev/tty" >>~/.huskyrc
fi
yarn --silent
yarn --silent prepare
cd .husky && chmod +x * && cd ..
echo -e "\e[33m:: Installing UI dependencies ::\n\e[m"
cd mimock-ui && yarn --silent && cd ..
echo -e "\e[33m:: Installing backend dependencies ::\n\e[m"
cd mimock-backend && ./mvnw -q -ntp clean install -DskipTests=true && cd ..
echo -e "\e[33m:: Starting dev database ::\n\e[m"
mimock_db=$(docker ps -a --filter name=mimock-db --format "{{.Names}}")
if [ -z "$mimock_db" ]; then
echo "🔵 Starting database"
docker build -t mimock-pg-database . -f Dockerfile.pg && docker run --name mimock-db -p 5427:5432 --network mimock-network -d mimock-pg-database
else
db_status=$(docker container inspect -f '{{.State.Running}}' $mimock_db)
if [ "$db_status" == "false" ]; then
echo -e "\e[36m🐋 Database is not running\e[m"
echo -e "\e[33m🐳 Re-starting database\e[m"
docker start $mimock_db >/dev/null
else
echo -e "\e[32m🐳 Mimock database is already running\e[m"
fi
fi
if $should_start_api; then
echo -e "\n"
echo -e "\e[33m:: Starting server ::\n\e[m"
cd mimock-backend && nohup ./mvnw spring-boot:run -DskipTests=true -Dapp.profiles=dev >/dev/null 2>&1 &
pid=$(echo $!)
cd ..
echo -e "🔵 Server is running\n"
echo -e "\e[36m> To stop the server, run 'kill -9 $pid'\n\e[m"
else
echo -e "\n"
echo -e "\e[31m> Something to keep in mind <\n\e[m"
echo -e "\e[33m⚠️ Spring boot app will not run in the background\e[m"
echo "🛸 You can run it manually with 'cd ./micmock-backend && ./mvnw spring-boot:run -DskipTests=true -Dapp.profiles=dev'"
echo "🛸 You can also run this script with '-b' option to start the app in the background"
fi
echo -e "\n"
echo $ul
echo -e "\e[32m🚀 Dev workspace setup completed!\e[m"
echo -e "\n"