-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflask-deploy.sh
More file actions
80 lines (63 loc) · 1.98 KB
/
flask-deploy.sh
File metadata and controls
80 lines (63 loc) · 1.98 KB
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
APPNAME="blog"
sudo apt-get install -y ufw
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow 443/tcp
sudo ufw --force enable
sudo ufw status
sudo apt-get -y update
sudo apt-get -y install python3 python3-venv python3-dev
sudo apt-get -y install supervisor nginx git
# Create a basic flask application
git clone https://github.com/samratrocks/flask-template.git
mv flask-template blog
cd blog
python3 -m venv venv
source venv/bin/activate
pip install flask
pip install gunicorn
echo "export FLASK_APP=$APPNAME.py" >> ~/.profile
# gunicorn -b localhost:8000 -w 4 $APPNAME:app
# Supervisor configuration.
cat <<EOL | sudo tee /etc/supervisor/conf.d/$APPNAME.conf
[program:$APPNAME]
command=/home/$USER/$APPNAME/venv/bin/gunicorn -b localhost:8000 -w 4 $APPNAME:app
directory=/home/$USER/$APPNAME
user=$USER
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
EOL
sudo supervisorctl reload
sudo rm /etc/nginx/sites-enabled/default
# Nginx configuration.
cat << EOL | sudo tee /etc/nginx/sites-enabled/$APPNAME
server {
# listen on port 80 (http)
listen 80;
server_name _;
location / {
# forward application requests to the gunicorn server
proxy_pass http://localhost:8000;
proxy_redirect off;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
location /static {
# handle static files directly, without forwarding to the application
alias /home/$USER/$APPNAME/app/static;
expires 30d;
}
}
EOL
sudo service nginx start
sudo service nginx reload
#``` Deploying application updates
# git pull # download the new version
# sudo supervisorctl stop $APPNAME # stop the current server
# flask db upgrade # upgrade the database
# flask translate compile # upgrade the translations
# sudo supervisorctl start $APPNAME # start a new server
# ```