-
Notifications
You must be signed in to change notification settings - Fork 1
feat(docker): configure n8n and Temporal to use shared PostgreSQL #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(docker): configure n8n and Temporal to use shared PostgreSQL #13
Conversation
…kend - Set up environment variables for n8n and Temporal PostgreSQL connections - Ensure both services use separate databases and credentials - Add persistent Docker volumes for PostgreSQL data - Update docker-compose and .env.example for clarity and security Refs #64541
|
""" WalkthroughThe changes restructure environment configuration and Docker Compose setup for a multi-service application. The Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant DockerCompose
participant PostgreSQL
participant InitScript
participant n8n
participant Temporal
Developer->>DockerCompose: docker-compose up
DockerCompose->>PostgreSQL: Start container
PostgreSQL->>InitScript: Run init-db.sh on startup
InitScript->>PostgreSQL: Create users and databases for n8n and Temporal
PostgreSQL-->>DockerCompose: Signal healthy after databases exist
DockerCompose->>n8n: Start container (waits for PostgreSQL healthy)
n8n->>PostgreSQL: Connect using n8n credentials
DockerCompose->>Temporal: Start container (waits for PostgreSQL and opensearch healthy)
Temporal->>PostgreSQL: Connect using temporal credentials
Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
🔍 Vulnerabilities of
|
| digest | sha256:c80b52813a106d26385464d78f435685657c50c7b192d5f4a69410752d213b00 |
| vulnerabilities | |
| platform | linux/amd64 |
| size | 243 MB |
| packages | 1628 |
📦 Base Image node:20-alpine
Description
| ||||||||||||
Description
| ||||||||||||
Description
| ||||||||||||
Description
| ||||||||||||
Description
|
…d Temporal - Updated .env.example to include production environment variables for n8n and Temporal - Refined docker-compose.prod.yml to streamline PostgreSQL configuration and remove unnecessary volume definitions - Ensured all required environment variables are clearly defined for production deployment Refs #64541
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (4)
scripts/init-db.sh (2)
1-2: Enhance script robustness with strict shell options
Consider addingset -uandset -o pipefailto catch unset variables and pipeline failures. For example:- set -e + set -euo pipefailThis will make the script more resilient and fail fast on unexpected errors.
4-12: Validate inputs and improve idempotency of database creation
- Add checks for required environment variables to avoid empty or malformed user/database names.
- Use
DO $$ … $$;blocks orCREATE ROLE IF NOT EXISTSto prevent errors if the script is re-run.Example enhancements:
+ : "${POSTGRES_USER_N8N:?Environment variable POSTGRES_USER_N8N is required}" + : "${POSTGRES_PASSWORD_N8N:?Environment variable POSTGRES_PASSWORD_N8N is required}" + : "${POSTGRES_DB_N8N:?Environment variable POSTGRES_DB_N8N is required}" + : "${POSTGRES_USER_TEMPORAL:?Environment variable POSTGRES_USER_TEMPORAL is required}" + : "${POSTGRES_PASSWORD_TEMPORAL:?Environment variable POSTGRES_PASSWORD_TEMPORAL is required}" + : "${POSTGRES_DB_TEMPORAL:?Environment variable POSTGRES_DB_TEMPORAL is required}" psql -v ON_ERROR_STOP=1 --username "postgres" <<-EOSQL - CREATE USER "$POSTGRES_USER_N8N" WITH ENCRYPTED PASSWORD '$POSTGRES_PASSWORD_N8N'; + DO $$ BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '$POSTGRES_USER_N8N') THEN + CREATE USER "$POSTGRES_USER_N8N" WITH ENCRYPTED PASSWORD '$POSTGRES_PASSWORD_N8N'; + END IF; + END $$; CREATE DATABASE "$POSTGRES_DB_N8N" OWNER "$POSTGRES_USER_N8N"; GRANT ALL PRIVILEGES ON DATABASE "$POSTGRES_DB_N8N" TO "$POSTGRES_USER_N8N"; - CREATE USER "$POSTGRES_USER_TEMPORAL" WITH ENCRYPTED PASSWORD '$POSTGRES_PASSWORD_TEMPORAL'; + DO $$ BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '$POSTGRES_USER_TEMPORAL') THEN + CREATE USER "$POSTGRES_USER_TEMPORAL" WITH ENCRYPTED PASSWORD '$POSTGRES_PASSWORD_TEMPORAL'; + END IF; + END $$; CREATE DATABASE "$POSTGRES_DB_TEMPORAL" OWNER "$POSTGRES_USER_TEMPORAL"; GRANT ALL PRIVILEGES ON DATABASE "$POSTGRES_DB_TEMPORAL" TO "$POSTGRES_USER_TEMPORAL"; EOSQLThese changes help prevent accidental re-creation errors and ensure that missing environment variables fail early.
.env.example (1)
30-30: Placeholder for GitHub token is fine
Ensure users understand not to commit real tokens.docker-compose.prod.yml (1)
80-80: Remove trailing spaces
YAMLLint flagged trailing spaces on this line. Please trim to avoid lint errors.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.env.example(1 hunks)docker-compose.prod.yml(2 hunks)docker-compose.yml(4 hunks)scripts/init-db.sh(1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
docker-compose.yml
[error] 80-80: trailing spaces
(trailing-spaces)
🔇 Additional comments (14)
.env.example (8)
9-14: Clarify general vs service-specific PostgreSQL variables
You’ve introducedPOSTGRES_DB_N8N/POSTGRES_USER_N8NandPOSTGRES_DB_TEMPORAL/POSTGRES_USER_TEMPORALfor dev isolation. Double-check whether the genericPOSTGRES_USER,POSTGRES_DB, andPOSTGRES_PASSWORDentries above are still needed—or if they can be removed—to avoid confusion.
16-19: Development n8n settings look good
The webhook URL, encryption key, and port defaults are clear and correctly scoped for local development.
21-23: Development OpenSearch settings are appropriate
UsingDISABLE_SECURITY_PLUGIN=trueand the default port is fine for dev.
25-27: Development Temporal settings are correct
The default ports align with your local setup.
45-47: Production OpenSearch port placeholder is correct
Defaulting to 9200 aligns with your compose files.
48-49: Production Temporal port placeholder is fine
This matches yourdocker-compose.prod.yml.
51-52: Production Temporal-UI port placeholder is correct
8080 is the standard UI port.
53-55: Production Temporal DB variables are in place
Placeholders forPOSTGRES_DB_TEMPORAL,POSTGRES_USER_TEMPORAL, andPOSTGRES_PASSWORD_TEMPORALare correctly scoped.docker-compose.prod.yml (1)
16-16: Verify Compose compatibility for!reset null
The!reset nullfeature requires a recent Docker Compose spec (> v3.5) and the new CLI. Please confirm your CI/CD and local environments support this syntax.docker-compose.yml (5)
11-13: n8n service dependency is properly gated on PostgreSQL health
Usingcondition: service_healthyensures n8n only starts after the DB is ready.
24-31: n8n’s PostgreSQL environment is correctly configured
You’ve setDB_TYPE, host, port, credentials, plus enhanced logging settings—this aligns with best practices for production-like dev environments.
74-81: PostgreSQL service now supports separate app DBs
DefiningPOSTGRES_DB_N8N,POSTGRES_USER_N8N, etc., alongside the defaultPOSTGRES_PASSWORDis a solid approach for multi-tenant setup.🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 80-80: trailing spaces
(trailing-spaces)
85-86: Initialization script mounted correctly
The newinit-db.shwill run on first startup to create both databases/users.
90-90: Health check verifies both databases exist
Your combinedpsqlcommand ensures bothn8nandtemporalDBs are up. Well done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
docker-compose.yml (1)
115-126:⚠️ Potential issueTemporal service DB environment variables misnamed
The Temporal server image expectsDB_SEEDS(host:port) rather thanPOSTGRES_SEEDS. Please update accordingly and include the port.
Apply this diff:- - POSTGRES_SEEDS: postgresql + - DB_SEEDS: postgresql:${POSTGRES_PORT:-5432}Also verify if you need
DB_PLUGIN=postgresqlper your Temporal version.
🧹 Nitpick comments (1)
docker-compose.yml (1)
78-85: Clear separation of credentials for multiple databases
Introducing distinctPOSTGRES_DB_N8N,POSTGRES_USER_N8N,POSTGRES_PASSWORD_N8N(and their Temporal counterparts) improves isolation.
Nitpick: remove the trailing whitespace on line 84 to satisfy YAML linting.🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 84-84: trailing spaces
(trailing-spaces)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.env.example(2 hunks)docker-compose.prod.yml(2 hunks)docker-compose.yml(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- .env.example
- docker-compose.prod.yml
🧰 Additional context used
🪛 YAMLlint (1.35.1)
docker-compose.yml
[error] 84-84: trailing spaces
(trailing-spaces)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Docker Security Scanning (n8n, Dockerfile.n8n, n8n-test:latest)
- GitHub Check: Service Availability Check
🔇 Additional comments (4)
docker-compose.yml (4)
11-13: Ensure n8n waits for PostgreSQL health before startup
Adding adepends_onwithcondition: service_healthyis a solid improvement to guarantee n8n only starts once the database is ready.
24-31: Explicit PostgreSQL configuration for n8n looks good
Switching from generic vars toDB_TYPE=postgresdbandDB_POSTGRESDB_*keys aligns with n8n’s Postgres driver conventions.
94-94: Strong health check verifying both databases
The combined SQL query ensures both the n8n and Temporal databases exist before marking the service healthy—excellent coverage.
89-89:✅ Verification successful
Verify database initialization script inclusion
Ensure thatscripts/init-db.shis present at the correct path and has executable permissions so it runs at container startup.
🏁 Script executed:
#!/bin/bash # Check presence and executability of init-db.sh if [ -f scripts/init-db.sh ] && [ -x scripts/init-db.sh ]; then echo "init-db.sh is present and executable" else echo "Error: scripts/init-db.sh is missing or not executable" exit 1 fiLength of output: 146
Database initialization script verified
Thescripts/init-db.shfile exists and has executable permissions, ensuring it will run at container startup. No further changes are needed.
- Added required environment variables for n8n and Temporal services in docker-compose.prod.yml - Set dependencies for n8n and Temporal services to ensure proper startup order - Improved clarity by using environment variable placeholders for host and database configurations This update enhances the production setup for better reliability and configuration management.
- Added a newline at the end of the init-db.sh script to ensure proper file formatting and prevent potential issues in execution. This change improves the script's compatibility and adheres to best practices for shell scripts.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM



Uh oh!
There was an error while loading. Please reload this page.