We develop a microblogging site using Flask as shown in Miguel Grinberg's Mega-Tutorial
We have installed so far:
- Python
- Flask
- python-dotenv
- Flask-WTF
- WTForms
- Flask-SQLAlchemy
- Flask-Migrate
- Flask-Login
- Flask-Moment
- email-validator
- langdetect
- requests
- elasticsearch
First, create a virtual environment in our main directory, and install the necessary packages:
$ python -m venv venv
$ source venv/bin/activate
$ [venv] pip install -r requirements.txtRun flask run on the top-level directory
To install the Elasticsearch engine in Docker:
$ sudo docker network create elastic
$ sudo docker pull docker.elastic.co/elasticsearch/elasticsearch:9.1.4To start the Elasticsearch engine with Docker, run
$ sudo docker run --name elasticsearch --network elastic \
--rm -p 9200:9200 --memory 2GB -e discovery.type=single-node \
-e xpack.security.enabled=false \
-t docker.elastic.co/elasticsearch/elasticsearch:9.1.4
We use Celery as our task queue. In addition to that, we need either a Redis or Valkey server up and running.
To get our Celery worker started, we need to
$ celery -A microblog.celery_app worker --loglevel INFOon our root directory.
To create the VM with the provided Vagrantfile:
$ vagrant upWe can start a SSH session with $ vagrant ssh and set up our environment.
Once inside the VM shell, we install the following packages:
$ sudo apt-get -y update
$ sudo apt-get -y install python3 python3-venv python3-dev
$ sudo apt-get -y install mysql-server postfix supervisor nginx gitBe sure to install Elasticsearch as you see fit, in my case I still used
the Docker container. Use the files found in deployment to configure
both supervisor and nginx.
Install as directed above, then add these additional packages.
[venv] $ pip install gunicorn pymysql cryptographyConfigure the .env file
SECRET_KEY=52cb883e323b48d78a0a36e8e951ba4a
MAIL_SERVER=localhost
MAIL_PORT=25
DATABASE_URL=mysql+pymysql://microblog:<db-password>@localhost:3306/microblog
MS_TRANSLATOR_KEY=<your-translator-key-here>We now compile the language translations
[venv] $ flask translate compileTo set up the MySQL server, supervisor and nginx, please refer to Miguel's tutorial
I should figure out how to automate the app deployment, either to a Linux box or using a multi-container solution such as Docker Compose.