|
| 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/pypi |
| 39 | +mkdir /apps/logs/pypi/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/data-driven-web-apps-with-flask app_repo |
| 54 | + |
| 55 | +# Setup the web app: |
| 56 | +cd cd /apps/app_repo/app/ch15_deploy/final/ |
| 57 | +pip install -r requirements.txt |
| 58 | + |
| 59 | +# Copy and enable the daemon |
| 60 | +cp /apps/app_repo/app/ch15_deploy/final/server/pypi.service /etc/systemd/system/pypi.service |
| 61 | + |
| 62 | +systemctl start pypi |
| 63 | +systemctl status pypi |
| 64 | +systemctl enable pypi |
| 65 | + |
| 66 | +# Setup the public facing server (NGINX) |
| 67 | +apt install nginx |
| 68 | + |
| 69 | +# CAREFUL HERE. If you are using default, maybe skip this |
| 70 | +rm /etc/nginx/sites-enabled/default |
| 71 | + |
| 72 | +cp /apps/app_repo/app/ch15_deploy/final/server/pypi.nginx /etc/nginx/sites-enabled/pypi.nginx |
| 73 | +update-rc.d nginx enable |
| 74 | +service nginx restart |
0 commit comments