perf: optimize production deployment with tuned gunicorn settings and health checks
This commit is contained in:
		
							parent
							
								
									66011bcd0f
								
							
						
					
					
						commit
						e52d0c61ca
					
				
					 1 changed files with 37 additions and 2 deletions
				
			
		
							
								
								
									
										39
									
								
								Dockerfile
									
										
									
									
									
								
							
							
						
						
									
										39
									
								
								Dockerfile
									
										
									
									
									
								
							|  | @ -1,17 +1,52 @@ | ||||||
| FROM python:3.11-slim-buster | FROM python:3.11-slim-buster | ||||||
| 
 | 
 | ||||||
| RUN apt-get update && apt-get install -y build-essential | # Install system dependencies | ||||||
|  | RUN apt-get update && \ | ||||||
|  |     apt-get install -y build-essential && \ | ||||||
|  |     apt-get clean && \ | ||||||
|  |     rm -rf /var/lib/apt/lists/* | ||||||
| 
 | 
 | ||||||
|  | # Set working directory | ||||||
| WORKDIR /rideaware_landing | WORKDIR /rideaware_landing | ||||||
| 
 | 
 | ||||||
|  | # Copy requirements first for better caching | ||||||
| COPY requirements.txt . | COPY requirements.txt . | ||||||
| 
 | 
 | ||||||
|  | # Install Python dependencies | ||||||
| RUN pip install --no-cache-dir -r requirements.txt | RUN pip install --no-cache-dir -r requirements.txt | ||||||
| 
 | 
 | ||||||
|  | # Copy application code | ||||||
| COPY . . | COPY . . | ||||||
| 
 | 
 | ||||||
|  | # Set environment variables | ||||||
| ENV FLASK_APP=server.py | ENV FLASK_APP=server.py | ||||||
|  | ENV PYTHONUNBUFFERED=1 | ||||||
|  | ENV PYTHONPATH=/rideaware_landing | ||||||
| 
 | 
 | ||||||
|  | # Create non-root user for security | ||||||
|  | RUN useradd --create-home --shell /bin/bash app && \ | ||||||
|  |     chown -R app:app /rideaware_landing | ||||||
|  | USER app | ||||||
|  | 
 | ||||||
|  | # Expose port | ||||||
| EXPOSE 5000 | EXPOSE 5000 | ||||||
| 
 | 
 | ||||||
| CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "4", "server:app"] | # Health check | ||||||
|  | HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | ||||||
|  |     CMD curl -f http://localhost:5000/health || exit 1 | ||||||
|  | 
 | ||||||
|  | # Run with optimized Gunicorn settings | ||||||
|  | CMD ["gunicorn", \ | ||||||
|  |      "--bind", "0.0.0.0:5000", \ | ||||||
|  |      "--workers", "4", \ | ||||||
|  |      "--worker-class", "sync", \ | ||||||
|  |      "--worker-connections", "1000", \ | ||||||
|  |      "--max-requests", "1000", \ | ||||||
|  |      "--max-requests-jitter", "50", \ | ||||||
|  |      "--preload", \ | ||||||
|  |      "--timeout", "30", \ | ||||||
|  |      "--keep-alive", "2", \ | ||||||
|  |      "--access-logfile", "-", \ | ||||||
|  |      "--error-logfile", "-", \ | ||||||
|  |      "--log-level", "info", \ | ||||||
|  |      "server:app"] | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Cipher Vance
						Cipher Vance