Basic setting is based on blog post.
First clone or fork the repository. Your own repository might be private.
$ git clone https://github.com/nhatcher/feirou.git
After that create a virtual environment and install requirements
$ cd users-template/
$ python -m venv venv
$ source venv/bin/activate
Then you need to apply the migrations. This will create an sqlite3 file in server/
.
(venv) $ pip install -r requirements.txt
(venv) $ cd server
(venv) server $ python manage.py migrate
Create a superuser
(venv) server $ python manage.py createsuperuser
Install caddy, only the binary in necessary. Note in particular that caddy shouldn't be running as a daemon in your local machine.
I normally download the binary, copy it to /opt/caddy/
and add the path to PATH
so it can be run in a terminal.
You need to have three servers running:
A proxy server:
$ caddy run
The front end:
frontend$ npm install
frontend$ npm run dev
The django server:
(venv) server$ python manage.py runserver
That's it, you can visit now http://localhost:2080/ and test your application locally!
That will run the linter, formatter, type checker and tests
(venv) $ ./run_tests.sh
- Get your own domain name with Namecheap (will cost you ~10โฌ per year)
- Create a Zoho account and link it to your domain name (free). In your zoho account create two email accounts. One for you the superuser and one for '[email protected]'
- Create an account in Sentry (free).
- Create an account on DigitalOcean. Free until we create a droplet.
Get the cheapest droplet in DigitalOcean. At the time of writing this is 4$/month. Choose the Ubuntu OS with the latest version (at the time of writing 23.04 x64, but the LTS version will work as well).
Make sure the Authentication method is 'SSH Key' and not 'Password'. You should setup the VPS in a way that you can ssh with your username only if ssh keys are correctly setup. Feel free to change the Hostname.
Once the droplet is created make sure the DNS is configured properly and points to your computer. You should be able to ssh [email protected]
. This usually involves changing DNS settings in you domain registrar provider. Note that it might take some time for the DNS config to propagate. This is a good moment to make yourself some coffee or go for a stroll. If you are lucky it's just a few minutes.
Don't install anything on your VPS or modify config files.
Create the file server_config.ini
filling each entry carefully.
Create an deployments_scripts
directory in the remote machine and copy the contents of everything inside deployment_scripts/
into that folder:
jsmith@local:~/$ rsync -a deployment_scripts [email protected]:~/
jsmith@local:~/$ scp ~/secrets/server_config.ini [email protected]:~/deployment_scripts/
In the remote computer, as a superuser run:
root@remote:~/deployment_scripts# ./install.sh
After that reboot your system. Just (from any directory):
# reboot
That's it! You are now ready for deployment!
As a final configuration we should create a user in the machine that you will use to mange the machine. Add the user to the sudoers list. Choose a good password.
# adduser jsmith
# usermod -aG sudo jsmith
Copy the ssh keys from root
to jsmith
and setup the right permissions
# mkdir /home/jsmith/.ssh/
# cp ~/.ssh/authorized_keys /home/jsmith/.ssh/authorized_keys
# chown jsmith:jsmith /home/jsmith/.ssh/ -R
# chmod 700 /home/jsmith/.ssh/ -R
Make sure you can ssh as jsmith
from your local machine and run sudo commands.
In the remote machine, as root, remove your authorized_keys:
# rm ~/.ssh/authorized_keys
Now [email protected]
should not work but [email protected]
should.
-
Issues with Systemd
Please refer to our Systemd services crash course
-
Caddy and Gunicorn logs
If configured correctly Caddy access logs should be at /var/log/caddy/access.log
and ``. A nice way to inspect those logs is jq:
# tail -f /var/log/caddy/access.log | jq .request.uri
Similarly logs created by Gunicorn will be at /var/log/django/access.log
and /var/log/django/error.log
.
- Application logs
This are the logs generated by your application and they will be sent to Sentry. You can also find the at:
# tail -f /var/log/django/django.log
Please have a look at the blog post.
If everything has been correctly set up, deployment will be a matter of running one script.
First push the code you want to deploy to the main branch on GitHub
As root in the remote computer just run
root@remote:~# deploy.sh
That will pull the latest code, create the virtualevn, install the dependencies, make migrations if needed and copy all the files needed.
Your app should be up and running at https://app.example.com
The app is in Brazilian Portuguese and English.
We need to install Linux gettext
:
$ sudo apt install gettext
$ sudo apt install gettext-doc autopoint libasprintf-dev libgettextpo-dev
Create the po
files.
(venv) $ django-admin makemessages --all
Fill in the translations
(venv) $ django-admin compilemessages
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.