Skip to content

This starter employs Django, Django Rest Framework, and PostgreSQL to construct a REST API with OpenAPI documentation, integrated with Docker, Docker Compose, and GitHub Actions.

Notifications You must be signed in to change notification settings

smallmacro/docker-drf-quick-starter

Repository files navigation

docker-drf-quick-starter

This starter employs Django, Django Rest Framework, and PostgreSQL to construct a REST API with OpenAPI documentation, integrated with Docker, Docker Compose, and GitHub Actions.

Features

  • Django web application framework
  • Postgresql database
  • Github Actions. For automatic testing , linting and Deployment. In order to connect the github with docker hub, we need to add Docker Hub's account name and access token into github repository secrets.
  • Test Driven Development. Write Test -> Run Test(fail) -> add Feature -> Run Test(Passes). base on unittest library and Django REST Framework test features.
  • Docker.
  • Fix database race condition by customing Django management command wait_for_db. Django Docs management command

Included Packages and Tools

  • Docker and Docker Hub account for pulling images for Python and Postgresql. Anonymous users vs authorized users rate limits
  • Github Actions for automatic linting and testing.(Need to set up DOCKERHUB_USER and DOCKERHUB_TOKEN in github secrets in order to pull images from Dock hub)
  • Django and Django REST Framework
  • Postgresql
  • Psycopg2, the postgresql database adaptor for python, requirs additional dependencies: build-base, postgresql-dev, musl-dev, postgresql-client
  • flake8 for linting.
  • Pillow for image uploading
  • drf-spectacularfor OPENAPI docs

Linting and Testing Commands

# app is the name of service.
docker-compose run --rm app sh -c "flake8"   #linting
docker-compose run --rm app sh -c "python manage.py test"   #tesing

Requirements

  • Django>=4.0.1,<4.1
  • djangorestframework>=3.13.1,<3.14
  • psycopg2>=2.9.3,<2.10
  • drf-spectacular>=0.22.1,<0.23
  • Pillow>=9.1.0,<9.2
  • uwsgi>=2.0.20,<2.1
  • flake8>=4.0.1,<4.1

Django Project structure

📦
├─ .dockerignore
├─ .env.sample
├─ .github
│  └─ workflows
│     └─ checks.yml.sample
├─ Dockerfile
├─ README.md
├─ docker-compose.yml
├─ requirements.dev.txt
├─ requirements.txt
├─ scripts
│  └─ run.sh
└─ src
   ├─ .flake8
   ├─ app
   │  ├─ __init__.py
   │  ├─ asgi.py
   │  ├─ settings.py
   │  ├─ urls.py
   │  └─ wsgi.py
   ├─ core
   │  ├─ __init__.py
   │  ├─ admin.py
   │  ├─ apps.py
   │  ├─ management
   │  │  ├─ __init__.py
   │  │  └─ commands
   │  │     ├─ __init__.py
   │  │     └─ wait_for_db.py
   │  ├─ migrations
   │  │  └─ __init__.py
   │  ├─ models.py
   │  └─ tests
   │     ├─ __init__.py
   │     └─ test_commands.py
   └─ manage.py

©generated by Project Tree Generator

A newly initiating Django project with custom Django management command wait_for_db implemented and tested in core folder. The core will manage all the models used in this projects and custom admin site functionality.

Recommendations

  • Test Driven Development. Create tests folders in each subredictory with every file starting file name with test_ in order to manage all test functions.

About

This starter employs Django, Django Rest Framework, and PostgreSQL to construct a REST API with OpenAPI documentation, integrated with Docker, Docker Compose, and GitHub Actions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published