This is an open-source tool for creating a database of sources.
(hat tip to Digital Ocean Django and Postgres)
The following instructions are intended for Ubuntu 16.
sudo apt-get update
sudo apt-get install python3-pip
sudo apt-get install git
sudo apt-get install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx
Install packages
sudo -H pip3 install --upgrade pip
sudo -H pip3 install virtualenv virtualenvwrapper
For Python3 and pip3
echo "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3" >> ~/.bashrc
Finalize the process
echo "export WORKON_HOME=~/Env" >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
Execute the bash script
source ~/.bashrc
Enter the database shell
sudo -u postgres psql
Create the database
CREATE DATABASE sourcelist;
Create the user
CREATE USER sourcelistuser WITH PASSWORD 'password-here';
Grant permissions
GRANT ALL PRIVILEGES ON DATABASE sourcelist TO sourcelistuser;
Close the shell
\q
Generate ssh key
ssh-keygen -t rsa -b 4096 -C "youremail"
Make the virtual environment
mkvirtualenv sourcelist
Clone the repo (or your fork)
git clone [email protected]:greglinch/sourcelist.git
Change into the directory
cd sourcelist
Install the requirements
pip3 install -r requirements.txt
Create the private settings file and fill in the vars with "UPDATE" comments
mv sourcelist/settings_private.py.dev sourcelist/settings_private.py
Initial migration for admin tables
python3 manage.py migrate
Initial migration for the app
python3 manage.py makemigrations sources
python3 manage.py migrate
Create a super user
python3 manage.py createsuperuser
Collect static assets
python3 manage.py collectstatic
Update the firewall permissions
sudo ufw allow 8080
Test the local server
python3 manage.py runserver 0.0.0.0:8080
Then navigate to the live site
domain.com:8080
Stop the local server
Ctrl + C
Exit your virtualenv
deactivate
Install key pieces
sudo -H pip3 install uwsgi
Make directory for sites
sudo mkdir -p /etc/uwsgi/sites
Make the ini file
sudo vim /etc/uwsgi/sites/sourcelist.ini
Paste in these settings
[uwsgi]
logto = /var/log/uwsgi/error.log
project = sourcelist
uid = ubuntu
base = /home/%(uid)
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 5
socket = /run/uwsgi/%(project).sock
chown-socket = %(uid):www-data
chmod-socket = 660
vacuum = true
Create a systemd unit file
sudo vim /etc/systemd/system/uwsgi.service
Paste this
[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown ubuntu:www-data /run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
Install nginx
sudo apt-get install nginx
Create a config file
sudo vim /etc/nginx/sites-available/sourcelist
Add this
server {
listen 80;
server_name YOUR-DOMAIN.COM;
access_log /var/log/nginx/sourcelist_access.log;
error_log /var/log/nginx/sourcelist_error.log;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/sourcelist/;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/sourcelist.sock;
}
}
Remove the symlink for the default site
sudo rm /etc/nginx/sites-enabled/default
Symlink the available site to an enable site
sudo ln -s /etc/nginx/sites-available/sourcelist /etc/nginx/sites-enabled
Check the configuration
sudo nginx -t
Restart nginx
sudo systemctl restart nginx
Start uwsgi
sudo systemctl start uwsgi
Update the firewall rules
sudo ufw delete allow 8080
sudo ufw allow 'Nginx Full'
Enable uwsgi and nginx to run on startup
sudo systemctl enable nginx
sudo systemctl enable uwsgi
For example:
https://certbot.eff.org/#ubuntuxenial-nginx
Run this command to generate or re-generate the translation file:
python3 manage.py makemessages -l es
Run this command to compile the translation:
python3 manage.py compilemessages
TODO: Write a fabric script to do this.
In the virtualenv:
-
git checkout main
-
git pull origin main
-
pip3 install -r requirements.txt
-
python3 manage.py makemigrations
-
python3 manage.py migrate
-
python3 manage.py buildwatson
-
sudo systemctl restart uwsgi