farasjibran / django-rest-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Todo API

Python version Django version Django-RestFramework Stars Forks Commit activity

Table of Contents

Description

Todo API is an project for me to learn how to use the django in python and how to dockerize the project

Install (Run) with Docker

About the Builds and Images in use:

There are currently 3 services in use: the api (Django App), the db (the postgrSQL database), and the nginx (Nginx configuration). - api: The Django Dockerfile is in the root directory, and it has an entrypoint file that connects the backend to the database and runs migrations as well as collects the statics. - db: This is built from the postgres:13-alpine image. The default environment variables are set in the docker-compose.yml file. - nginx: The default configuration for nginx is inside the nginx folder in the nginx.conf file.

Runing Docker-Compose

  1. Clone the repo:

    git clone https://github.com/farasjibran/django-rest-api
  2. Configure the environment variables.

    1. Copy the content of the example env file that is inside the django-rest-api folder into a .env file:
      cp .env.example .env
    2. The new .env file should contain all the environment variables necessary to run all the django app in all the environments. However, the only needed variables for docker to run are the following:
      SECRET_KEY
      DB_NAME
      DB_USER
      DB_PASSWORD
      DB_HOST
      DB_PORT
    3. For the database, the default configurations should be:
      DB_NAME=db_todos
      DB_USER=todos_user
      DB_PASSWORD=todos_password!
      DB_HOST=db
      DB_PORT=5432
    4. The DOCKER_SECRET_KEY is the django secret key. To generate a new one see: Stackoverflow Link
  3. Run docker-compose:

    docker-compose up --build
  4. Congratulations =) !!! The App should be running in localhost:80

  5. (Optional step) To create a super user run:

    docker-compose run api ./manage.py createsuperuser

Installation without Docker

  1. Clone the repo:

    git clone https://github.com/farasjibran/django-rest-api
  2. Configure a virtual env and set up the database. See Link for configuring Virtual Environment and Link for Database setup.

  3. Configure the environment variables.

    1. Copy the content of the example env file that is inside the django-rest-api folder into a .env file:
      cp .env.example .env
    2. The new .env file should contain all the environment variables necessary to run all the django app in all the environments. However, the only needed variables for the development environment to run are the following:
      SECRET_KEY
      DB_NAME
      DB_USER
      DB_PASSWORD
      DB_HOST
      DB_PORT
    3. For the database, the default configurations should be:
      DB_NAME=todo_app
      DB_USER=postgres
      DB_PASSWORD=
      DB_HOST=localhost
      DB_PORT=5432
    4. The SECRET_KEY is the django secret key. To generate a new one see: Stackoverflow Link
  4. Run the migrations and then the app:

    python manage.py migrate
    python manage.py runserver
  5. Congratulations =) !!! The App should be running in localhost:8000

  6. (Optional step) To create a super user run:

    python manage.py createsuperuser

Useful Links

Postgresql Databse

Docker

Django and DRF

Miscellaneous

About


Languages

Language:Python 92.8%Language:Dockerfile 4.3%Language:Shell 2.8%