Aller au contenu

Lancer le projet ​

Ce qu'il te faut ​

  • Python 3.11 ou plus récent, et pip.
  • PostgreSQL est optionnel en local : sans lui, l'API utilise SQLite.

Sans Docker, avec SQLite ​

C'est le plus rapide pour commencer :

sh
cd api
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
DB_HOST= python manage.py migrate
DB_HOST= python manage.py runserver 0.0.0.0:8000

Vérifie http://127.0.0.1:8000/health, puis la liste des produits sur http://127.0.0.1:8000/api/products/. Django REST Framework affiche une page navigable, avec un formulaire pour créer un produit.

Pourquoi DB_HOST= devant chaque commande ? Le fichier .env d'exemple pointe vers PostgreSQL. Vider DB_HOST fait basculer l'API sur SQLite. Voir Configuration et démarrage.

Avec PostgreSQL ​

Si tu as un PostgreSQL qui tourne, remplis DB_NAME, DB_USER, DB_PASSWORD, DB_HOST dans api/.env, puis :

sh
python manage.py migrate
python manage.py runserver 0.0.0.0:8000

Avec Docker ​

Depuis la racine du dépôt :

sh
# Dev : runserver
docker build -f api/Dockerfile.dev -t trinity-api:dev api
docker run -p 8000:8000 -e DB_HOST= trinity-api:dev

# Prod : Gunicorn, l'image exacte qui part en production
docker build -f api/Dockerfile.prod -t trinity-api:local api

L'image de prod refuse de démarrer sans SECRET_KEY quand DEBUG=False, et elle attend un PostgreSQL. Voir Configuration et démarrage.

Les commandes utiles ​

Commande (dans api/)Ce qu'elle fait
python manage.py runserverServeur de développement
python manage.py makemigrationsÉcrit une migration après un changement de modèle
python manage.py migrateApplique les migrations
python manage.py createsuperuserCrée un compte pour /admin/
DB_HOST= pytestLance les tests
flake8 products trinity_apiLint