This project is a Django web application that uses PostgreSQL as a database, and uses uwsgi + nginx This README md
explains how to run the project using Docker
- Pre-requirements
- Create a project network in Docker
- Project Launch
- Project Structure
- Important Settings
- URL Templates
- Notes
Make sure you have the following tools installed:
- Docker
Create a project network in Docker:
docker network create aromastream
If you have not yet built a Docker image, run the following command into the db_dockerfile directory and execute:
docker build -t postgres
Create a PostgreSQL data storage volume to save data between container restarts:
docker volume create postgres_data
You can start a PostgreSQL container without using environment variables This method uses the default PostgreSQL settings specified in the Dockerfile:
docker run -d \
--name psg \
-p 5432:5432 \
-v postgres_data:/var/lib/postgresql/data
--network aromastream
postgres
-d
: Runs the container in the background--name my_postgres_container
: Specifies the name of the container-p 5432:5432
: Forces port 5432 of the container to port 5432 of the host-v postgres_data:/var/lib/postgresql/data
: Connects persistent storage for PostgreSQL data
- Create a Docker image and start the container:
This will start the container with your application Port 80 will be used for Django web service via Nginx and uWSGI
docker build -t aromastream_django docker run -it --name django -p 80:80 --network aromastream aromastream aromastream_django bash
- Apply migrations
python manage py migrate
- Start Nginx and uWSGI:
In the container, run the following commands to start Nginx and uWSGI:
service nginx start
uwsgi --ini configs/uwsgi ini
These commands will start Nginx as a web server and uWSGI to handle requests to your Django application
- Dockerfile - file with instructions for building the Docker image
- requirements txt - list of Python dependencies for the project
- manage py - command line utility for managing your Django project
- api/ - the main directory of your project containing the Django application
The project uses PostgreSQL as the database Connection settings:
- ENGINE: django db backends postgresql - driver for working with PostgreSQL
- NAME: django - name of the database
- USER: django - user name to connect to the database
- PASSWORD: 8995 - user password to connect to the database
- HOST: 127 0 0 1 - address of the database server
- PORT: 5432 - the port of the database server
- DEBUG: True - debug mode including detailed error messages (not recommended for production environments)
- ALLOWED_HOSTS: ['*'] - list of allowed hosts to access the application
- INSTALLED_APPS: include Django's base applications and additional applications such as
drf_spectacular
for automatically generating API schemas,rest_framework
for building APIs, anddrf_api_logger
for logging requests - MIDDLEWARE: include standard Django middleware and
APILoggerMiddleware
for API logging
Uses the rest_framework_simplejwt
library for authentication:
- SLIDING_TOKEN_LIFETIME: 30 days is the lifetime of the JWT token
- SLIDING_TOKEN_REFRESH_LIFETIME: 1 second - lifetime of the update token
- DRF_API_LOGGER_DATABASE: True - enable logging of requests to the database
- DRF_LOGGER_QUEUE_MAX_SIZE: 50 - maximum queue size for logging
- DRF_API_LOGGER_EXCLUDE_KEYS: ['password', 'token'] - keys that will be excluded from the logs
- CORS_ALLOWED_ORIGINS: Not used - List of sources that are allowed to make cross-site HTTP requests
- CORS_ALLOW_ALL_ORIGINS: True - If True, all sources will be allowed
- ARDUINO_URL: 'localhost:1203/{}' - URL to communicate with Arduino
- PAGE_SIZE: 15 - page size for API pagination
- TIME_ZONE: 'Europe/Moscow' - time zone setting
Below are the available API routes and their destinations:
- /admin/: the Django admin interface for managing the application
- /api/: the main prefix for all API endpoints All API routes will be accessible via this path
- /api/login/:
TokenObtainSlidingView
- get JWT token for authentication - /api/signup/:
UserCreateView
- creating a new user - /api/user/:
UserGetView
- getting information about the current user - /api/user/update/:
UserUpdateView
- updating the current user's data - /api/password_reset/:
UserPasswordUpdateView
- reset user's password - /api/password_reset/confirm/:
UserPasswordUpdateConfirmView
- confirm password reset - /api/timestamps/:
TimeStampCreateView
- creating new timestamps - /api/timestamps/<int:video_id>/:
TimeStampListView
- get a list of timestamps for the specified video - /api/videos/:
VideoListView
- get a list of videos - /api/videos/<int:video_id>/:
VideoDetailView
- get detailed information about the video - /api/videos/popular/:
PopularVideoListView
- get a list of popular videos - /api/videos/search/:
SearchVideoListView
- search video by criteria - /api/arduino/trigger:
TriggerListView
- call a trigger to interact with Arduino - /api/schema/swagger-ui/:
SpectacularSwaggerView
- display the API schema in the Swagger UI - /api/schema/redoc/:
SpectacularRedocView
- display the API schema in ReDoc
- The PostgreSQL user and database are created automatically when the container is started
- To access the database, use the following parameters:
- Host:
- Port: 5432
- Username: django
- Password: 8995
- Database name: django
- For security, it is important to change the secret key from SECRET_KEY in Django settings
If you have any questions or concerns, please create an issue in the project repository