feat: add support for external PostgreSQL and Redis services#3707
Open
VidhyaSanjeevi wants to merge 1 commit intoDokploy:canaryfrom
Open
feat: add support for external PostgreSQL and Redis services#3707VidhyaSanjeevi wants to merge 1 commit intoDokploy:canaryfrom
VidhyaSanjeevi wants to merge 1 commit intoDokploy:canaryfrom
Conversation
6618c61 to
ffb49d7
Compare
Add environment variable support for connecting to external PostgreSQL and Redis instances instead of the built-in Docker Swarm services. This enables deploying Dokploy on Kubernetes and other container orchestrators where running Docker Swarm services for infrastructure isn't possible. Changes: - Skip built-in Postgres/Redis Docker Swarm service creation when external services are configured (DATABASE_URL pointing to external host, or REDIS_URL/REDIS_HOST set) - Add REDIS_URL support for full connection string with auth, TLS, port - Add REDIS_PORT and REDIS_PASSWORD individual env var support - Prevent runtime env vars (DATABASE_URL, REDIS_URL, POSTGRES_* etc) from being hardcoded at build time by esbuild - Update backup/restore to work with external PostgreSQL via pg_dump/ pg_restore using PGPASSWORD env var - Guard cleanRedis/reloadRedis admin operations when using external Redis - Export isExternalDatabase() and isExternalRedis() helpers from constants - Update .env.example and .env.production.example with documentation Closes Dokploy#2611
ffb49d7 to
46267b9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add environment variable support for connecting to external PostgreSQL and Redis instances instead of the built-in Docker Swarm services. This enables deploying Dokploy on Kubernetes and other container orchestrators where running Docker Swarm services for infrastructure isn't practical or possible.
Closes #2611
Motivation
When deploying Dokploy on Kubernetes (e.g., K3s, EKS, GKE), the built-in Docker Swarm services for PostgreSQL and Redis can't be used. Additionally, production environments often prefer managed database services (RDS, Cloud SQL, etc.) for reliability, backups, and scaling.
The current codebase already supports \DATABASE_URL\ for the database connection (as of the recent centralization in \packages/server/src/db/constants.ts), but there was no way to:
Changes
Core
Redis Connection
Build
Settings API
eloadRedis\ admin operations when using external Redis
Backup & Restore
Documentation
New Environment Variables
Backward Compatibility
All changes are fully backward compatible:
Testing
Greptile Overview
Greptile Summary
This PR adds support for connecting Dokploy to external PostgreSQL and Redis instances via environment variables (
DATABASE_URL,REDIS_URL,REDIS_HOST,REDIS_PORT,REDIS_PASSWORD). When these are configured, the built-in Docker Swarm service creation is skipped, and backup/restore operations use direct CLI tools instead ofdocker exec. The esbuild config is updated to prevent these env vars from being inlined at build time, and admin Redis operations are guarded against external instances.Key issues found:
DATABASE_URL(host, port, user, database) are interpolated directly into shell command strings passed toexecAsync()without any escaping. The codebase already usesshell-quoteelsewhere for this purpose. While the threat model is limited to operator-controlled env vars, this is a defense-in-depth concern that should be addressed before merging.creds.databasevalue is interpolated into SQL string literals within shell commands (e.g.,WHERE datname = '${creds.database}'), creating a potential SQL injection vector.getPostgresCredentials()is identically duplicated acrossbackups/web-server.tsandrestore/web-server.ts. Consider extracting it to the shared constants module.isExternalDatabase()returnstruefor the default developmentDATABASE_URL(which useslocalhost), which may be unexpected for contributors running the setup script locally.Confidence Score: 2/5
Last reviewed commit: ee06956
(4/5) You can add custom instructions or style guidelines for the agent here!