feat: add production container support with health check endpoint
Implements Phase 5 containerization specification: - Add /health endpoint for container monitoring - Create multi-stage Containerfile (Podman/Docker compatible) - Add compose.yaml for orchestration - Add Caddyfile.example for reverse proxy (auto-HTTPS) - Add nginx.conf.example as alternative - Update .env.example with container and RSS feed variables - Add gunicorn WSGI server to requirements.txt Container features: - Multi-stage build for smaller image size - Non-root user (starpunk:1000) - Health check with database connectivity test - Volume mount for data persistence - Resource limits and logging configuration - Security headers and HTTPS configuration examples Health check endpoint: - Tests database connectivity - Verifies filesystem access - Returns JSON with status, version, and environment Following Phase 5 design in docs/designs/phase-5-rss-and-container.md
This commit is contained in:
@@ -52,6 +52,54 @@ def create_app(config=None):
|
||||
return {"error": "Internal server error"}, 500
|
||||
return render_template("500.html"), 500
|
||||
|
||||
# Health check endpoint for containers and monitoring
|
||||
@app.route("/health")
|
||||
def health_check():
|
||||
"""
|
||||
Health check endpoint for containers and monitoring
|
||||
|
||||
Returns:
|
||||
JSON with status and basic info
|
||||
|
||||
Response codes:
|
||||
200: Application healthy
|
||||
500: Application unhealthy
|
||||
|
||||
Checks:
|
||||
- Database connectivity
|
||||
- File system access
|
||||
- Basic application state
|
||||
"""
|
||||
from flask import jsonify
|
||||
import os
|
||||
|
||||
try:
|
||||
# Check database connectivity
|
||||
from starpunk.database import get_db
|
||||
|
||||
db = get_db(app)
|
||||
db.execute("SELECT 1").fetchone()
|
||||
db.close()
|
||||
|
||||
# Check filesystem access
|
||||
data_path = app.config.get("DATA_PATH", "data")
|
||||
if not os.path.exists(data_path):
|
||||
raise Exception("Data path not accessible")
|
||||
|
||||
return (
|
||||
jsonify(
|
||||
{
|
||||
"status": "healthy",
|
||||
"version": app.config.get("VERSION", __version__),
|
||||
"environment": app.config.get("ENV", "unknown"),
|
||||
}
|
||||
),
|
||||
200,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"status": "unhealthy", "error": str(e)}), 500
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user