-
Create droplet on Digitalocean, specifying to use your SSH key at creation time (so it gets added in the root account automatically).
-
Update the
teams
DNS record on Cloudflare so thatteams.itacpc.it
points to the IP address of the newly created droplet. -
Create a new CNAME record for the year-specific subdomain (e.g.
teamsXX
) which points toteams.itacpc.it
. -
Delete the CNAME record for the previous year.
-
Open the console (via browser) logged in as root:
useradd itacpc
.adduser itacpc sudo
.- Copy the right key from
/root/.ssh/authorized_keys
into/home/itacpc/.ssh/authorized_keys
.
-
Close the browser console.
-
Create a section in your laptop's
~.ssh/config
file such as the following:Host teams User itacpc Hostname teamsXX.itacpc.it IdentityFile ~/.ssh/your_chosen_key_rsa
-
Log in from a normal terminal with
ssh teams
. -
Update ubuntu
sudo apt update && sudo apt upgrade
. -
Run
sudo apt install pipenv git postgresql nginx certbot
. -
Clone this repository
git clone [email protected]:itacpc/teams.git
. -
Enter the repository and create the pipenv
pipenv install
. -
Log in as
postgres
by runningsudo su - postgres
, then:- Create DB user
itacpc
with a password, by running:createuser -P itacpc
. - Create DB
itacpc
owned 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 root: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)
python3 ./manage.py collectstatic
. - Exit back to the previous shell.
- Run the migrations to initialize the DB
-
Create a
.env
file 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 shell
by running:from django.core.management.utils import get_random_secret_key get_random_secret_key()
-
Update the systemd configuration in
systemd/gunicorn.service
with 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
. -
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
.
- TODO: backup
- TODO: change nginx configuration to redirect
teamsXX.itacpc.it
toitacpc.it
- Destroy the droplet.