-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_fly_io.sh
109 lines (101 loc) · 2.72 KB
/
run_fly_io.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
#!/bin/sh
# run_fly_io.sh
# 2023-02-01 | CR
#
APP_DIR='chalicelib'
PYTHON3_EXEC='/usr/local/bin/python3.9'
if [ -f "./.env" ]; then
ENV_FILESPEC="./.env"
else
ENV_FILESPEC="../.env"
fi
set -o allexport; source ${ENV_FILESPEC}; set +o allexport ;
if [ "$PORT" = "" ]; then
PORT="5001"
fi
if [ "$1" = "deactivate" ]; then
cd ${APP_DIR} ;
deactivate ;
fi
if [[ "$1" != "deactivate" && "$1" != "pipfile" && "$1" != "clean" && "$1" != "set_webhook" ]]; then
${PYTHON3_EXEC} -m venv ${APP_DIR} ;
. ${APP_DIR}/bin/activate ;
cd ${APP_DIR} ;
if [ -f "requirements.txt" ]; then
pip3 install -r requirements.txt
else
pip install requests
pip install fastapi
pip install a2wsgi
pip install openai
pip install pymongo
pip install werkzeug
pip install "python-jose[cryptography]"
pip install "passlib[bcrypt]"
pip install wheel
pip install python-multipart
pip install python-dotenv
pip install gunicorn
pip freeze > requirements.txt
fi
fi
if [ "$1" = "pipfile" ]; then
deactivate ;
pipenv lock
fi
if [ "$1" = "clean" ]; then
echo "Cleaning..."
deactivate ;
rm -rf __pycache__ ;
rm -rf bin ;
rm -rf include ;
rm -rf lib ;
rm -rf pyvenv.cfg ;
rm -rf ../.vercel/cache ;
rm -rf .vercel/cache ;
rm -rf ../node_modules ;
rm requirements.txt
ls -lah
fi
if [[ "$1" = "test" ]]; then
# echo "Error: no test specified" && exit 1
echo "Run test..."
python -m pytest
echo "Done..."
fi
if [ "$1" = "create_app" ]; then
flyctl auth login
flyctl apps create ${FLYIO_APP_NAME}
fi
if [[ "$1" = "create_app" || "$1" = "set_vars" ]]; then
flyctl secrets set TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
flyctl secrets set TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID}
flyctl secrets set OPENAI_API_KEY=${OPENAI_API_KEY}
flyctl secrets set APP_NAME=${APP_NAME}
flyctl secrets set SERVER_NAME=${SERVER_NAME}
flyctl secrets set DB_URI=${DB_URI}
flyctl secrets set DB_NAME=${DB_NAME}
flyctl secrets set SECRET_KEY=${SECRET_KEY}
flyctl secrets set ALGORITHM=${ALGORITHM}
flyctl secrets set ACCESS_TOKEN_EXPIRE_MINUTES=${ACCESS_TOKEN_EXPIRE_MINUTES}
fi
if [ "$1" = "restart" ]; then
flyctl apps restart ${FLYIO_APP_NAME} ;
fi
if [ "$1" = "deploy" ]; then
flyctl deploy ;
fi
if [ "$1" = "deploy_prod" ]; then
flyctl deploy ;
fi
if [ "$1" = "run_docker" ]; then
docker-compose up -d
fi
if [ "$1" = "run_ngrok" ]; then
../node_modules/ngrok/bin/ngrok http $PORT
fi
if [[ "$1" = "run" || "$1" = "" ]]; then
cd ..
# python -m ${APP_DIR}.index
gunicorn -b 0.0.0.0:${PORT} --log-level debug -w 4 'chalicelib.index:app'
fi