feat: Configuration Docker Compose à 3 services
- Frontend: Flutter web (app.ptits-pas.fr) - Backend: NestJS API (app.ptits-pas.fr/api) - Database: PostgreSQL 17 + PgAdmin (app.ptits-pas.fr/pgadmin) - Réseau: ptitspas_network + proxy_network (Traefik) - Documentation architecture et déploiement
This commit is contained in:
parent
bbf73458cb
commit
ad81a2f4f4
72
README-ARCHITECTURE.md
Normal file
72
README-ARCHITECTURE.md
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
# 🏗️ Architecture du projet P'tits Pas
|
||||||
|
|
||||||
|
## 📁 Structure du projet
|
||||||
|
|
||||||
|
Ce projet est organisé en **3 dépôts Git distincts** :
|
||||||
|
|
||||||
|
- **`ptitspas-frontend`** : Application Flutter (interface utilisateur)
|
||||||
|
- **`ptitspas-backend`** : API NestJS (serveur backend)
|
||||||
|
- **`ptitspas-database`** : Configuration PostgreSQL et migrations
|
||||||
|
|
||||||
|
## 🌍 Deux environnements supportés
|
||||||
|
|
||||||
|
### 🚀 **Environnement de production (serveur)**
|
||||||
|
- **Localisation** : `/home/ynov/project/` sur le serveur
|
||||||
|
- **Configuration** : `docker-compose.yml` + `.env`
|
||||||
|
- **Domaine** : `https://ynov.ptits-pas.fr`
|
||||||
|
- **Reverse proxy** : Traefik avec SSL automatique
|
||||||
|
- **Gestion** : Déploiement automatique via webhooks Gitea
|
||||||
|
|
||||||
|
### 💻 **Environnement de développement (local)**
|
||||||
|
- **Configuration** : `docker-compose.dev.yml` + `.env.example` dans chaque dépôt
|
||||||
|
- **Accès** : Ports locaux (3000, 8000, 8080, 5432)
|
||||||
|
- **Hot reload** : Modifications de code prises en compte instantanément
|
||||||
|
- **Base locale** : PostgreSQL indépendante avec PgAdmin
|
||||||
|
|
||||||
|
## 🏃♂️ Guide de démarrage développeur
|
||||||
|
|
||||||
|
### 1. **Backend** (à démarrer en premier)
|
||||||
|
```bash
|
||||||
|
git clone <url-backend>
|
||||||
|
cd ptitspas-backend
|
||||||
|
cp .env.example .env
|
||||||
|
docker compose -f docker-compose.dev.yml up -d
|
||||||
|
```
|
||||||
|
**Accès** : http://localhost:3000/api
|
||||||
|
|
||||||
|
### 2. **Frontend**
|
||||||
|
```bash
|
||||||
|
git clone <url-frontend>
|
||||||
|
cd ptitspas-frontend
|
||||||
|
cp .env.example .env
|
||||||
|
docker compose -f docker-compose.dev.yml up -d
|
||||||
|
```
|
||||||
|
**Accès** : http://localhost:8000
|
||||||
|
|
||||||
|
### 3. **PgAdmin** (inclus avec le backend)
|
||||||
|
**Accès** : http://localhost:8080
|
||||||
|
- Email : admin@localhost
|
||||||
|
- Mot de passe : admin123
|
||||||
|
|
||||||
|
## 🔄 Workflow de développement
|
||||||
|
|
||||||
|
1. **Développer localement** avec les `docker-compose.dev.yml`
|
||||||
|
2. **Tester les modifications** sur http://localhost:8000
|
||||||
|
3. **Commiter et pousser** dans les dépôts respectifs
|
||||||
|
4. **Déploiement automatique** sur le serveur via webhooks
|
||||||
|
|
||||||
|
## 🗂️ Fichiers de configuration
|
||||||
|
|
||||||
|
| Fichier | Usage | Localisation |
|
||||||
|
|---------|-------|--------------|
|
||||||
|
| `docker-compose.yml` | Production (serveur) | `/home/ynov/project/` |
|
||||||
|
| `docker-compose.dev.yml` | Développement (local) | Chaque dépôt |
|
||||||
|
| `.env` | Variables production | Serveur uniquement |
|
||||||
|
| `.env.example` | Template développement | Chaque dépôt |
|
||||||
|
|
||||||
|
## 🔒 Sécurité
|
||||||
|
|
||||||
|
- ✅ Fichiers `.env` **non versionnés** (ajoutés au `.gitignore`)
|
||||||
|
- ✅ Variables sensibles **externalisées**
|
||||||
|
- ✅ Configurations **séparées** dev/prod
|
||||||
|
- ✅ SSL automatique en production via Let's Encrypt
|
||||||
144
README-DEPLOYMENT.md
Normal file
144
README-DEPLOYMENT.md
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
# 🚀 Déploiement YNOV - Architecture Complète
|
||||||
|
|
||||||
|
## 🌐 URLs d'accès
|
||||||
|
|
||||||
|
- **Application principale** : https://ynov.ptits-pas.fr/
|
||||||
|
- **API Backend** : https://ynov.ptits-pas.fr/api/
|
||||||
|
- **Administration DB** : https://ynov.ptits-pas.fr/pgadmin/
|
||||||
|
|
||||||
|
## 🏗️ Architecture
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
||||||
|
│ Frontend │ │ Backend │ │ Database │
|
||||||
|
│ (Flutter) │───▶│ (NestJS) │───▶│ (PostgreSQL) │
|
||||||
|
│ ynov-frontend │ │ ynov-backend │ │ ynov-postgres │
|
||||||
|
│ Port: 80 │ │ Port: 3000 │ │ Port: 5432 │
|
||||||
|
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
||||||
|
│ │ │
|
||||||
|
└───────────────────────┼───────────────────────┘
|
||||||
|
│
|
||||||
|
ynov_network (réseau interne)
|
||||||
|
│
|
||||||
|
proxy_network (Traefik)
|
||||||
|
│
|
||||||
|
Internet
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📁 Structure des fichiers
|
||||||
|
|
||||||
|
```
|
||||||
|
/home/ynov/project/
|
||||||
|
├── docker-compose.yml # Orchestration globale
|
||||||
|
├── backend/
|
||||||
|
│ ├── Dockerfile # Build NestJS
|
||||||
|
│ ├── src/ # Code source
|
||||||
|
│ └── package.json # Dépendances
|
||||||
|
├── frontend/
|
||||||
|
│ └── frontend/
|
||||||
|
│ ├── Dockerfile # Build Flutter
|
||||||
|
│ ├── pubspec.yaml # Config Flutter
|
||||||
|
│ └── lib/ # Code source
|
||||||
|
└── database/
|
||||||
|
├── docker-compose.yml # Config spécifique DB
|
||||||
|
└── migrations/ # Scripts SQL
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔑 Credentials
|
||||||
|
|
||||||
|
### Base de données
|
||||||
|
- **Host** : `ynov-postgres` (interne) ou `localhost:5433` (externe)
|
||||||
|
- **User** : `admin`
|
||||||
|
- **Password** : `admin123`
|
||||||
|
- **Database** : `ptitpas_db`
|
||||||
|
|
||||||
|
### PgAdmin
|
||||||
|
- **Email** : `admin@ynov.local`
|
||||||
|
- **Password** : `admin123`
|
||||||
|
|
||||||
|
## 🚀 Commandes de déploiement
|
||||||
|
|
||||||
|
### Déploiement complet
|
||||||
|
```bash
|
||||||
|
cd /home/ynov/project
|
||||||
|
docker compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Déploiement par service
|
||||||
|
```bash
|
||||||
|
# Base de données seulement
|
||||||
|
docker compose up -d database pgadmin
|
||||||
|
|
||||||
|
# Backend seulement
|
||||||
|
docker compose up -d --build backend
|
||||||
|
|
||||||
|
# Frontend seulement
|
||||||
|
docker compose up -d --build frontend
|
||||||
|
```
|
||||||
|
|
||||||
|
### Monitoring
|
||||||
|
```bash
|
||||||
|
# Voir les logs
|
||||||
|
docker compose logs -f
|
||||||
|
|
||||||
|
# Statut des services
|
||||||
|
docker compose ps
|
||||||
|
|
||||||
|
# Redémarrer un service
|
||||||
|
docker compose restart backend
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 Configuration réseau
|
||||||
|
|
||||||
|
### Réseaux Docker
|
||||||
|
- **ynov_network** : Communication interne entre services
|
||||||
|
- **proxy_network** : Exposition via Traefik
|
||||||
|
|
||||||
|
### Priorités Traefik
|
||||||
|
- **Frontend** : Priority 10 (plus basse = défaut)
|
||||||
|
- **Backend** : Priority 20
|
||||||
|
- **PgAdmin** : Priority 30 (plus haute = prioritaire)
|
||||||
|
|
||||||
|
## 📝 Variables d'environnement
|
||||||
|
|
||||||
|
### Backend
|
||||||
|
- `DATABASE_URL` : Connexion PostgreSQL
|
||||||
|
- `NODE_ENV` : Mode production
|
||||||
|
|
||||||
|
### Frontend
|
||||||
|
- `API_URL` : URL de l'API backend
|
||||||
|
|
||||||
|
## 🔄 Webhooks de déploiement
|
||||||
|
|
||||||
|
### Repository Frontend
|
||||||
|
- **Trigger** : Push sur `main`
|
||||||
|
- **Action** : `docker compose up -d --build frontend`
|
||||||
|
|
||||||
|
### Repository Backend
|
||||||
|
- **Trigger** : Push sur `main`
|
||||||
|
- **Action** : `docker compose up -d --build backend`
|
||||||
|
|
||||||
|
### Repository Database
|
||||||
|
- **Trigger** : Push sur `main`
|
||||||
|
- **Action** : `docker compose up -d --build database`
|
||||||
|
|
||||||
|
## 🛠️ Dépannage
|
||||||
|
|
||||||
|
### Logs par service
|
||||||
|
```bash
|
||||||
|
docker compose logs frontend
|
||||||
|
docker compose logs backend
|
||||||
|
docker compose logs database
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rebuild complet
|
||||||
|
```bash
|
||||||
|
docker compose down
|
||||||
|
docker compose up -d --build --force-recreate
|
||||||
|
```
|
||||||
|
|
||||||
|
### Vérifier la connectivité réseau
|
||||||
|
```bash
|
||||||
|
docker network ls
|
||||||
|
docker network inspect project_ynov_network
|
||||||
|
```
|
||||||
100
docker-compose.yml
Normal file
100
docker-compose.yml
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
services:
|
||||||
|
# Base de données PostgreSQL
|
||||||
|
database:
|
||||||
|
image: postgres:17
|
||||||
|
container_name: ptitspas-postgres
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER}
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB}
|
||||||
|
volumes:
|
||||||
|
- ./database/migrations/01_init.sql:/docker-entrypoint-initdb.d/01_init.sql
|
||||||
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
networks:
|
||||||
|
- ptitspas_network
|
||||||
|
|
||||||
|
# Interface d'administration DB
|
||||||
|
pgadmin:
|
||||||
|
image: dpage/pgadmin4
|
||||||
|
container_name: ptitspas-pgadmin
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
|
||||||
|
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
|
||||||
|
SCRIPT_NAME: /pgadmin
|
||||||
|
depends_on:
|
||||||
|
- database
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.ptitspas-pgadmin.rule=Host(\"app.ptits-pas.fr\") && PathPrefix(\"/pgadmin\")"
|
||||||
|
- "traefik.http.routers.ptitspas-pgadmin.entrypoints=websecure"
|
||||||
|
- "traefik.http.routers.ptitspas-pgadmin.tls.certresolver=leresolver"
|
||||||
|
- "traefik.http.routers.ptitspas-pgadmin.priority=30"
|
||||||
|
- "traefik.http.services.ptitspas-pgadmin.loadbalancer.server.port=80"
|
||||||
|
networks:
|
||||||
|
- ptitspas_network
|
||||||
|
- proxy_network
|
||||||
|
|
||||||
|
# Backend NestJS
|
||||||
|
backend:
|
||||||
|
build:
|
||||||
|
context: ./backend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: ptitspas-backend
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_HOST: ${POSTGRES_HOST}
|
||||||
|
POSTGRES_PORT: ${POSTGRES_PORT}
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER}
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB}
|
||||||
|
API_PORT: ${API_PORT}
|
||||||
|
JWT_ACCESS_SECRET: ${JWT_ACCESS_SECRET}
|
||||||
|
JWT_ACCESS_EXPIRES: ${JWT_ACCESS_EXPIRES}
|
||||||
|
JWT_REFRESH_SECRET: ${JWT_REFRESH_SECRET}
|
||||||
|
JWT_REFRESH_EXPIRES: ${JWT_REFRESH_EXPIRES}
|
||||||
|
NODE_ENV: ${NODE_ENV}
|
||||||
|
depends_on:
|
||||||
|
- database
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.ptitspas-api.rule=Host(\"app.ptits-pas.fr\") && PathPrefix(\"/api\")"
|
||||||
|
- "traefik.http.routers.ptitspas-api.entrypoints=websecure"
|
||||||
|
- "traefik.http.routers.ptitspas-api.tls.certresolver=leresolver"
|
||||||
|
- "traefik.http.routers.ptitspas-api.priority=20"
|
||||||
|
- "traefik.http.services.ptitspas-api.loadbalancer.server.port=3000"
|
||||||
|
networks:
|
||||||
|
- ptitspas_network
|
||||||
|
- proxy_network
|
||||||
|
|
||||||
|
# Frontend Flutter
|
||||||
|
frontend:
|
||||||
|
build:
|
||||||
|
context: ./frontend
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: ptitspas-frontend
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
API_URL: ${API_URL}
|
||||||
|
depends_on:
|
||||||
|
- backend
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.ptitspas-front.rule=Host(\"app.ptits-pas.fr\")"
|
||||||
|
- "traefik.http.routers.ptitspas-front.entrypoints=websecure"
|
||||||
|
- "traefik.http.routers.ptitspas-front.tls.certresolver=leresolver"
|
||||||
|
- "traefik.http.routers.ptitspas-front.priority=10"
|
||||||
|
- "traefik.http.services.ptitspas-front.loadbalancer.server.port=80"
|
||||||
|
networks:
|
||||||
|
- ptitspas_network
|
||||||
|
- proxy_network
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
ptitspas_network:
|
||||||
|
driver: bridge
|
||||||
|
proxy_network:
|
||||||
|
external: true
|
||||||
Loading…
x
Reference in New Issue
Block a user