1
+ #! /usr/bin/env bash
2
+
3
+ # Consider running these two commands separately
4
+ # Do a reboot before continuing.
5
+ apt update
6
+ apt upgrade -y
7
+
8
+ apt install zsh
9
+ sh -c " $( curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh) "
10
+
11
+ # Install some OS dependencies:
12
+ sudo apt-get install -y -q build-essential git unzip zip nload tree
13
+ sudo apt-get install -y -q python3-pip python3-dev python3-venv
14
+ sudo apt-get install -y -q nginx
15
+ # for gzip support in uwsgi
16
+ sudo apt-get install --no-install-recommends -y -q libpcre3-dev libz-dev
17
+
18
+ # Stop the hackers
19
+ sudo apt install fail2ban -y
20
+
21
+ ufw allow 22
22
+ ufw allow 80
23
+ ufw allow 443
24
+ ufw enable
25
+
26
+ # Basic git setup
27
+ git config --global credential.helper cache
28
+ git config --global credential.helper ' cache --timeout=720000'
29
+
30
+ # Be sure to put your info here:
31
+ git config --global user.email
" [email protected] "
32
+ git config --global user.name " Your name"
33
+
34
+ # Web app file structure
35
+ mkdir /apps
36
+ chmod 777 /apps
37
+ mkdir /apps/logs
38
+ mkdir /apps/logs/guitary
39
+ mkdir /apps/logs/guitary/app_log
40
+ cd /apps
41
+
42
+ # Create a virtual env for the app.
43
+ cd /apps
44
+ python3 -m venv venv
45
+ source /apps/venv/bin/activate
46
+ pip install --upgrade pip setuptools
47
+ pip install --upgrade httpie glances
48
+ pip install --upgrade uwsgi
49
+
50
+
51
+ # clone the repo:
52
+ cd /apps
53
+ git clone https://github.com/talkpython/python-for-dotnet-developers-course app_repo
54
+
55
+ # Setup the web app:
56
+ cd /apps/app_repo/apps/py/ch07_web/
57
+ pip install -r requirements.txt
58
+
59
+ # Copy and enable the daemon
60
+ cp /apps/app_repo/apps/py/ch12_deployment/config/guitary.service /etc/systemd/system/guitary.service
61
+
62
+
63
+ systemctl start guitary
64
+ systemctl status guitary
65
+ systemctl enable guitary
66
+
67
+ # systemctl daemon-reload
68
+ # If you make changes to the service file
69
+
70
+ # Setup the public facing server (NGINX)
71
+ apt install nginx
72
+
73
+ # CAREFUL HERE. If you are using default, maybe skip this
74
+ rm /etc/nginx/sites-enabled/default
75
+
76
+ cp /apps/app_repo/apps/py/ch12_deployment/config/guitary.nginx /etc/nginx/sites-enabled/guitary.nginx
77
+ update-rc.d nginx enable
78
+ service nginx restart
79
+
80
+
81
+ # Optionally add SSL support via Let's Encrypt:
82
+ # https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04
83
+
84
+ add-apt-repository ppa:certbot/certbot
85
+ apt install python-certbot-nginx
0 commit comments