Vyberaktivitu.online was an aggregator of czech online course providers running online in years 2021 and 2022. It is a CRUD application with a searchable catalog consisting of one-day or long-term online activities. Website includes a simple invitation app for registered users.
Used technologies:
- Languages - Python 3.9, JS, HTML, CSS
- Backend - Django 3.2 with various 3rd party apps (allauth, crispy-forms, etc.)
- Frontend - Django templates with Boostrap 5, Javascript 3rd party libraries, sprinkled with some simple JS
- Database - Postgres 13.3
- Development - Pycharm, Docker
- Production - VPS, Dokku
- create a new ssh key pair
cd ~/ssh/ && ssh-keygen -t rsa
and call it for example vyberaktivitu - copy public ssh key from
cat ~/.ssh/vyberaktivitu.pub
and paste to the initial set-up page - create an ssh shortcut
nano ~/.ssh/config
so you canssh root@vyberaktivitu
Host vyberaktivitu
ForwardAgent yes
Hostname <ip-address>
Port 22
ServerAliveInterval 60
ServerAliveCountMax 60
IdentityFile vyberaktivitu
- change the permissions of the config file
chmod 644 ~/.ssh/config
to fix Bad owner or permissions error - ssh in
ssh root@vyberaktivitu
and create another useradduser <name>
and add it to the sudo groupusermod -aG sudo <name>
- install dokku using (as root user) using the first script from https://dokku.com/
- from the local machine allow ssh access (no pass needed) to the new sudo user as well
ssh-copy-id -i ~/.ssh/vyberaktivitu <name>@vyberaktivitu
- point A record to the IP of the server (
vyberaktivitu.online
and*.vyberaktivitu.online
)
- open ip or domain address of the server in a web browser
- set Hostname to the same as your domain name you bought, so
vyberaktivitu.online
- check Use virtualhost naming for apps
- create app
dokku apps:create vyberaktivitu
- download plugin for the db
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
- create database and pass
DATABASE_URL
to the app
dokku postgres:create vyberaktivitu_db --image-version 13.3
sudo dokku postgres:create vyberaktivitu_db
dokku postgres:link vyberaktivitu_db vyberaktivitu
- add other env. variables
dokku config:set --no-restart vyberaktivitu DJANGO_ALLOWED_HOSTS=<ip-address>,vyberaktivitu.online,www.vyberaktivitu.online
dokku config:set --no-restart vyberaktivitu DJANGO_SETTINGS_MODULE=config.settings.production
dokku config:set --no-restart vyberaktivitu EMAIL_HOST=smtp.seznam.cz
dokku config:set --no-restart vyberaktivitu [email protected]
dokku config:set --no-restart vyberaktivitu EMAIL_HOST_PASSWORD=<password>
dokku config:show vyberaktivitu
- add domains to the app
dokku domains:add vyberaktivitu vyberaktivitu.online wwww.vyberaktivitu.online
- enable SSL (https) with letsencrypt plugin for these domains
dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
# email address for renewal warnings for your certificate
dokku config:set --no-restart --global [email protected]
# enable command can also be used to renew
dokku letsencrypt:enable vyberaktivitu
dokku letsencrypt:cron-job --add
- enable Django security settings by setting
ENVIRONMENT
env. variabledokku config:set vyberaktivitu ENVIRONMENT=production
- do a deployment check
dokku --rm run vyberaktivitu python manage.py check --deploy
and open the website to check whether there are no infinite redirects - add and link persistent storage for media files
sudo mkdir -p /var/lib/dokku/data/storage/vyberaktivitu
dokku storage:mount vyberaktivitu /var/lib/dokku/data/storage/vyberaktivitu:/app/media
sudo chown -R dokku:dokku /var/lib/dokku/data/storage/vyberaktivitu/
dokku storage:report vyberaktivitu
- create alias in nginx config to media files
sudo nano /home/dokku/vyberaktivitu/nginx.conf.d/media.conf
and add the following (the config file gets included to the main config file automatically):
location /media {
alias /var/lib/dokku/data/storage/vyberaktivitu;
}
- restart the container
dokku ps:restart vyberaktivitu
- add the public ssh key to dokku (for dokku
user)
cat ~/.ssh/vyberaktivitu.pub | ssh root@vyberaktivitu dokku ssh-keys:add key1
- add a remote repository for dokku user
git remote add dokku dokku@vyberaktivitu:vyberaktivitu
- make sure that there are the latest migration files
- make sure that
.buildpacks
consists ofhttps://github.com/heroku/heroku-buildpack-python.git
so it gets used instead of Dockerfile - make sure that
DOKKU_SCALE
consists ofweb=1
- make sure that
Procfile
consists of the following:
web: gunicorn config.wsgi:application
release: python manage.py migrate --noinput
- make sure that
runtime.txt
consists ofpython-3.9.5
- zero downtime deploy - make sure that
CHECKS
consists of//vyberaktivitu.online Vyber online aktivitu
- create a super user(s)
dokku --rm run vyberaktivitu python manage.py createsuperuser
- populate a week schedule table
dokku --rm run vyberaktivitu python manage.py fill_weekschedule
- add age categories in django admin manually
- rename
example.com
tovyberaktivitu.online
in django admin - fix 413 Request Entity Too Large error
dokku nginx:set vyberaktivitu client-max-body-size 50m
- update system
sudo apt update && sudo apt upgrade
- having created another non-root account, disable password access to root - open
sudo nano /etc/ssh/sshd_config
and changePermitRootLogin
fromyes
toprohibit-password
- remove authorized SSH key from /root/.ssh/authorized_keys (if you want to switch to root user, run
sudo su -
from the sudo user) - configure firewall - allow inbound only at TCP ports 22, 80 and 443
- check cron jobs
dokku cron:list vyberaktivitu
orsudo crontab -u dokku -l
(taken from app.json) - redirect www to non-www domain name with dokku-redirect:
sudo dokku plugin:install https://github.com/dokku/dokku-redirect.git
dokku redirect:set vyberaktivitu www.vyberaktivitu.online vyberaktivitu.online
# it's still a good idea to keep both names in dokku domains and letsencrypt
- (optional) upgrading postgres database:
docker sudo pull postgres:<version-to-upgrade-to>
dokku ps:stop vyberaktivitu
dokku postgres:export vyberaktivitu_db > /tmp/vyberaktivitu-db-export
dokku postgres:unlink vyberaktivitu_db vyberaktivitu
dokku postgres:destroy vyberaktivitu_db
dokku postgres:create vyberaktivitu_db --image-version <version-to-upgrade-to>
dokku postgres:import vyberaktivitu_db < /tmp/vyberaktivitu-db-export
dokku postgres:link vyberaktivitu_db vyberaktivitu
dokku ps:start vyberaktivitu
- (optional) updating system and dokku with dokku-update:
git clone https://github.com/dokku/dokku-update.git
cd dokku-update/
sudo ./dokku-update run -s
dokku ps:start vyberaktivitu
Dependencies:
# both
crispy-bootstrap5
Django
django-allauth
django-autoslug
django-cookie-law
django-crispy-forms
django-environ
django-filter
django-taggit
django-tinymce
Pillow
psycopg2-binary
whitenoise
# only production
gunicorn
# only local
django-debug-toolbar