26c05912fc
Test and Lint / backend-test (push) Successful in 1m11s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m21s
Version and Release / version-bump (push) Successful in 33s
Version and Release / trigger-drone (push) Successful in 2s
- Fix database connection error "getaddrinfo ENOTFOUND postgres" - Add wait-for-db.sh script to ensure PostgreSQL is ready before starting - Fix email processor initialization timing issue - Add missing storage path environment variables - Add database dependency to backend service - Enhance health check endpoint with database connectivity check - Update production database defaults to match docker-compose - Install postgresql-client in Docker image for health checks - Document all required environment variables in .env.example Fixes immediate production deployment failures and ensures proper service startup order. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
3.1 KiB
3.1 KiB
Production Deployment Fixes
This document describes the fixes applied to resolve production deployment issues in Docker.
Issues Fixed
1. Database Connection Error: "getaddrinfo ENOTFOUND postgres"
Problem: The backend was trying to connect to hostname "postgres" but the database service is named "db" in docker-compose. Solution:
- Updated
knexfile.jsto use correct default host "db" instead of "postgres" - Added
depends_on: dbto backend service in docker-compose.prod.yml
2. Backend Starting Before Database Ready
Problem: Backend service started before PostgreSQL was ready, causing connection failures. Solution:
- Created
wait-for-db.shscript that waits for PostgreSQL to be ready - Updated Dockerfile to install postgresql-client and use the wait script
- Script also runs migrations automatically on startup
3. Email Processor Initialization Failure
Problem: Email processor tried to initialize on module load before database was available. Solution:
- Modified
emailProcessor.jsto export initialization functions - Updated
server.jsto call initialization after database is ready - Added proper error handling for email service initialization
4. Missing Environment Variables
Problem: Critical storage path environment variables were missing. Solution:
- Added STORAGE_PATH, EVENTS_PATH, and ARCHIVE_PATH to docker-compose.prod.yml
- Created
.env.exampledocumenting all required environment variables
5. Enhanced Health Check
Problem: Basic health check didn't verify database connectivity. Solution:
- Updated
/api/healthendpoint to check database connection - Returns proper HTTP 503 status when unhealthy
Files Modified
- backend/knexfile.js - Fixed production database defaults
- backend/wait-for-db.sh - Created database wait script
- backend/Dockerfile - Added postgresql-client and wait script
- docker-compose.prod.yml - Added dependencies and environment variables
- backend/src/services/emailProcessor.js - Disabled auto-initialization
- backend/server.js - Added email initialization and improved health check
- backend/.env.example - Created environment variable documentation
Deployment Steps
- Ensure all environment variables are set according to
.env.example - Build and deploy with docker-compose:
docker-compose -f docker-compose.prod.yml build docker-compose -f docker-compose.prod.yml up -d - The backend will now:
- Wait for PostgreSQL to be ready
- Run migrations automatically
- Initialize all services in proper order
- Provide health status at
/api/health
Verification
Check deployment health:
curl http://localhost/api/health
Expected response:
{
"status": "ok",
"database": "connected",
"timestamp": "2025-07-13T20:30:00.000Z"
}
Email Configuration
Email service requires configuration in the database. If email is not configured:
- The service will log a warning but continue running
- Emails will be queued but not sent
- Configure email settings in the admin panel after deployment