-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
144 lines (125 loc) · 2.86 KB
/
run.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
############ HELP #############
Help()
{
echo "OPTIONS"
echo
echo "Syntax: sh run.sh -[h|t|d|v]"
echo "options:"
echo "h Help"
echo "t Run tests"
echo "d Check dependencies"
echo "v Create test virtualenv"
echo "f Run server with full prep"
echo
echo "Example: sh run.sh -f"
}
############ DEPENDENCIES #############
DEPENDENCIES()
{
if [[ "$VIRTUAL_ENV" != "" ]]
then
cd scripts
sh dependencies.sh
cd ..
else
echo "No VENV found. Please create a virtualenv first."
exit
fi
}
############ RUN TESTS #############
TESTS()
{
pytest
}
############ CHECK VIRTUAL ENV #############
CHECK_VIRTUAL_ENV()
{
if [[ "$VIRTUAL_ENV" != "" ]]
then
INVENV=1
echo "Found virtual environment"
else
INVENV=0
echo "No virtual environment activated"
echo "Activating virtual environment..."
source env/bin/activate
sleep 3
if [[ "$VIRTUAL_ENV" != "" ]]
then
INVENV=1
echo "Activated Venv"
else
INVENV=0
echo "No virtual environment found"
echo "installing virtualenv..."
pip install virtualenv
echo "starting venv: env"
virtualenv env
echo "Activating env"
source env/bin/activate
if [[ "$VIRTUAL_ENV" != "" ]]
then
INVENV=1
echo "Activated VENV"
else
INVENV=0
echo "Error: Failed to activate the VENV"
exit
fi
fi
fi
}
############ RUN SERVER #############
RUN_SERVER()
{
if [ -n "$PORT" ]
then
PORT_=$PORT
else
PORT_=80
fi
echo "Starting server on port $PORT_"
# add --reload flag for auto reload during development
uvicorn src.main:app --host 0.0.0.0 --port $PORT_
}
############ RUN #############
# Process Options
while getopts ":htdvf:" option; do
case $option in
h)
echo "Option: Help"
Help
exit
;;
d)
echo "Option: Dependencies"
CHECK_VIRTUAL_ENV
DEPENDENCIES
;;
t)
echo "Option: Tests"
CHECK_VIRTUAL_ENV
TESTS
;;
v)
echo "Option: Virtual Env"
CHECK_VIRTUAL_ENV
;;
f)
echo "Option: Complete Execution"
CHECK_VIRTUAL_ENV
DEPENDENCIES
TESTS
;;
\?) # Invalid option
echo "Error: Invalid option"
exit
;;
esac
done
echo ""
echo "Running server with run script..."
echo "Press Ctrl + C to exit"
echo ""
RUN_SERVER