feat(pg): added ability to customize postgres port when running containerized app#1173
feat(pg): added ability to customize postgres port when running containerized app#1173waleedlatif1 merged 1 commit intostagingfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR adds the ability to customize the PostgreSQL port for containerized deployments by introducing a POSTGRES_PORT environment variable that defaults to 5432. The change affects five Docker Compose configuration files and the environment example file:
- Environment Configuration: Added
POSTGRES_PORTto.env.examplewith proper documentation as an optional variable - Docker Compose Files: Updated
docker-compose.local.yml,docker-compose.prod.yml,docker-compose.ollama.yml, and.devcontainer/docker-compose.ymlto use${POSTGRES_PORT:-5432}in both database connection URLs and port mappings - Service Integration: Modified DATABASE_URL strings across all services (simstudio, realtime, migrations) to incorporate the configurable port
The implementation uses Docker Compose parameter expansion syntax to maintain backward compatibility while enabling port customization. This feature addresses common deployment scenarios where port 5432 might conflict with existing PostgreSQL installations or other services. The change follows established patterns in the codebase for environment variable configuration and maintains consistency across different deployment environments (development, production, local, ollama).
Confidence score: 1/5
- This PR has a critical bug in the devcontainer configuration that will cause database connection failures when custom ports are used
- Score reflects a fundamental error in DATABASE_URL construction where the port variable is used in the hostname position instead of the port position
- Pay close attention to
.devcontainer/docker-compose.yml- the DATABASE_URL format is incorrect and needs immediate fixing before merge
5 files reviewed, 3 comments
| - DATABASE_URL=postgresql://postgres:postgres@db:${POSTGRES_PORT:-5432}/simstudio | ||
| - POSTGRES_URL=postgresql://postgres:postgres@db:${POSTGRES_PORT:-5432}/simstudio |
There was a problem hiding this comment.
logic: Critical error: ${POSTGRES_PORT:-5432} is placed in the hostname position instead of port position. Should be postgresql://postgres:postgres@db:5432/simstudio since the container always uses internal port 5432
| - DATABASE_URL=postgresql://postgres:postgres@db:${POSTGRES_PORT:-5432}/simstudio | |
| - POSTGRES_URL=postgresql://postgres:postgres@db:${POSTGRES_PORT:-5432}/simstudio | |
| - DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio | |
| - POSTGRES_URL=postgresql://postgres:postgres@db:5432/simstudio |
| environment: | ||
| - NODE_ENV=development | ||
| - DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio | ||
| - DATABASE_URL=postgresql://postgres:postgres@db:${POSTGRES_PORT:-5432}/simstudio |
There was a problem hiding this comment.
logic: Same issue here - POSTGRES_PORT variable is incorrectly used in hostname position instead of port
| - DATABASE_URL=postgresql://postgres:postgres@db:${POSTGRES_PORT:-5432}/simstudio | |
| - DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio |
| dockerfile: docker/db.Dockerfile | ||
| environment: | ||
| - DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio | ||
| - DATABASE_URL=postgresql://postgres:postgres@db:${POSTGRES_PORT:-5432}/simstudio |
There was a problem hiding this comment.
logic: POSTGRES_PORT variable incorrectly positioned in database URL - will break migrations when custom port is used
| - DATABASE_URL=postgresql://postgres:postgres@db:${POSTGRES_PORT:-5432}/simstudio | |
| - DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio |
Summary
added ability to customize postgres port when running containerized app by specifying
POSTGRES_PORT, defaults to 5432Type of Change
Testing
Tested manually.
Checklist