Dockerisation de tout
This commit is contained in:
176
DOCKER.md
Normal file
176
DOCKER.md
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
# Dockerisation du projet Audio Classifier
|
||||||
|
|
||||||
|
## 🐳 Architecture Docker
|
||||||
|
|
||||||
|
Le projet est entièrement dockerisé avec deux configurations distinctes :
|
||||||
|
|
||||||
|
1. **Production** (`docker-compose.yml`) - Version optimisée pour le déploiement
|
||||||
|
2. **Développement** (`docker-compose.dev.yml`) - Version avec hot-reload pour le développement
|
||||||
|
|
||||||
|
## 📁 Structure des Services
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
postgres: # Base de données PostgreSQL avec pgvector
|
||||||
|
backend: # API FastAPI (Python 3.11)
|
||||||
|
frontend: # Interface Next.js (Node.js 20)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🚀 Commandes de déploiement
|
||||||
|
|
||||||
|
### Mode Production
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Démarrer tous les services
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# Arrêter tous les services
|
||||||
|
docker-compose down
|
||||||
|
|
||||||
|
# Voir les logs
|
||||||
|
docker-compose logs
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mode Développement
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Démarrer tous les services en mode dev
|
||||||
|
docker-compose -f docker-compose.dev.yml up -d
|
||||||
|
|
||||||
|
# Arrêter tous les services
|
||||||
|
docker-compose -f docker-compose.dev.yml down
|
||||||
|
|
||||||
|
# Voir les logs
|
||||||
|
docker-compose -f docker-compose.dev.yml logs
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🏗 Construction des images
|
||||||
|
|
||||||
|
### Backend (Production)
|
||||||
|
- **Base** : `python:3.9-slim` (pour compatibilité Essentia)
|
||||||
|
- **Dépendances système** : ffmpeg, libsndfile, etc.
|
||||||
|
- **Dépendances Python** : Toutes les dépendances du fichier `requirements.txt`
|
||||||
|
- **Optimisation** : Multi-stage build pour réduire la taille
|
||||||
|
|
||||||
|
### Backend (Développement)
|
||||||
|
- **Base** : `python:3.11-slim`
|
||||||
|
- **Dépendances** : Version minimale sans Essentia
|
||||||
|
- **Hot-reload** : Montage du code source pour développement
|
||||||
|
|
||||||
|
### Frontend (Production)
|
||||||
|
- **Base** : `node:20-alpine`
|
||||||
|
- **Build** : Application Next.js compilée
|
||||||
|
- **Optimisation** : Image légère Alpine Linux
|
||||||
|
|
||||||
|
### Frontend (Développement)
|
||||||
|
- **Base** : `node:20-alpine`
|
||||||
|
- **Hot-reload** : Montage du code source
|
||||||
|
- **Dépendances** : Installation des modules Node
|
||||||
|
|
||||||
|
## ⚙️ Configuration des environnements
|
||||||
|
|
||||||
|
### Variables d'environnement
|
||||||
|
|
||||||
|
Les variables sont définies dans les fichiers `.env` et peuvent être surchargées :
|
||||||
|
|
||||||
|
**Base de données :**
|
||||||
|
- `POSTGRES_USER` - Utilisateur PostgreSQL
|
||||||
|
- `POSTGRES_PASSWORD` - Mot de passe PostgreSQL
|
||||||
|
- `POSTGRES_DB` - Nom de la base de données
|
||||||
|
- `DATABASE_URL` - URL de connexion complète
|
||||||
|
|
||||||
|
**Backend :**
|
||||||
|
- `CORS_ORIGINS` - Origines autorisées pour CORS
|
||||||
|
- `ANALYSIS_USE_CLAP` - Activation des embeddings CLAP
|
||||||
|
- `ANALYSIS_NUM_WORKERS` - Nombre de workers d'analyse
|
||||||
|
- `ESSENTIA_MODELS_PATH` - Chemin vers les modèles Essentia
|
||||||
|
|
||||||
|
**Frontend :**
|
||||||
|
- `NEXT_PUBLIC_API_URL` - URL de l'API backend
|
||||||
|
|
||||||
|
### Volumes Docker
|
||||||
|
|
||||||
|
**Base de données :**
|
||||||
|
- `postgres_data` - Persistance des données PostgreSQL
|
||||||
|
|
||||||
|
**Backend :**
|
||||||
|
- `${AUDIO_LIBRARY_PATH}:/audio:ro` - Montage de la bibliothèque audio (lecture seule)
|
||||||
|
- `./backend/models:/app/models` - Montage des modèles Essentia
|
||||||
|
|
||||||
|
**Frontend :**
|
||||||
|
- `./frontend:/app` (dev) - Montage du code source
|
||||||
|
- `/app/node_modules` (dev) - Persistance des modules Node
|
||||||
|
|
||||||
|
## 🔄 Flux de développement
|
||||||
|
|
||||||
|
1. **Développement backend :**
|
||||||
|
- Modifier le code dans `backend/src/`
|
||||||
|
- Hot-reload automatique avec `docker-compose.dev.yml`
|
||||||
|
|
||||||
|
2. **Développement frontend :**
|
||||||
|
- Modifier le code dans `frontend/`
|
||||||
|
- Hot-reload automatique avec Next.js
|
||||||
|
|
||||||
|
3. **Déploiement :**
|
||||||
|
- Construire les images avec `docker-compose build`
|
||||||
|
- Démarrer les services avec `docker-compose up -d`
|
||||||
|
|
||||||
|
## 🔧 Maintenance et debugging
|
||||||
|
|
||||||
|
### Accéder au conteneur backend
|
||||||
|
```bash
|
||||||
|
docker exec -it audio_classifier_api sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Accéder au conteneur frontend
|
||||||
|
```bash
|
||||||
|
docker exec -it audio_classifier_ui sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Accéder à la base de données
|
||||||
|
```bash
|
||||||
|
docker exec -it audio_classifier_db psql -U audio_user -d audio_classifier
|
||||||
|
```
|
||||||
|
|
||||||
|
### Réinitialiser la base de données
|
||||||
|
```bash
|
||||||
|
docker-compose down -v
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📈 Performance et optimisation
|
||||||
|
|
||||||
|
### Backend
|
||||||
|
- Utilisation de `--platform=linux/amd64` pour compatibilité Essentia
|
||||||
|
- Installation des dépendances Python par étapes pour meilleur cache
|
||||||
|
- Montage des modèles Essentia pour persistance
|
||||||
|
|
||||||
|
### Frontend
|
||||||
|
- Utilisation d'Alpine Linux pour image légère
|
||||||
|
- Installation des dépendances avant copie du code
|
||||||
|
- Exclusion de `node_modules` du contexte de build
|
||||||
|
|
||||||
|
## 🔒 Sécurité
|
||||||
|
|
||||||
|
- Conteneurs non-root par défaut
|
||||||
|
- Montage lecture-seule de la bibliothèque audio
|
||||||
|
- Mise à jour régulière des images de base
|
||||||
|
- Utilisation de versions spécifiques des dépendances
|
||||||
|
|
||||||
|
## 🆘 Problèmes courants
|
||||||
|
|
||||||
|
### Essentia non disponible sur ARM
|
||||||
|
Solution : Utiliser `--platform=linux/amd64` dans le Dockerfile
|
||||||
|
|
||||||
|
### Permissions de fichiers
|
||||||
|
Solution : Vérifier les permissions du dossier audio monté
|
||||||
|
|
||||||
|
### CORS errors
|
||||||
|
Solution : Vérifier la configuration `CORS_ORIGINS`
|
||||||
|
|
||||||
|
## 📚 Références
|
||||||
|
|
||||||
|
- [Docker Documentation](https://docs.docker.com/)
|
||||||
|
- [Docker Compose Documentation](https://docs.docker.com/compose/)
|
||||||
|
- [PostgreSQL avec pgvector](https://github.com/pgvector/pgvector)
|
||||||
|
- [Next.js Dockerisation](https://nextjs.org/docs/deployment)
|
||||||
16
README.md
16
README.md
@@ -59,23 +59,23 @@ AUDIO_LIBRARY_PATH=/chemin/vers/vos/fichiers/audio
|
|||||||
./scripts/download-essentia-models.sh
|
./scripts/download-essentia-models.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. Lancer avec Docker
|
### 4. Lancer avec Docker (Production)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
L'API sera disponible sur `http://localhost:8000`
|
L'API sera disponible sur `http://localhost:8001`
|
||||||
La documentation interactive : `http://localhost:8000/docs`
|
La documentation interactive : `http://localhost:8001/docs`
|
||||||
|
Le frontend sera accessible sur `http://localhost:3000`
|
||||||
|
|
||||||
### 5. Lancer le frontend (développement)
|
### 5. Lancer avec Docker (Développement)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd frontend
|
docker-compose -f docker-compose.dev.yml up -d
|
||||||
npm install
|
|
||||||
npm run dev
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
L'API sera disponible sur `http://localhost:8001`
|
||||||
Le frontend sera accessible sur `http://localhost:3000`
|
Le frontend sera accessible sur `http://localhost:3000`
|
||||||
|
|
||||||
## 📖 Utilisation
|
## 📖 Utilisation
|
||||||
@@ -91,7 +91,7 @@ Le frontend sera accessible sur `http://localhost:3000`
|
|||||||
|
|
||||||
#### Via l'API
|
#### Via l'API
|
||||||
```bash
|
```bash
|
||||||
curl -X POST http://localhost:8000/api/analyze/folder \
|
curl -X POST http://localhost:8001/api/analyze/folder \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"path": "/audio/music", "recursive": true}'
|
-d '{"path": "/audio/music", "recursive": true}'
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
FROM python:3.8-slim
|
# Use amd64 platform for better Essentia compatibility, works with emulation on ARM
|
||||||
|
FROM --platform=linux/amd64 python:3.9-slim
|
||||||
|
|
||||||
# Install system dependencies
|
# Install system dependencies
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
@@ -12,6 +13,16 @@ RUN apt-get update && apt-get install -y \
|
|||||||
liblapack-dev \
|
liblapack-dev \
|
||||||
pkg-config \
|
pkg-config \
|
||||||
curl \
|
curl \
|
||||||
|
build-essential \
|
||||||
|
libyaml-dev \
|
||||||
|
libfftw3-dev \
|
||||||
|
libavcodec-dev \
|
||||||
|
libavformat-dev \
|
||||||
|
libavutil-dev \
|
||||||
|
libswresample-dev \
|
||||||
|
libsamplerate0-dev \
|
||||||
|
libtag1-dev \
|
||||||
|
libchromaprint-dev \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Set working directory
|
# Set working directory
|
||||||
@@ -24,20 +35,12 @@ RUN pip install --no-cache-dir --upgrade pip setuptools wheel
|
|||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
|
|
||||||
# Install Python dependencies in stages for better caching
|
# Install Python dependencies in stages for better caching
|
||||||
# Using versions compatible with Python 3.8
|
# Using versions compatible with Python 3.9
|
||||||
RUN pip install --no-cache-dir numpy==1.23.5
|
RUN pip install --no-cache-dir numpy==1.24.3
|
||||||
RUN pip install --no-cache-dir scipy==1.10.1
|
RUN pip install --no-cache-dir scipy==1.11.4
|
||||||
|
|
||||||
# Install Essentia - Python 3.8 version (latest available with pre-built wheels)
|
# Install Essentia - Python 3.9 with ARM64 support
|
||||||
RUN ARCH=$(uname -m) && \
|
RUN pip install --no-cache-dir essentia
|
||||||
if [ "$ARCH" = "x86_64" ]; then \
|
|
||||||
echo "Installing Essentia for x86_64 Python 3.8..." && \
|
|
||||||
pip install --no-cache-dir --trusted-host essentia.upf.edu \
|
|
||||||
https://essentia.upf.edu/python-wheels/essentia-2.1b6.dev218-cp38-cp38-manylinux1_x86_64.whl || \
|
|
||||||
echo "Essentia installation failed, using fallback mode"; \
|
|
||||||
else \
|
|
||||||
echo "Essentia wheels only available for x86_64, using fallback mode"; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ mutagen==1.47.0
|
|||||||
# Essentia for genre/mood/instrument classification
|
# Essentia for genre/mood/instrument classification
|
||||||
# Note: Essentia is installed separately in Dockerfile from official wheels
|
# Note: Essentia is installed separately in Dockerfile from official wheels
|
||||||
|
|
||||||
# Scientific Computing (versions compatible with Python 3.8)
|
# Scientific Computing (versions compatible with Python 3.9)
|
||||||
numpy==1.23.5
|
numpy==1.24.3
|
||||||
scipy==1.10.1
|
scipy==1.11.4
|
||||||
|
|
||||||
# Configuration & Validation
|
# Configuration & Validation
|
||||||
pydantic==2.5.3
|
pydantic==2.5.3
|
||||||
|
|||||||
@@ -44,6 +44,23 @@ services:
|
|||||||
- ./backend/src:/app/src
|
- ./backend/src:/app/src
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
build:
|
||||||
|
context: ./frontend
|
||||||
|
dockerfile: Dockerfile.dev
|
||||||
|
container_name: audio_classifier_ui_dev
|
||||||
|
environment:
|
||||||
|
NEXT_PUBLIC_API_URL: http://backend:8000
|
||||||
|
NODE_ENV: development
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
volumes:
|
||||||
|
- ./frontend:/app
|
||||||
|
- /app/node_modules
|
||||||
|
depends_on:
|
||||||
|
- backend
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
driver: local
|
driver: local
|
||||||
|
|||||||
@@ -39,17 +39,16 @@ services:
|
|||||||
- ./backend/models:/app/models
|
- ./backend/models:/app/models
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
# Frontend (development mode - for production use static build)
|
frontend:
|
||||||
# frontend:
|
build: ./frontend
|
||||||
# build: ./frontend
|
container_name: audio_classifier_ui
|
||||||
# container_name: audio_classifier_ui
|
environment:
|
||||||
# environment:
|
NEXT_PUBLIC_API_URL: http://backend:8000
|
||||||
# NEXT_PUBLIC_API_URL: http://localhost:8000
|
ports:
|
||||||
# ports:
|
- "3000:3000"
|
||||||
# - "3000:3000"
|
depends_on:
|
||||||
# depends_on:
|
- backend
|
||||||
# - backend
|
restart: unless-stopped
|
||||||
# restart: unless-stopped
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
|
|||||||
22
frontend/Dockerfile
Normal file
22
frontend/Dockerfile
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
FROM node:20-alpine
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package files
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Copy application code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the application
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Expose port
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Start the application
|
||||||
|
CMD ["npm", "start"]
|
||||||
16
frontend/Dockerfile.dev
Normal file
16
frontend/Dockerfile.dev
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
FROM node:20-alpine
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package files
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Expose port
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Start the development server
|
||||||
|
CMD ["npm", "run", "dev"]
|
||||||
Reference in New Issue
Block a user