forked from flojoy-ai/studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflojoy
executable file
·328 lines (289 loc) · 7.92 KB
/
flojoy
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/bin/bash
# Run all services required by Flojoy Studio
success_color='\033[38;5;71m'
warning_color='\033[38;5;208m'
error_color='\033[0;31m'
info_color='\033[0;34m'
general_color='\033[38;5;212m'
default_color='\033[0m'
info_mark=👉
check_mark=✔
alert_mark=⚠️
error_mark=❌
is_command_successful=0
success_msg()
{
message=$1
echo -e "$success_color$check_mark $message $default_color"
echo ''
}
info_msg()
{
message=$1
echo -e "$info_color$info_mark $message $default_color"
echo ''
}
warning_msg()
{
message=$1
echo -e "$warning_color$alert_mark $message $default_color"
echo ''
}
error_msg()
{
message=$1
echo -e "$error_color$error_mark $message $default_color"
echo ''
echo ''
}
echo ''
echo ''
echo ' ============================================================'
echo ' || Welcome to Flojoy! ||'
echo ' || ||'
echo ' || For Installation, Follow the Link Below ||'
echo ' || https://docs.flojoy.ai/getting-started/install/ ||'
echo ' || ||'
echo ' ============================================================'
echo ''
venv=""
initNodePackages=true
initPythonPackages=true
is_ci=false
test_ci=false
initSubmodule=true
enableSentry=true
enableTelemetry=true
isDebugMode=false
isRemoteMode=false
# Gives Feedback if the command run is successful or failed, if failed it exits the execution.
feedback()
{
is_successful=$1
message=$2
help_message=$3
if [ "$is_successful" -eq 0 ]; then
success_msg "$message"
else
error_msg "$help_message"
exit 1
fi
}
# Help function
helpFunction()
{
echo ""
echo "Usage: $0 -n -p -s -S -t -T -d -v venv-path -r"
echo " -v: path to a Python virtual environment"
echo " -n: To NOT install npm packages"
echo " -p: To NOT install python packages"
echo " -s: To NOT update submodules"
echo " -S: To NOT enable Sentry"
echo " -t: To enable local CI tests"
echo " -T: To disable Telemetry"
echo " -d: To enable debug mode"
echo " -r: To start studio in remote mode without electron"
echo 1 # Exit script after printing help
}
# Parse command-line arguments
while [ $# -gt 0 ]
do
key="$1"
case $key in
-n)
initNodePackages=false
shift
;;
-p)
initPythonPackages=false
shift
;;
-v)
venv="$2"
shift
shift
;;
-c)
is_ci=true
shift
;;
-T)
enableTelemetry=false
shift
;;
-S)
enableSentry=false
shift
;;
-t)
test_ci=true #run with CI=true, allows to properly run tests locally
shift
;;
-s)
initSubmodule=false # don't update submodules, prevents overwriting local changes
shift
;;
-d)
isDebugMode=true
shift
;;
-r)
isRemoteMode=true
shift
;;
*) # unknown option
echo "Unknown option: $1"
helpFunction
exit 1
;;
esac
done
git pull
# checking if flojoy.yaml file exists
CWD="$PWD"
createFlojoyDirectoryWithYmlFile()
{
FOLDER=$HOME/.flojoy
FILE=$HOME/.flojoy/flojoy.yaml
if test -d "$FOLDER"; then
if test -f "$FILE"; then
info_msg "$FILE exists."
echo "PATH: $CWD" > $FILE
feedback $? "Updated file path in flojoy.yaml file." "Couldn't update file path in flojoy.yaml file, check the permission or sign in as root user"
else
info_msg "file flojoy.yaml in directory $FOLDER does not exists. "
touch $FILE && echo "PATH: $CWD" > $FILE
feedback $? "Successfully created flojoy.yaml file in $FOLDER directory." "Couldn't create flojoy.yaml file in $FOLDER directory, check the permission or sign in as root user"
fi
else
info_msg "directory ~/.flojoy/flojoy.yaml does not exists. "
mkdir "$FOLDER" && touch "$FILE" && echo "PATH: $CWD" > "$FILE"
feedback $? "Created new $FOLDER directory with flojoy.yaml file." 'Failed to create file in the home directory, check the permission or sign in as root user'
fi
CREDENTIALS_FILE=$FOLDER/credentials.txt
if ! test -f "$CREDENTIALS_FILE"; then
touch "$CREDENTIALS_FILE"
fi
}
createFlojoyDirectoryWithYmlFile
# update submodules
if [ "$initSubmodule" = true ]; then
git submodule update --init --recursive >/dev/null 2>&1
feedback $? 'Updated submodules successfully' 'Failed to update submodules, check if git is installed correctly and configured with your github account.'
fi
# checking virtual environment
venvCmd=""
if [ -n "$venv" ]
then
info_msg "Virtual env path is provided, will use: ${venv}"
venvCmd="source ${venv}/bin/activate"
if [ "$(echo -n $venv | tail -c 1)" = '/' ];then
venvCmd="source ${venv}bin/activate"
fi
else
info_msg "No virtual env provided"
fi
# Check if Python, Pip, or npm is missing.
if [ $is_ci = false ];then
source check-dependencies
# Call the function to check for dependencies
missing_dependencies=$(check_dependencies)
# If there are missing dependencies, print the list of them
if [ -n "$missing_dependencies" ]; then
error_msg "$missing_dependencies"
exit 1
fi
fi
# Install python packages
if [ $initPythonPackages = true ]
then
cd $CWD
info_msg "Flag -p is not provided, Python packages will be installed from requirements.txt file"
if [ -n "$venv" ];then
pip_cmd="pip install -r requirements.txt"
else
pip_cmd="python3 -m pip install -r requirements.txt"
fi
set -o pipefail
$venvCmd && $pip_cmd 2>&1 | while IFS= read -r line; do
if [[ $line == Requirement* ]]; then
echo "$line" | awk -F'in' '{print $1}'
elif [[ $line == WARNING* ]]; then
echo ''
else
echo "$line"
fi
done
feedback $? 'Python packages installed successfully!' 'Failed to install Python packages. Look at error details printed above.'
fi
# Install node packages
if [ $initNodePackages = true ]
then
info_msg "Argument -n is not provided, Node packages will be installed from package.json"
set -o pipefail
cd "$CWD" && npm install 2>&1
feedback $? 'Installed Node packages successfully.' 'Node package installation failed! Look at error details printed above'
fi
if [ $is_ci = true ];then
exit 0
fi
# Setup Sentry env var
if [ $enableSentry = true ]
then
info_msg "Sentry will be enabled!"
export FLOJOY_ENABLE_SENTRY=1
else
info_msg "Sentry will be disabled!"
export FLOJOY_ENABLE_SENTRY=0
fi
# Setup Telemetry
if [ $enableTelemetry = true ]
then
info_msg "Telemetry will be enabled!"
export FLOJOY_ENABLE_TELEMETRY=1
else
info_msg "Telemetry will be disabled!"
export FLOJOY_ENABLE_TELEMETRY=0
fi
# setup deploy environment
if [ $isRemoteMode = true ]
then
info_msg "Electron will be disabled!"
export DEPLOY_ENV=remote
else
export DEPLOY_ENV=local
fi
cd $CWD
# YOLOV3 check/download moved to node
# Leave commented until tested?
# Checking for YOLOV3 Weights
# CWD="$PWD"
# FILE=$PWD/PYTHON/utils/object_detection/yolov3.weights
# if test -f "$FILE"; then
# info_msg "$FILE exists."
# else
# touch "$PWD"/PYTHON/utils/object_detection/yolov3.weights
# wget -O "$PWD"/PYTHON/utils/object_detection/yolov3.weights https://pjreddie.com/media/files/yolov3.weights
# echo ''
# fi
sleep 1
# set deploy status to dev
export DEPLOY_STATUS=dev
# start project services
if [ $test_ci = true ]; then
start_project_cmd='npm run start-project:ci'
else
start_project_cmd='npm run start-project'
fi
if [ $isDebugMode = true ]; then
info_msg "Debug mode will be enabled!"
export FASTAPI_LOG=debug
else
export FASTAPI_LOG=error
fi
# start project services
if [ -n "$venvCmd" ]; then
$venvCmd && $start_project_cmd
else
$start_project_cmd
fi