|
| 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