Update .gitignore to exclude local database files and enhance README with Docker deployment instructions and examples for file uploads.
Some checks failed
Docker Build / build (push) Has been cancelled
Some checks failed
Docker Build / build (push) Has been cancelled
This commit is contained in:
parent
8d6ae6291e
commit
89da43b706
46
.dockerignore
Normal file
46
.dockerignore
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# Git
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# Python
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
*.so
|
||||||
|
.Python
|
||||||
|
*.egg-info/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Environnement virtuel
|
||||||
|
venv/
|
||||||
|
env/
|
||||||
|
ENV/
|
||||||
|
.venv/
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
Dockerfile
|
||||||
|
docker-compose.yml
|
||||||
|
.dockerignore
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
README.md
|
||||||
|
.cursor/
|
||||||
|
|
||||||
|
# Fichiers de configuration locaux
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
34
.github/workflows/docker-build.yml
vendored
Normal file
34
.github/workflows/docker-build.yml
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Workflow CI/CD pour construire et tester l'image Docker
|
||||||
|
name: Docker Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main, master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
- name: Build Docker image
|
||||||
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: false
|
||||||
|
tags: pynextcloud-api:latest
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
- name: Test image
|
||||||
|
run: |
|
||||||
|
docker images
|
||||||
|
echo "✅ Image Docker construite avec succès"
|
||||||
|
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,6 +1,11 @@
|
|||||||
# Fichiers de configuration sensibles
|
# Fichiers de configuration sensibles
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
# Base de données locale (si jamais créée)
|
||||||
|
*.db
|
||||||
|
*.sqlite
|
||||||
|
*.sqlite3
|
||||||
|
|
||||||
# Environnement virtuel Python
|
# Environnement virtuel Python
|
||||||
venv/
|
venv/
|
||||||
env/
|
env/
|
||||||
|
|||||||
83
COOLIFY.md
Normal file
83
COOLIFY.md
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
# 🚀 Guide de déploiement Coolify
|
||||||
|
|
||||||
|
## Configuration rapide
|
||||||
|
|
||||||
|
### 1. Variables d'environnement requises
|
||||||
|
|
||||||
|
Dans Coolify, ajoutez ces variables d'environnement :
|
||||||
|
|
||||||
|
```env
|
||||||
|
NEXTCLOUD_URL=https://votre-serveur-nextcloud.com
|
||||||
|
NEXTCLOUD_USERNAME=votre_username
|
||||||
|
NEXTCLOUD_PASSWORD=votre_password
|
||||||
|
APP_HOST=0.0.0.0
|
||||||
|
APP_PORT=8000
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Configuration du projet
|
||||||
|
|
||||||
|
- **Build Pack** : Dockerfile
|
||||||
|
- **Port** : 8000
|
||||||
|
- **Health Check Path** : `/health`
|
||||||
|
- **Health Check Interval** : 30s
|
||||||
|
|
||||||
|
### 3. Déploiement automatique
|
||||||
|
|
||||||
|
Coolify détectera automatiquement :
|
||||||
|
- ✅ `Dockerfile` pour construire l'image
|
||||||
|
- ✅ `docker-compose.yml` pour la configuration
|
||||||
|
- ✅ Health check configuré
|
||||||
|
|
||||||
|
### 4. Branches et CI/CD
|
||||||
|
|
||||||
|
- **Branche principale** : `main` ou `master`
|
||||||
|
- **Auto-deploy** : Activez le déploiement automatique sur push
|
||||||
|
- **Build automatique** : Coolify construira l'image à chaque push
|
||||||
|
|
||||||
|
### 5. Vérification du déploiement
|
||||||
|
|
||||||
|
Après le déploiement, testez ces endpoints :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Health check
|
||||||
|
curl https://votre-domaine.com/health
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
https://votre-domaine.com/docs
|
||||||
|
|
||||||
|
# Liste des routes
|
||||||
|
curl https://votre-domaine.com/debug/routes
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. Logs et monitoring
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Dans Coolify, accédez aux logs via l'interface
|
||||||
|
# Ou utilisez la commande Docker :
|
||||||
|
docker logs -f <container_name>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Le conteneur ne démarre pas
|
||||||
|
- Vérifiez que toutes les variables d'environnement sont définies
|
||||||
|
- Consultez les logs du build dans Coolify
|
||||||
|
- Vérifiez que le port 8000 n'est pas déjà utilisé
|
||||||
|
|
||||||
|
### Health check échoue
|
||||||
|
- Attendez 40 secondes (start_period) après le démarrage
|
||||||
|
- Vérifiez que l'endpoint `/health` répond
|
||||||
|
- Consultez les logs de l'application
|
||||||
|
|
||||||
|
### Erreurs de connexion Nextcloud
|
||||||
|
- Vérifiez l'URL de votre serveur Nextcloud
|
||||||
|
- Testez les identifiants manuellement
|
||||||
|
- Assurez-vous que le serveur Nextcloud est accessible depuis le conteneur
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
Pour toute question, consultez :
|
||||||
|
- [Documentation Coolify](https://coolify.io/docs)
|
||||||
|
- Les logs de l'application dans Coolify
|
||||||
|
- L'endpoint `/debug/routes` pour vérifier les routes disponibles
|
||||||
|
|
||||||
26
Dockerfile
Normal file
26
Dockerfile
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Utiliser une image Python officielle
|
||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
# Définir le répertoire de travail
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copier les fichiers de dépendances
|
||||||
|
COPY requirements.txt .
|
||||||
|
|
||||||
|
# Installer les dépendances
|
||||||
|
RUN pip install --no-cache-dir --upgrade pip && \
|
||||||
|
pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Copier le code de l'application
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Exposer le port de l'application
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
# Variable d'environnement pour Python (éviter les .pyc et buffer stdout/stderr)
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
|
PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
# Commande pour lancer l'application
|
||||||
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
|
|
||||||
99
README.md
99
README.md
@ -65,6 +65,69 @@ Une fois le serveur démarré, accédez à :
|
|||||||
- Documentation Swagger UI : `http://localhost:8000/docs`
|
- Documentation Swagger UI : `http://localhost:8000/docs`
|
||||||
- Documentation ReDoc : `http://localhost:8000/redoc`
|
- Documentation ReDoc : `http://localhost:8000/redoc`
|
||||||
|
|
||||||
|
## 🐳 Déploiement avec Docker
|
||||||
|
|
||||||
|
### Avec Docker Compose (Local)
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 1. Assurez-vous que le fichier .env est configuré
|
||||||
|
Copy-Item env.example .env
|
||||||
|
notepad .env
|
||||||
|
|
||||||
|
# 2. Construire et lancer le conteneur
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# 3. Voir les logs
|
||||||
|
docker-compose logs -f
|
||||||
|
|
||||||
|
# 4. Arrêter le conteneur
|
||||||
|
docker-compose down
|
||||||
|
```
|
||||||
|
|
||||||
|
L'API sera accessible sur `http://localhost:8000`
|
||||||
|
|
||||||
|
### Déploiement sur Coolify 🚀
|
||||||
|
|
||||||
|
**Configuration Coolify :**
|
||||||
|
|
||||||
|
1. **Connectez votre repository Git** à Coolify
|
||||||
|
|
||||||
|
2. **Variables d'environnement à définir dans Coolify :**
|
||||||
|
```
|
||||||
|
NEXTCLOUD_URL=https://votre-serveur-nextcloud.com
|
||||||
|
NEXTCLOUD_USERNAME=votre_username
|
||||||
|
NEXTCLOUD_PASSWORD=votre_password
|
||||||
|
APP_HOST=0.0.0.0
|
||||||
|
APP_PORT=8000
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Coolify détectera automatiquement** le `Dockerfile` et le `docker-compose.yml`
|
||||||
|
|
||||||
|
4. **Port à exposer :** 8000
|
||||||
|
|
||||||
|
5. **Health check :** `/health` (déjà configuré dans le docker-compose.yml)
|
||||||
|
|
||||||
|
**Build automatique :**
|
||||||
|
- Coolify construira automatiquement l'image à chaque push sur la branche configurée
|
||||||
|
- Le conteneur redémarrera automatiquement en cas d'échec grâce au health check
|
||||||
|
|
||||||
|
### Construire l'image Docker manuellement
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# Construire l'image
|
||||||
|
docker build -t pynextcloud-api .
|
||||||
|
|
||||||
|
# Lancer le conteneur
|
||||||
|
docker run -d \
|
||||||
|
-p 8000:8000 \
|
||||||
|
--env-file .env \
|
||||||
|
--name pynextcloud \
|
||||||
|
pynextcloud-api
|
||||||
|
|
||||||
|
# Voir les logs
|
||||||
|
docker logs -f pynextcloud
|
||||||
|
```
|
||||||
|
|
||||||
## 📡 Endpoints disponibles
|
## 📡 Endpoints disponibles
|
||||||
|
|
||||||
### 1. Route racine
|
### 1. Route racine
|
||||||
@ -158,13 +221,13 @@ POST /upload
|
|||||||
Upload un fichier vers un dossier Nextcloud.
|
Upload un fichier vers un dossier Nextcloud.
|
||||||
|
|
||||||
**Paramètres (form-data) :**
|
**Paramètres (form-data) :**
|
||||||
- `file` : Le fichier à uploader
|
- `file` : Le fichier à uploader **(requis)**
|
||||||
- `path` : Chemin du dossier de destination (ex: `/Documents`)
|
- `path` : Chemin du dossier de destination (ex: `/Documents`) **(requis)**
|
||||||
- `filename` : Nom du fichier (optionnel, utilise le nom original si non spécifié)
|
- `filename` : Nom du fichier (optionnel, utilise le nom original si non spécifié)
|
||||||
|
|
||||||
**Exemples :**
|
**Exemples :**
|
||||||
```powershell
|
```powershell
|
||||||
# Upload un fichier avec PowerShell
|
# Upload simple
|
||||||
$file = Get-Item "C:\chemin\vers\monfichier.pdf"
|
$file = Get-Item "C:\chemin\vers\monfichier.pdf"
|
||||||
$form = @{
|
$form = @{
|
||||||
file = $file
|
file = $file
|
||||||
@ -172,23 +235,34 @@ $form = @{
|
|||||||
}
|
}
|
||||||
Invoke-WebRequest -Uri "http://localhost:8000/upload" -Method POST -Form $form
|
Invoke-WebRequest -Uri "http://localhost:8000/upload" -Method POST -Form $form
|
||||||
|
|
||||||
# Upload avec un nom personnalisé
|
# Upload avec renommage
|
||||||
$form = @{
|
$form = @{
|
||||||
file = Get-Item "C:\chemin\vers\monfichier.pdf"
|
file = Get-Item "C:\chemin\vers\rapport.pdf"
|
||||||
path = "/Documents"
|
path = "/Documents/Projets"
|
||||||
filename = "nouveau_nom.pdf"
|
filename = "rapport_annuel_2025.pdf"
|
||||||
}
|
}
|
||||||
Invoke-WebRequest -Uri "http://localhost:8000/upload" -Method POST -Form $form
|
Invoke-WebRequest -Uri "http://localhost:8000/upload" -Method POST -Form $form
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Dans Postman :**
|
||||||
|
- Method: **POST**
|
||||||
|
- URL: `http://localhost:8000/upload`
|
||||||
|
- Body: **form-data**
|
||||||
|
|
||||||
|
| Key | Type | Value |
|
||||||
|
|-----|------|-------|
|
||||||
|
| file | File | *[Sélectionnez votre fichier]* |
|
||||||
|
| path | Text | /Documents |
|
||||||
|
| filename | Text | mon_fichier.pdf *(optionnel)* |
|
||||||
|
|
||||||
**Réponse exemple :**
|
**Réponse exemple :**
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"success": true,
|
"success": true,
|
||||||
"message": "Fichier uploadé avec succès",
|
"message": "Fichier uploadé avec succès",
|
||||||
"file": {
|
"file": {
|
||||||
"name": "rapport.pdf",
|
"name": "rapport_annuel_2025.pdf",
|
||||||
"path": "/Documents/rapport.pdf",
|
"path": "/Documents/Projets/rapport_annuel_2025.pdf",
|
||||||
"size": 1024567,
|
"size": 1024567,
|
||||||
"content_type": "application/pdf"
|
"content_type": "application/pdf"
|
||||||
}
|
}
|
||||||
@ -209,10 +283,15 @@ PyNextcloud/
|
|||||||
│ ├── health.py # Health check
|
│ ├── health.py # Health check
|
||||||
│ ├── list.py # Lister les fichiers/dossiers
|
│ ├── list.py # Lister les fichiers/dossiers
|
||||||
│ ├── info.py # Informations d'un fichier/dossier
|
│ ├── info.py # Informations d'un fichier/dossier
|
||||||
│ └── upload.py # Upload de fichiers
|
│ ├── upload.py # Upload de fichiers
|
||||||
|
│ └── debug.py # Routes de débogage
|
||||||
├── requirements.txt # Dépendances Python
|
├── requirements.txt # Dépendances Python
|
||||||
├── env.example # Exemple de fichier de configuration
|
├── env.example # Exemple de fichier de configuration
|
||||||
├── .env # Configuration (à créer, non versionné)
|
├── .env # Configuration (à créer, non versionné)
|
||||||
|
├── Dockerfile # 🐳 Image Docker
|
||||||
|
├── docker-compose.yml # 🐳 Configuration Docker Compose
|
||||||
|
├── .dockerignore # Fichiers à ignorer pour Docker
|
||||||
|
├── .gitignore # Fichiers à ignorer pour Git
|
||||||
└── README.md # Ce fichier
|
└── README.md # Ce fichier
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
32
docker-compose.yml
Normal file
32
docker-compose.yml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
pynextcloud:
|
||||||
|
build: .
|
||||||
|
container_name: pynextcloud-api
|
||||||
|
ports:
|
||||||
|
- "${APP_PORT:-8000}:8000"
|
||||||
|
environment:
|
||||||
|
# Configuration Nextcloud (à définir dans .env)
|
||||||
|
- NEXTCLOUD_URL=${NEXTCLOUD_URL}
|
||||||
|
- NEXTCLOUD_USERNAME=${NEXTCLOUD_USERNAME}
|
||||||
|
- NEXTCLOUD_PASSWORD=${NEXTCLOUD_PASSWORD}
|
||||||
|
# Configuration de l'application
|
||||||
|
- APP_HOST=0.0.0.0
|
||||||
|
- APP_PORT=8000
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
restart: unless-stopped
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/health')\""]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
|
networks:
|
||||||
|
- pynextcloud-network
|
||||||
|
|
||||||
|
networks:
|
||||||
|
pynextcloud-network:
|
||||||
|
driver: bridge
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user