Skip to content

ermantraun/aromastream_django

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aromastream Django

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

Contents

Pre-requirements

Make sure you have the following tools installed:

  • Docker

Create a project network in Docker

Create a project network in Docker:

docker network create aromastream

Starting the PostgreSQL image

0 Clone the repository

1 Build the Docker image

If you have not yet built a Docker image, run the following command into the db_dockerfile directory and execute:

docker build -t postgres  

2 Create a volume to store the data

Create a PostgreSQL data storage volume to save data between container restarts:

docker volume create postgres_data

3 Start the container

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

Project Startup

  1. Create a Docker image and start the container:
    docker build -t aromastream_django  
    docker run -it --name django -p 80:80 --network aromastream aromastream aromastream_django bash
    This will start the container with your application Port 80 will be used for Django web service via Nginx and uWSGI
  2. Apply migrations
    python manage py migrate
  3. 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

Project Structure

  • 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

Important Settings

Database

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

Security

  • DEBUG: True - debug mode including detailed error messages (not recommended for production environments)
  • ALLOWED_HOSTS: ['*'] - list of allowed hosts to access the application

Applications and middleware

  • INSTALLED_APPS: include Django's base applications and additional applications such as drf_spectacular for automatically generating API schemas, rest_framework for building APIs, and drf_api_logger for logging requests
  • MIDDLEWARE: include standard Django middleware and APILoggerMiddleware for API logging

JWT Authentication

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

API Logging

  • 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

Configuring CORS

  • 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

Advanced Settings

  • ARDUINO_URL: 'localhost:1203/{}' - URL to communicate with Arduino
  • PAGE_SIZE: 15 - page size for API pagination
  • TIME_ZONE: 'Europe/Moscow' - time zone setting

URL-templates

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

Notes

  • 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •