forked from Ynov/ptitspas-ynov-back
✨ Ajout configuration développement local
- docker-compose.dev.yml : Stack complète (Postgres + Backend + PgAdmin) - .env.example : Variables pour développement local - README-DEV.md : Guide développeur complet - Dockerfile : Configuration Docker backend - Correction dependencies package.json (typeorm, class-validator) - Hot reload configuré pour développement
This commit is contained in:
parent
b75034739c
commit
95459871f2
22
.env.example
22
.env.example
@ -1,15 +1,23 @@
|
|||||||
# Fichier: .env.example
|
# Fichier: .env.example
|
||||||
|
# Copier ce fichier vers .env et adapter les valeurs selon votre environnement
|
||||||
|
|
||||||
# Configuration de la base de données PostgreSQL
|
# Configuration de la base de données PostgreSQL
|
||||||
POSTGRES_HOST=
|
POSTGRES_HOST=postgres
|
||||||
POSTGRES_PORT=
|
POSTGRES_PORT=5432
|
||||||
POSTGRES_USER=
|
POSTGRES_USER=admin
|
||||||
POSTGRES_PASSWORD=
|
POSTGRES_PASSWORD=admin123
|
||||||
POSTGRES_DB=
|
POSTGRES_DB=ptitpas_db
|
||||||
|
|
||||||
|
# Configuration PgAdmin (accessible sur http://localhost:8080)
|
||||||
|
PGADMIN_DEFAULT_EMAIL=admin@localhost
|
||||||
|
PGADMIN_DEFAULT_PASSWORD=admin123
|
||||||
|
|
||||||
# Configuration de l'API
|
# Configuration de l'API
|
||||||
API_PORT=3000
|
API_PORT=3000
|
||||||
|
|
||||||
# Secrets pour l'authentification JWT
|
# Secrets pour l'authentification JWT
|
||||||
JWT_SECRET=
|
JWT_SECRET=dev-jwt-secret-key-change-me
|
||||||
JWT_EXPIRATION_TIME=
|
JWT_EXPIRATION_TIME=7d
|
||||||
|
|
||||||
|
# Environnement
|
||||||
|
NODE_ENV=development
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -54,3 +54,4 @@ pids
|
|||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
.env
|
||||||
|
|||||||
39
Dockerfile
Normal file
39
Dockerfile
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
FROM node:18-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copier les fichiers de configuration
|
||||||
|
COPY package*.json ./
|
||||||
|
COPY tsconfig*.json ./
|
||||||
|
COPY nest-cli.json ./
|
||||||
|
|
||||||
|
# Installer TOUTES les dépendances (dev + prod pour le build)
|
||||||
|
RUN npm install && npm cache clean --force
|
||||||
|
|
||||||
|
# Copier le code source
|
||||||
|
COPY src ./src
|
||||||
|
|
||||||
|
# Builder l'application
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Stage production
|
||||||
|
FROM node:18-alpine AS production
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Installer seulement les dépendances de production
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install --only=production && npm cache clean --force
|
||||||
|
|
||||||
|
# Copier le build depuis le stage builder
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
|
|
||||||
|
# Créer un utilisateur non-root
|
||||||
|
RUN addgroup -g 1001 -S nodejs
|
||||||
|
RUN adduser -S nestjs -u 1001
|
||||||
|
|
||||||
|
USER nestjs
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["node", "dist/main"]
|
||||||
63
README-DEV.md
Normal file
63
README-DEV.md
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# 🚀 Guide de développement local
|
||||||
|
|
||||||
|
## Prérequis
|
||||||
|
- Docker et Docker Compose installés
|
||||||
|
- Git
|
||||||
|
|
||||||
|
## 🏃♂️ Démarrage rapide
|
||||||
|
|
||||||
|
### 1. Cloner le projet
|
||||||
|
```bash
|
||||||
|
git clone <url-du-depot-backend>
|
||||||
|
cd ptitspas-backend
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Configuration de l'environnement
|
||||||
|
```bash
|
||||||
|
# Copier le fichier d'exemple
|
||||||
|
cp .env.example .env
|
||||||
|
|
||||||
|
# Optionnel : adapter les valeurs dans .env selon vos besoins
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Lancer l'application
|
||||||
|
```bash
|
||||||
|
# Démarrer tous les services (PostgreSQL + PgAdmin + Backend)
|
||||||
|
docker compose -f docker-compose.dev.yml up -d
|
||||||
|
|
||||||
|
# Voir les logs
|
||||||
|
docker compose -f docker-compose.dev.yml logs -f
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🌐 Accès aux services
|
||||||
|
|
||||||
|
- **Backend API** : http://localhost:3000
|
||||||
|
- **PgAdmin** : http://localhost:8080
|
||||||
|
- Email : admin@localhost
|
||||||
|
- Mot de passe : admin123
|
||||||
|
- **PostgreSQL** : localhost:5432
|
||||||
|
- Utilisateur : admin
|
||||||
|
- Mot de passe : admin123
|
||||||
|
- Base : ptitpas_db
|
||||||
|
|
||||||
|
## 🛠️ Commandes utiles
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Arrêter les services
|
||||||
|
docker compose -f docker-compose.dev.yml down
|
||||||
|
|
||||||
|
# Rebuild le backend après modification du Dockerfile
|
||||||
|
docker compose -f docker-compose.dev.yml up --build backend
|
||||||
|
|
||||||
|
# Voir l'état des services
|
||||||
|
docker compose -f docker-compose.dev.yml ps
|
||||||
|
|
||||||
|
# Accéder au container backend
|
||||||
|
docker exec -it ptitspas-backend-dev sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📝 Notes de développement
|
||||||
|
|
||||||
|
- Les modifications du code source sont automatiquement prises en compte (hot reload)
|
||||||
|
- Les données PostgreSQL sont persistantes via le volume `postgres_dev_data`
|
||||||
|
- Le fichier `.env` n'est pas versionné pour des raisons de sécurité
|
||||||
71
docker-compose.dev.yml
Normal file
71
docker-compose.dev.yml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# Docker Compose pour développement local
|
||||||
|
# Usage: docker compose -f docker-compose.dev.yml up -d
|
||||||
|
|
||||||
|
services:
|
||||||
|
# Base de données PostgreSQL
|
||||||
|
postgres:
|
||||||
|
image: postgres:17
|
||||||
|
container_name: ptitspas-postgres-dev
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER:-admin}
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-admin123}
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB:-ptitpas_db}
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
volumes:
|
||||||
|
- postgres_dev_data:/var/lib/postgresql/data
|
||||||
|
# Si le fichier d'init existe dans le dépôt database
|
||||||
|
# - ../database/migrations/01_init.sql:/docker-entrypoint-initdb.d/01_init.sql
|
||||||
|
networks:
|
||||||
|
- ptitspas_dev
|
||||||
|
|
||||||
|
# Interface d'administration DB
|
||||||
|
pgadmin:
|
||||||
|
image: dpage/pgadmin4
|
||||||
|
container_name: ptitspas-pgadmin-dev
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-admin@localhost}
|
||||||
|
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin123}
|
||||||
|
ports:
|
||||||
|
- "8080:80"
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
||||||
|
networks:
|
||||||
|
- ptitspas_dev
|
||||||
|
|
||||||
|
# Backend NestJS
|
||||||
|
backend:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: ptitspas-backend-dev
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_HOST: ${POSTGRES_HOST:-postgres}
|
||||||
|
POSTGRES_PORT: ${POSTGRES_PORT:-5432}
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER:-admin}
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-admin123}
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB:-ptitpas_db}
|
||||||
|
API_PORT: ${API_PORT:-3000}
|
||||||
|
JWT_SECRET: ${JWT_SECRET:-dev-jwt-secret-key}
|
||||||
|
JWT_EXPIRATION_TIME: ${JWT_EXPIRATION_TIME:-7d}
|
||||||
|
NODE_ENV: ${NODE_ENV:-development}
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
||||||
|
volumes:
|
||||||
|
# Pour le hot reload en développement
|
||||||
|
- ./src:/app/src
|
||||||
|
- /app/node_modules
|
||||||
|
networks:
|
||||||
|
- ptitspas_dev
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_dev_data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
ptitspas_dev:
|
||||||
|
driver: bridge
|
||||||
10391
package-lock.json
generated
10391
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -25,8 +25,10 @@
|
|||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.0.1",
|
||||||
"@nestjs/platform-express": "^11.0.1",
|
"@nestjs/platform-express": "^11.0.1",
|
||||||
"joi": "^18.0.0",
|
"joi": "^18.0.0",
|
||||||
|
"class-validator": "^0.14.0",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"rxjs": "^7.8.1"
|
"rxjs": "^7.8.1",
|
||||||
|
"typeorm": "^0.3.17"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@eslint/eslintrc": "^3.2.0",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user