-
Notifications
You must be signed in to change notification settings - Fork 16
/
cjl
executable file
·111 lines (95 loc) · 3.88 KB
/
cjl
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
#!/usr/bin/env bash
# Ensure dependencies are installed
if ! [ -x "$(command -v docker)" ] || ! [ -x "$(command -v docker-compose)" ]; then
(>&2 echo 'You must install docker and docker-compose to use this script.')
exit 1
fi
# Ensure required environment variables are passed
if [ -z "$CJL_USER" ] || [ -z "$CJL_PASS" ]; then
(>&2 echo 'You must provide the $CJL_USER and $CJL_PASS environment variables to use this script.')
exit 1
fi
# Destroy all containers/images
if [ "$1" == "clean" ]; then
function clean {
echo " >>> Killing all docker containers <<<" && echo "" && docker ps -qa | xargs docker kill && echo ""
echo " >>> Removing all stopped containers <<<" && echo "" && docker ps -qa | xargs docker rm -v && echo ""
echo " >>> Removing all images <<<" && echo "" && docker images -qa | xargs docker rmi && echo ""
}
if [ "$2" != "-y" ]; then
echo "WARNING: This command is destructive. It removes all containers and images installed on your local machine."
read -r -p "Are you SURE you want to continue? [y/N]" clean_confirmation
if [[ $clean_confirmation =~ ^(y|Y)$ ]]; then
clean
clean
else
echo "Clean aborted."
fi
else
clean
clean
fi
exit
fi
# Destroy the database
if [ "$1" == "reset-db" ]; then
function reset_db {
echo " >>> Removing all database data <<<" && \
sudo rm -rf ~/.procezeus/* && \
echo " >>> Database removed <<<"
}
if [ "$2" != "-y" ]; then
echo "WARNING: This command is destructive. It removes all database data on your local machine."
read -r -p "Are you SURE you want to continue? [y/N]" clean_confirmation
if [[ $clean_confirmation =~ ^(y|Y)$ ]]; then
reset_db
else
echo "Database reset aborted."
fi
else
reset_db
fi
exit
fi
# Runs all tests and lints across all services
if [ "$1" == "test" ]; then
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml down &&
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml build &&
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml up -d
if [ "$2" == "backend_service" ]; then
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml run backend_service
elif [ "$2" == "ml_service" ]; then
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml run ml_service
elif [ "$2" == "nlp_service" ]; then
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml run nlp_service
elif [ "$2" == "web_client" ]; then
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml run web_client
else
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml run ml_service
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml run nlp_service
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml run backend_service
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml run web_client
fi
docker-compose -f docker-compose.base.yml -f docker-compose.test.yml down
exit 0
fi
# Tries to fix all Javascript and Python linting errors for you
if [ "$1" == "lint-fix" ]; then
if ! [ -x "$(command -v autopep8)" ]; then
echo "You must install autopep8 to auto-fix Python linting errors. python3 -m pip install autopep8."
fi
if ! [ -x "$(command -v npm)" ]; then
echo "You must install node & npm to install front-end dependencies and auto-fix Javascript linting errors."
fi
echo " >> Automatically fixing linting errors <<" && echo ""
cd ./src/web_client && npm install && npm run lintfix && cd ../.. && autopep8 -aair --pep8-passes 2000 . && \
echo "Done!"
exit
fi
# Choose an environment, default is dev
if [ -z "$COMPOSE_FILE" ]; then
COMPOSE_FILE='dev'
fi
# Passes script arguments to docker-compose
COMPOSE="docker-compose -f docker-compose.base.yml -f docker-compose.$COMPOSE_FILE.yml $@"
bash -c "$COMPOSE"