Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

ragnarok22/instashare_api

Repository files navigation

InstaShare API

InstaShare API

Django CI Codecov GitHub license GitHub tag (latest by date) GitHub repo size GitHub commit activity

License

Distributed under the terms of the MIT license.

Running in development mode

This project was built using:

create an isolation environment

(This step is not required if you use poetry)

python -m venv .venv

install dependencies

pip install .

or use poetry:

poetry install

Activate the local environment

source .venv/bin/activate

or use poetry:

poetry shell

Then run the development server

python manage.py runserver

Deploy

This project uses Docker for deployment

environment variables

You must create .env file with the next variables:

  • DJANGO_SETTINGS_MODULE: project settings. (set config.settings.develop).
  • SECRET_KEY: used to provide cryptographic signing.
  • DB_HOST: postgres database host.
  • DB_PORT: postgres database port.
  • DB_USER: postgres database user.
  • POSTGRES_PASSWORD: postgres database password.
  • POSTGRES_DB: postgres database name.
  • ALLOWED_HOSTS: A list of strings representing the host/domain names that this Django site can serve.
  • REDIS_URL: The redis url. (Ex: redis://localhost:6379)

Here you have an example

deploy the application

You must have installed Docker and Docker Compose to run the application:

docker-compose up -d

Set Nginx

Here set an example for a nginx configuration and with the certbot to manage the ssl. This project is set to only run in secure protocol (https)

server {
    server_name instashare-api.ragnarok22.dev;

    location / {
        proxy_pass http://localhost:8000;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/instashare-api.ragnarok22.dev/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/instashare-api.ragnarok22.dev/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = instashare-api.ragnarok22.dev) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;

    server_name instashare-api.ragnarok22.dev;
    return 404; # managed by Certbot
}

Running tests

For running test

coverage run manage.py test apps
coverage report

API Documentation

Run the project:

python manage.py runserver

And then go to http://localhost:8000/docs/