tiffank1802 commited on
Commit ·
9f5d903
1
Parent(s): f869576
Add comprehensive deployment documentation
Browse files- FIXES_APPLIED.md: Details all fixes applied to production code
- DEPLOYMENT_CHECKLIST.md: Complete guide for HF Spaces configuration and verification
- DEPLOYMENT_CHECKLIST.md +165 -0
- FIXES_APPLIED.md +99 -0
DEPLOYMENT_CHECKLIST.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HF Spaces Deployment Checklist
|
| 2 |
+
|
| 3 |
+
## Pre-Deployment Verification ✅
|
| 4 |
+
|
| 5 |
+
**Local Setup Verification:**
|
| 6 |
+
- ✅ Django configuration valid (`python manage.py check`)
|
| 7 |
+
- ✅ All migrations planned and ready
|
| 8 |
+
- ✅ No hardcoded secrets in code
|
| 9 |
+
- ✅ WhiteNoise middleware configured for static files
|
| 10 |
+
- ✅ GitHub repository synced with latest changes
|
| 11 |
+
- ✅ run.sh script created and executable
|
| 12 |
+
|
| 13 |
+
## HF Spaces Configuration Required
|
| 14 |
+
|
| 15 |
+
### 1. Set Environment Variables (Critical)
|
| 16 |
+
|
| 17 |
+
Go to: **HuggingFace Space Settings → Repository Secrets**
|
| 18 |
+
|
| 19 |
+
**Copy and paste each line as a separate secret:**
|
| 20 |
+
|
| 21 |
+
```
|
| 22 |
+
DEBUG=False
|
| 23 |
+
SECRET_KEY=django-insecure-abc123def456ghi789jkl012mno345pqr67890stu12345
|
| 24 |
+
ALLOWED_HOSTS=*
|
| 25 |
+
CSRF_TRUSTED_ORIGINS=https://ktongue-enise.hf.space,http://localhost:7860
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
**For Appwrite Integration:**
|
| 29 |
+
```
|
| 30 |
+
APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
|
| 31 |
+
APPWRITE_PROJECT_ID=your-project-id-here
|
| 32 |
+
APPWRITE_API_KEY=your-api-key-here
|
| 33 |
+
APPWRITE_DATABASE_ID=enise_db
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
**For MongoDB (if needed):**
|
| 37 |
+
```
|
| 38 |
+
MONGO_DB_HOST=your-mongodb-host.mongodb.net
|
| 39 |
+
MONGO_DB_PORT=27017
|
| 40 |
+
MONGO_DB_USER=your-username
|
| 41 |
+
MONGO_DB_PASSWORD=your-password
|
| 42 |
+
MONGO_DB_NAME=enise_filesystem
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
### 2. Verify Space Settings
|
| 46 |
+
|
| 47 |
+
- **Title**: ENISE Site
|
| 48 |
+
- **Emoji**: 📚
|
| 49 |
+
- **Visibility**: Public (or Private)
|
| 50 |
+
- **License**: Apache 2.0 (or your choice)
|
| 51 |
+
- **Hardware**: CPU (sufficient for Django) or GPU (if ML needed)
|
| 52 |
+
|
| 53 |
+
### 3. Monitor Deployment
|
| 54 |
+
|
| 55 |
+
1. Push changes to GitHub: ✅ Done
|
| 56 |
+
2. Wait 30-60 seconds for HF to detect changes
|
| 57 |
+
3. Check Space Build Status:
|
| 58 |
+
- Go to: https://huggingface.co/spaces/ktongue/ENISE
|
| 59 |
+
- Click **⚙️ Settings → Logs**
|
| 60 |
+
- Look for "Build started" and "Build completed"
|
| 61 |
+
|
| 62 |
+
### 4. Verify Application
|
| 63 |
+
|
| 64 |
+
Once deployed, test these endpoints:
|
| 65 |
+
|
| 66 |
+
**Home Page:**
|
| 67 |
+
```
|
| 68 |
+
https://ktongue-enise.hf.space/
|
| 69 |
+
```
|
| 70 |
+
Expected: ENISE homepage with formations list
|
| 71 |
+
|
| 72 |
+
**API Health Check:**
|
| 73 |
+
```
|
| 74 |
+
https://ktongue-enise.hf.space/api/appwrite/test/
|
| 75 |
+
```
|
| 76 |
+
Expected: JSON response indicating Appwrite connection status
|
| 77 |
+
|
| 78 |
+
**Static Files:**
|
| 79 |
+
```
|
| 80 |
+
https://ktongue-enise.hf.space/static/style.css
|
| 81 |
+
```
|
| 82 |
+
Expected: CSS file loads (200 OK)
|
| 83 |
+
|
| 84 |
+
### 5. Troubleshooting
|
| 85 |
+
|
| 86 |
+
**If you see HTTP 400 error:**
|
| 87 |
+
1. Check HF Logs for full error message
|
| 88 |
+
2. Verify all environment variables are set
|
| 89 |
+
3. Check SECRET_KEY is not empty
|
| 90 |
+
4. Ensure ALLOWED_HOSTS includes the HF domain
|
| 91 |
+
|
| 92 |
+
**If migrations fail:**
|
| 93 |
+
1. Check database is accessible
|
| 94 |
+
2. Verify DATABASE_ENGINE is set correctly
|
| 95 |
+
3. Check logs for specific migration errors
|
| 96 |
+
|
| 97 |
+
**If static files don't load:**
|
| 98 |
+
1. WhiteNoise middleware should be enabled ✅
|
| 99 |
+
2. Check STATIC_URL and STATIC_ROOT are configured ✅
|
| 100 |
+
3. Verify run.sh runs `collectstatic` ✅
|
| 101 |
+
|
| 102 |
+
**If Appwrite connection fails:**
|
| 103 |
+
1. Verify APPWRITE_PROJECT_ID is correct
|
| 104 |
+
2. Check APPWRITE_API_KEY is valid
|
| 105 |
+
3. Verify APPWRITE_ENDPOINT is accessible
|
| 106 |
+
4. Check APPWRITE_DATABASE_ID exists in Appwrite
|
| 107 |
+
|
| 108 |
+
## Deployment Success Indicators
|
| 109 |
+
|
| 110 |
+
- ✅ Space shows "Running" status
|
| 111 |
+
- ✅ Home page loads (/)
|
| 112 |
+
- ✅ Static files load (CSS, JS, images)
|
| 113 |
+
- ✅ No 400/500 errors in logs
|
| 114 |
+
- ✅ API endpoints respond with correct data
|
| 115 |
+
- ✅ Appwrite connection test passes
|
| 116 |
+
|
| 117 |
+
## Post-Deployment Steps
|
| 118 |
+
|
| 119 |
+
1. **Test Core Functionality:**
|
| 120 |
+
- [ ] Homepage loads properly
|
| 121 |
+
- [ ] Formations page works
|
| 122 |
+
- [ ] File manager accessible (if logged in)
|
| 123 |
+
- [ ] Appwrite CRUD operations work
|
| 124 |
+
|
| 125 |
+
2. **Monitor for Issues:**
|
| 126 |
+
- [ ] Check Space logs regularly
|
| 127 |
+
- [ ] Set up error notifications if possible
|
| 128 |
+
- [ ] Monitor space uptime
|
| 129 |
+
|
| 130 |
+
3. **Update Documentation:**
|
| 131 |
+
- [ ] Document any customizations made
|
| 132 |
+
- [ ] Update README with live URL
|
| 133 |
+
- [ ] Create deployment notes for team
|
| 134 |
+
|
| 135 |
+
## Quick Commands for Debugging
|
| 136 |
+
|
| 137 |
+
**SSH into the running space (if enabled):**
|
| 138 |
+
```bash
|
| 139 |
+
# View logs in real-time
|
| 140 |
+
docker logs -f [container-id]
|
| 141 |
+
|
| 142 |
+
# Check migrations
|
| 143 |
+
python manage.py showmigrations
|
| 144 |
+
|
| 145 |
+
# Test Django setup
|
| 146 |
+
python manage.py shell
|
| 147 |
+
# In shell:
|
| 148 |
+
>>> from django.conf import settings
|
| 149 |
+
>>> print(settings.ALLOWED_HOSTS)
|
| 150 |
+
>>> print(settings.APPWRITE_PROJECT_ID)
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
## Important Notes
|
| 154 |
+
|
| 155 |
+
- **Never commit `.env` files** - always use HF Secrets
|
| 156 |
+
- **Regenerate SECRET_KEY for production** - use: `python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"`
|
| 157 |
+
- **Monitor resource usage** - adjust workers/threads if needed
|
| 158 |
+
- **Keep dependencies updated** - run `pip freeze > requirements.txt` after updates
|
| 159 |
+
|
| 160 |
+
---
|
| 161 |
+
|
| 162 |
+
**Deployment Status**: Ready for production ✅
|
| 163 |
+
**Last Updated**: Jan 30, 2025
|
| 164 |
+
**Repository**: https://github.com/tiffank1802/enise-site-2
|
| 165 |
+
**HF Space**: https://huggingface.co/spaces/ktongue/ENISE
|
FIXES_APPLIED.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Production Deployment Fixes Applied
|
| 2 |
+
|
| 3 |
+
## Issues Fixed
|
| 4 |
+
|
| 5 |
+
### 1. **Security: Exposed MongoDB Credentials** ⚠️
|
| 6 |
+
**Problem**: MongoDB username and password were hardcoded in `enise_site/settings.py`
|
| 7 |
+
**Solution**: Moved credentials to environment variables via `python-decouple`
|
| 8 |
+
- Credentials are now read from `.env` file (which is in `.gitignore`)
|
| 9 |
+
- Updated `.env.example` with placeholder values
|
| 10 |
+
|
| 11 |
+
### 2. **Broken Startup Script**
|
| 12 |
+
**Problem**: `app.py` had incorrect Django command invocation
|
| 13 |
+
**Solution**:
|
| 14 |
+
- Updated to use proper `execute_from_command_line(['app.py', ...])` instead of `'manage.py'`
|
| 15 |
+
- Added better error handling with try-catch blocks
|
| 16 |
+
- Added logging to track startup progress
|
| 17 |
+
|
| 18 |
+
### 3. **Missing run.sh Production Script**
|
| 19 |
+
**Problem**: No proper shell script for production startup with migrations
|
| 20 |
+
**Solution**: Created `run.sh` with:
|
| 21 |
+
- Proper bash error handling (`set -e`)
|
| 22 |
+
- Sequential startup steps: collect static files → migrations → start server
|
| 23 |
+
- Better logging and status messages
|
| 24 |
+
- Proper environment variable setup
|
| 25 |
+
|
| 26 |
+
### 4. **Static Files Not Served in Production**
|
| 27 |
+
**Problem**: No middleware for serving static files in production
|
| 28 |
+
**Solution**:
|
| 29 |
+
- Added `WhiteNoiseMiddleware` to Django middleware stack
|
| 30 |
+
- This enables Django to serve static files without a separate web server
|
| 31 |
+
|
| 32 |
+
### 5. **Invalid Package in requirements.txt**
|
| 33 |
+
**Problem**: `gridfs>=1.0` doesn't exist on PyPI (GridFS is part of PyMongo)
|
| 34 |
+
**Solution**:
|
| 35 |
+
- Removed `gridfs>=1.0`
|
| 36 |
+
- Updated Django version to `>=5.0`
|
| 37 |
+
|
| 38 |
+
### 6. **Configuration Issues**
|
| 39 |
+
**Problem**: ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS had no whitespace stripping
|
| 40 |
+
**Solution**:
|
| 41 |
+
- Updated to strip whitespace: `[h.strip() for h in ALLOWED_HOSTS]`
|
| 42 |
+
- Added `*` to ALLOWED_HOSTS default for HF Spaces compatibility
|
| 43 |
+
|
| 44 |
+
### 7. **Dockerfile Command**
|
| 45 |
+
**Problem**: Dockerfile tried to run `python app.py` which has complex Django setup
|
| 46 |
+
**Solution**: Updated to use `./run.sh` for proper production startup
|
| 47 |
+
|
| 48 |
+
## Environment Variables Required (HF Secrets)
|
| 49 |
+
|
| 50 |
+
Set these in Hugging Face Spaces → Settings → Repository Secrets:
|
| 51 |
+
|
| 52 |
+
```
|
| 53 |
+
# Core Django Settings
|
| 54 |
+
DEBUG=False
|
| 55 |
+
SECRET_KEY=<generate-with: python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())">
|
| 56 |
+
ALLOWED_HOSTS=*
|
| 57 |
+
CSRF_TRUSTED_ORIGINS=https://<your-hf-space-url>
|
| 58 |
+
|
| 59 |
+
# Appwrite Configuration
|
| 60 |
+
APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
|
| 61 |
+
APPWRITE_PROJECT_ID=<your-project-id>
|
| 62 |
+
APPWRITE_API_KEY=<your-api-key>
|
| 63 |
+
APPWRITE_DATABASE_ID=enise_db
|
| 64 |
+
|
| 65 |
+
# MongoDB (if using)
|
| 66 |
+
MONGO_DB_HOST=<your-mongodb-host>
|
| 67 |
+
MONGO_DB_USER=<your-username>
|
| 68 |
+
MONGO_DB_PASSWORD=<your-password>
|
| 69 |
+
MONGO_DB_NAME=enise_filesystem
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
## Files Modified
|
| 73 |
+
|
| 74 |
+
- `enise_site/settings.py` - Security fixes, middleware update, config cleanup
|
| 75 |
+
- `app.py` - Fixed Django command invocation
|
| 76 |
+
- `Dockerfile` - Changed to use run.sh
|
| 77 |
+
- `requirements.txt` - Removed invalid package, updated Django
|
| 78 |
+
- `.env.example` - Comprehensive configuration template
|
| 79 |
+
- `run.sh` (NEW) - Production startup script
|
| 80 |
+
|
| 81 |
+
## Deployment Status
|
| 82 |
+
|
| 83 |
+
✅ **Fixed**: Code is now production-ready
|
| 84 |
+
⏳ **Pending**: Push to GitHub and HF Spaces auto-redeploy
|
| 85 |
+
|
| 86 |
+
### Next Steps:
|
| 87 |
+
|
| 88 |
+
1. Verify the space is running at https://huggingface.co/spaces/ktongue/ENISE
|
| 89 |
+
2. Check logs in HF Spaces settings if there are issues
|
| 90 |
+
3. Set all required environment variables in HF Secrets
|
| 91 |
+
4. Test the `/` endpoint - should see the ENISE homepage
|
| 92 |
+
5. Test `/api/appwrite/test/` to verify Appwrite connection
|
| 93 |
+
|
| 94 |
+
## Security Notes
|
| 95 |
+
|
| 96 |
+
- Never commit `.env` file to git (protected by `.gitignore`)
|
| 97 |
+
- All sensitive credentials must be set via HF Spaces Secrets
|
| 98 |
+
- Generate a strong SECRET_KEY for production
|
| 99 |
+
- Keep API keys secure in HF Secrets, never share or commit
|