-
Create droplet on Digitalocean, specifying to use your SSH key at creation time (so it gets added in the root account automatically).
-
Create a new A record
teamsXXpointing to the IP address of the newly created droplet. -
Delete the CNAME record for the previous year.
-
Open the console (via browser) logged in as root:
adduser itacpc --home /home/itacpc(it will prompt you to choose a password)adduser itacpc sudosu itacpcmkdir ~/.ssh- CTRL+D to logout back to root.
- Copy the right key from
/root/.ssh/authorized_keysinto/home/itacpc/.ssh/authorized_keys
-
Close the browser console.
-
Create a section in your laptop's
~.ssh/configfile such as the following:Host teams User itacpc Hostname teamsXX.itacpc.it IdentityFile ~/.ssh/your_chosen_key_rsa -
Make sure that the identity you need to clone from github is added (e.g.
ssh-add ~/.ssh/<file>). -
Log in from a normal terminal with
ssh -A teams(the-Ais to allow cloning from github). -
Update ubuntu
sudo apt update && sudo apt upgrade. -
Run
sudo apt install pipenv git postgresql nginx certbot python3-certbot-nginx. -
Clone this repository
git clone git@github.com:itacpc/teams.git. -
Enter the repository and run
pipenv install(it might be necessary to adapt thePipfileif it doesn't work immediately). -
Log in as
postgresby runningsudo su - postgres, then:- Create DB user
itacpcwith a password, by running:createuser -P itacpc - Create DB
itacpcowned by useritacpc, by running:createdb itacpc -O itacpc - Exit back to the previous shell.
- Create DB user
-
Create the log file for Django
sudo touch /var/log/django.log -
Make the log file writable
sudo chown itacpc:www-data /var/log/django.log -
Create the static files folder for Django
sudo mkdir /var/www/django -
Make the folder writable
sudo chown itacpc:www-data /var/www/django/ -
Enter the virtual environment
pipenv shell, then:- Run the migrations to initialize the DB
python3 ./manage.py migrate. - Load the universities
python3 ./manage.py loaddata universities. - Create a superuser
python3 ./manage.py createsuperuser. - Collect static files (CSS, flags, etc)
DEBUG=False python3 ./manage.py collectstatic. - Exit back to the previous shell.
- Run the migrations to initialize the DB
-
Create a
.envfile with this content:DEBUG = False REGISTRATION_IS_CLOSED = False CAN_DISCLOSE_CREDENTIALS = False SECRET_KEY = "generate-a-new-secret-key-here" EMAIL_HOST = mail-server-host-here EMAIL_PORT = 587 EMAIL_HOST_USER = mail-server-user-here EMAIL_HOST_PASSWORD = mail-server-password-here DB_NAME = itacpc DB_USER = itacpc DB_PASSWORD = database-password-here DB_HOST = 'localhost' DB_PORT = ''You can generate a key via
django-admin shellby running:from django.core.management.utils import get_random_secret_key get_random_secret_key() -
Update
itacpc/settings.pychangingteamsXX.itacpc.itto the correct year. -
Update the systemd configuration in
systemd/gunicorn.servicewith the correct Python virtual environment path. -
Copy the systemd configuration
sudo cp systemd/* /etc/systemd/system/. -
Enable the systemd configuration
sudo systemctl enable gunicorn --now. -
Update
nginx/itacpcchangingteamsXX.itacpc.itto the correct year. -
Copy the nginx configuration
sudo cp nginx/itacpc /etc/nginx/sites-available/. -
Disable the default nginx configuration
sudo rm /etc/nginx/sites-enabled/default. -
Enable the new nginx configuration
sudo ln -s /etc/nginx/sites-available/itacpc /etc/nginx/sites-enabled/itacpc. -
Run certbot to fix HTTPS stuff:
sudo certbot.
- Backup the teams database in the "dumpdata" JSON format that Django can export/import:
./manage.py dumpdata --all --output teams20XX_dumpdata.json - Also backup in the Postgres format, just in case:
pg_dump -f teams20XX_pgdump.sql - Save these backup files in the
manage/archive/teams-datafolder. - TODO: should we change nginx configuration to redirect
teamsXX.itacpc.ittoitacpc.itfor a while? For SEO reasons? Probably not so important anyway. - Delete the
teamsXXDNS entry from Cloudflare. - Destroy the droplet from Digitalocean.