Skip to content

Commit 8301d1f

Browse files
committed
Here are the linux server files we need.
1 parent 25dfbc6 commit 8301d1f

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
server {
2+
listen 80;
3+
server_name fake_pypi.com
4+
server_tokens off;
5+
charset utf-8;
6+
client_max_body_size 150M;
7+
8+
location /static {
9+
gzip on;
10+
gzip_buffers 8 256k;
11+
uwsgi_buffers 8 256k;
12+
13+
alias /apps/app_repo/src/ch15-deploy/final/pypi_deploy/pypi/static;
14+
expires 365d;
15+
}
16+
location / {
17+
try_files $uri @yourapplication;
18+
}
19+
location @yourapplication {
20+
include uwsgi_params;
21+
22+
gzip on;
23+
gzip_buffers 8 256k;
24+
uwsgi_buffers 8 256k;
25+
uwsgi_read_timeout 300;
26+
27+
proxy_pass http://127.0.0.1:9051;
28+
proxy_set_header Host $host;
29+
proxy_set_header X-Real-IP $remote_addr;
30+
proxy_set_header X-Forwarded-Protocol $scheme;
31+
}
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=uWSGI PyPI server instance
3+
After=syslog.target
4+
5+
[Service]
6+
ExecStart=/apps/venv/bin/uwsgi -H /apps/venv --ini-paste /apps/app_repo/src/ch15-deploy/final/pypi_deploy/pypi/production.ini
7+
RuntimeDirectory=/apps/app_repo/src/ch15-deploy/final/pypi_deploy/pypi/
8+
Restart=always
9+
KillSignal=SIGQUIT
10+
Type=notify
11+
StandardError=syslog
12+
NotifyAccess=all
13+
14+
[Install]
15+
WantedBy=multi-user.target
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
# Install some OS dependencies:
9+
sudo apt-get install -y -q build-essential git
10+
sudo apt-get install -y -q python3-pip python3-dev python3-venv
11+
sudo apt-get install -y -q unzip wget git
12+
sudo apt-get install -y -q nginx
13+
# for gzip support in uwsgi
14+
sudo apt-get install --no-install-recommends -y -q libpcre3-dev libz-dev nload
15+
16+
# Stop the hackers
17+
sudo apt install fail2ban -y
18+
19+
ufw allow 22
20+
ufw allow 80
21+
ufw allow 443
22+
ufw enable
23+
24+
# Basic git setup
25+
git config --global credential.helper cache
26+
git config --global credential.helper 'cache --timeout=720000'
27+
28+
# Be sure to put your info here:
29+
git config --global user.email "you@email.com"
30+
git config --global user.name "Your name"
31+
32+
# Web app file structure
33+
mkdir /apps
34+
chmod 777 /apps
35+
mkdir /apps/logs
36+
mkdir /apps/logs/pypi
37+
mkdir /apps/logs/pypi/app_log
38+
cd /apps
39+
40+
# Create a virtual env for the app.
41+
cd /apps
42+
python3 -m venv venv
43+
source /apps/venv/bin/activate
44+
pip install --upgrade pip setuptools
45+
pip install --upgrade httpie glances
46+
47+
48+
# clone the repo:
49+
cd /apps
50+
git clone https://github.com/talkpython/data-driven-web-apps-with-pyramid-and-sqlalchemy app_repo
51+
52+
# Setup the web app:
53+
# TODO: Replace this with correct path from repo
54+
cd /apps/app_repo/src/ch15-deploy/final/pypi_deploy
55+
# pip install -r requirements.txt
56+
python setup.py develop
57+
58+
# Copy and enable the daemon
59+
cp /apps/app_repo/src/ch15-deploy/final/pypi_deploy/server/pypi.service /etc/systemd/system/
60+
61+
systemctl start pypi
62+
systemctl status pypi
63+
systemctl enable pypi
64+
65+
# Setup the public facing server (NGINX)
66+
apt install nginx
67+
68+
# CAREFUL HERE. If you are using default, maybe skip this
69+
rm /etc/nginx/sites-enabled/default
70+
71+
cp /apps/app_repo/src/ch15-deploy/final/pypi_deploy/server/pypi.nginx /etc/nginx/sites-enabled/pypi.nginx
72+
update-rc.d nginx enable
73+
service nginx restart

0 commit comments

Comments
 (0)