This guide covers deploying the Geocoding API to Coolify, a self-hosted PaaS.
- Coolify Instance: Running Coolify server
- Domain: (Optional) Custom domain for your API
- Environment Variables: Secure values for production
git clone <your-repo-url>
cd geocoding-apiIn your Coolify dashboard, set these environment variables:
Required:
# Database
DB_USER=geocoding_user
DB_PASSWORD=<generate-secure-password>
DB_NAME=geocoding_db
# Security (CRITICAL - Generate secure keys!)
JWT_SECRET=<generate-32-char-secret>
API_SECRET_KEY=<generate-32-char-secret>Optional:
# Ports (Coolify will auto-assign if not set)
API_PORT=8080
API_EXTERNAL_PORT=8080
DB_EXTERNAL_PORT=5432
# Performance
RATE_LIMIT_PER_MINUTE=100
MAX_CONNECTIONS=50
GO_ENV=productionCoolify will automatically:
- Build the Docker images
- Create the database with health checks
- Start the API service
- Set up networking between services
# Generate JWT Secret (32 chars)
openssl rand -hex 32
# Generate API Secret (32 chars)
openssl rand -hex 32
# Generate DB Password (24 chars)
openssl rand -base64 24- Never commit
.envfiles with secrets - Use Coolify's environment variable management
- Rotate secrets regularly
The application includes built-in health checks:
- API:
GET /api/v1/health - Database: PostgreSQL ready check
- Docker: Container health monitoring
# Health check
curl https://your-domain.com/api/v1/health
# API status
curl -H "X-API-Key: your-key" https://your-domain.com/api/v1/geocode?query=10001# View API logs
docker logs geocoding_api
# View database logs
docker logs geocoding_db- Multiple API containers behind load balancer
- Single PostgreSQL instance (or read replicas)
# Minimum
- API: 512MB RAM, 0.5 CPU
- DB: 1GB RAM, 1 CPU, 10GB storage
# Recommended
- API: 1GB RAM, 1 CPU
- DB: 2GB RAM, 1 CPU, 50GB storage# Create backup
docker exec geocoding_db pg_dump -U geocoding_user geocoding_db > backup.sql
# Restore backup
docker exec -i geocoding_db psql -U geocoding_user geocoding_db < backup.sql- PostgreSQL data:
/var/lib/postgresql/data - API logs: Application logs in container
-
"No .env file found"
- ✅ This is normal in Docker - using environment variables
- Check Coolify environment variable configuration
-
Database Connection Failed
- Verify DB_PASSWORD matches in both services
- Check PostgreSQL health status
- Ensure network connectivity
-
API Key Authentication Failed
- Verify JWT_SECRET is set consistently
- Check API key is active in database
- Validate API_SECRET_KEY configuration
# Check running containers
docker ps
# Test database connection
docker exec geocoding_db psql -U geocoding_user -d geocoding_db -c "\dt"
# View API environment
docker exec geocoding_api env | grep -E "(DB_|JWT_|API_)"
# Test API health
curl http://localhost:8080/api/v1/health-- Add indexes for common queries (if not already present)
CREATE INDEX IF NOT EXISTS idx_zip_codes_zip ON zip_codes(zip);
CREATE INDEX IF NOT EXISTS idx_api_keys_user_id ON api_keys(user_id);
CREATE INDEX IF NOT EXISTS idx_usage_records_api_key_id ON usage_records(api_key_id);- Enable gzip compression (already configured)
- Use connection pooling (already configured)
- Monitor rate limiting effectiveness
Coolify handles SSL automatically with Let's Encrypt:
- Add your domain in Coolify
- Enable SSL/TLS
- Force HTTPS redirects
| Feature | Development | Production |
|---|---|---|
| Database | Local PostgreSQL | Docker PostgreSQL |
| Environment | .env file | Coolify env vars |
| SSL | HTTP | HTTPS (Let's Encrypt) |
| Logging | Debug level | Info level |
| Secrets | Simple values | Generated secrets |
Once deployed, access API documentation at:
- Swagger UI:
https://your-domain.com/docs - OpenAPI spec:
https://your-domain.com/api-docs.yaml
For deployment issues:
- Check Coolify logs
- Verify environment variables
- Test health endpoints
- Review container logs
🚀 Ready to deploy! Your production-ready geocoding API is configured for Coolify deployment.