This repository is only for Backend part of TechnoTrack FullStack development course by Mail.Ru.
sudo apt update
sudo apt nginx python3 memcached
sudo apt install git -y
sudo apt install redis-server -y
sudo apt install python3-pip -y
sudo pip3 install virtualenv
sudo systemctl start memcached
git clone https://github.com/denisstasyev/messenger-backend.git
cd messenger-backend/
virtualenv venv
pip3 install -r requirements.txt
source venv/bin/activate
Change user from "denis" to your local user in ./routing_configs/nginx/messenger-backend.conf, change server_name to your (my: stasyev.chikenkiller.com)
sudo cp ./routing_configs/nginx/stasyev.chickenkiller.com /etc/nginx/sites-available
sudo ln -s /etc/nginx/sites-available/stasyev.chickenkiller.com /etc/nginx/sites-enabled
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
mkdir instance
touch ./instance/production.cfg
flask db upgrade
In production.cfg add SQLALCHEMY_DATABASE_URI (better to use Postgresql), MAIL_PASSWORD and SECRET_KEY. Finally change in app/_init_.py line to:
app.config.from_pyfile("production.cfg", silent=True)
HTTPS via Certbot
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot python-certbot-nginx -y
sudo certbot --nginx
sudo certbot renew --dry-run
Run this project with commands:
cd messenger-backend/
source venv/bin/activate
gunicorn -c routing_configs/gunicorn/gunicorn.conf.py run:app
To setup this project:
- setup nginx in folder /configs;
- create database:
sudo apt install postgresql
sudo -u postgres psql
CREATE USER denis WITH ENCRYPTED PASSWORD 'your_password';
CREATE DATABASE "messenger" OWNER denis;
GRANT ALL PRIVILEGES ON DATABASE "messenger" TO denis;
- setup database via migrations.
flask db init
flask db migrate -m "000_some_text"
flask db upgrade
In case of any migration problems:
DROP TABLE alembic_version;
psql messenger-backend-development
SELECT * FROM users;
You can use any migration commant via db postfix, for example:
python3 run.py db upgrade
Celery creates queue of asynchronous tasks. To enable asynchronous tasks run command below at the same time with Gunicorn command above:
celery -A app.celery worker --loglevel=INFO
For scheduled tasks run also Celery Beat:
celery -A app.celery beat --loglevel=INFO
To manage celery use Flower:
flower -A app.celery --port=5555
sudo apt install memcached
sudo systemctl start memcached