fix: route compose db connections to postgres service #4
Reference in New Issue
Block a user
Delete Branch "codex/fix-dockerfile-and-compose-for-meme-wrangler-w3lgdz"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_69064e9bb8348320946392cb0b92f1a6
Summary by CodeRabbit
Documentation
New Features
Chores
Walkthrough
This PR standardizes environment filenames to
.ENV(adds.ENV.example), updates Docker/compose/deploy docs and scripts to use.ENV, adds Postgres healthchecks and env defaults, adjusts Dockerfile build/install steps, and enhances bot initialization with lazy Telegram dependency handling and DATABASE_URL derivation/normalization.Changes
\.ENV.example,\.gitignore,\.dockerignore.ENV.examplewith commented env vars and placeholders. Updates.gitignoreto ignore both.envand.ENV. Simplifies.dockerignoreto focus on Git, Python cache, and env files.AGENTS.md,DOCKER_DEPLOY.md,README.md.envreferences with.ENV/.ENV.example, adds Postgres host/port hints (POSTGRES_HOST=postgres, POSTGRES_PORT=5432), and adds Portainer stack/env upload guidance and COMPOSE_ENV_FILE notes.Dockerfilebuild-essential,libpq-dev) with --no-install-recommends, refactors copy/install steps to include full source, ensures/app/backupsexists, and consolidates ENV declarations.docker-compose.ymlenv_filefor postgres and meme-wrangler, introduces defaulted DB and runtime env vars (POSTGRES_, TELEGRAM_, POSTGRES_HOST/PORT), constructs DATABASE_URL from components, adds postgres healthcheck, and makes meme-wrangler depend_on postgres withcondition: service_healthy.bot.py_build_database_url()and_normalize_database_url()functions; assignsDATABASE_URL = _build_database_url()and uses urlparse/urlunparse for normalization.deploy.shENV_FILEdetection (.ENVpreferred, fallback to.env), updates checks and upload steps to use$ENV_FILE, and adjusts messaging to reflect dual filename support.Sequence Diagram
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
bot.py: lazy import proxies, error behavior when telegram missing, URL parsing/normalization correctness.docker-compose.yml: env interpolation for DATABASE_URL, healthcheck syntax, depend_on condition.Dockerfile: package install flags and backup directory creation.deploy.sh: detection logic for.ENVvs.envand subsequent use of$ENV_FILE.Poem
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
@coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (2 passed)
_build_database_url()and_normalize_database_url()functions) combined with Docker Compose configuration updates that establish POSTGRES_HOST=postgres as the default, ensuring containerized deployments connect to the internal postgres service rather than localhost. While the PR includes supporting changes such as documentation updates, environment file restructuring, and Dockerfile improvements, the title accurately captures the main technical fix that ties these changes together. The title is clear, specific, and uses appropriate conventional commit formatting with the "fix:" prefix.✨ Finishing touches
🧪 Generate unit tests (beta)
codex/fix-dockerfile-and-compose-for-meme-wrangler-w3lgdz📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between
63dc74e8a2and1cbb4513d7.📒 Files selected for processing (1)
bot.py(3 hunks)🧰 Additional context used
🪛 Ruff (0.14.2)
bot.py
51-53: Avoid specifying long messages outside the exception class
(TRY003)
55-55: Unused method argument:
args(ARG002)
55-55: Unused method argument:
kwargs(ARG002)
56-58: Avoid specifying long messages outside the exception class
(TRY003)
64-66: Avoid specifying long messages outside the exception class
(TRY003)
105-105: Undefined name
quote(F821)
105-105: Undefined name
quote(F821)
🔇 Additional comments (3)
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.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands and usage tips.Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between
2d6c388a3eand63dc74e8a2.📒 Files selected for processing (10)
.ENV.example(1 hunks).dockerignore(1 hunks).gitignore(1 hunks)AGENTS.md(1 hunks)DOCKER_DEPLOY.md(5 hunks)Dockerfile(1 hunks)README.md(3 hunks)bot.py(3 hunks)deploy.sh(2 hunks)docker-compose.yml(1 hunks)🧰 Additional context used
🪛 dotenv-linter (4.0.0)
.ENV.example
[warning] 4-4: [UnorderedKey] The OWNER_ID key should go before the TELEGRAM_BOT_TOKEN key
(UnorderedKey)
[warning] 5-5: [UnorderedKey] The CHANNEL_ID key should go before the OWNER_ID key
(UnorderedKey)
[warning] 6-6: [UnorderedKey] The POSTGRES_DB key should go before the TELEGRAM_BOT_TOKEN key
(UnorderedKey)
[warning] 7-7: [UnorderedKey] The POSTGRES_USER key should go before the TELEGRAM_BOT_TOKEN key
(UnorderedKey)
[warning] 8-8: [UnorderedKey] The POSTGRES_PASSWORD key should go before the POSTGRES_USER key
(UnorderedKey)
[warning] 9-9: [UnorderedKey] The POSTGRES_HOST key should go before the POSTGRES_PASSWORD key
(UnorderedKey)
[warning] 10-10: [UnorderedKey] The POSTGRES_PORT key should go before the POSTGRES_USER key
(UnorderedKey)
[warning] 11-11: [UnorderedKey] The MEMEBOT_BACKUP_DIR key should go before the OWNER_ID key
(UnorderedKey)
🪛 Ruff (0.14.2)
bot.py
51-53: Avoid specifying long messages outside the exception class
(TRY003)
55-55: Unused method argument:
args(ARG002)
55-55: Unused method argument:
kwargs(ARG002)
56-58: Avoid specifying long messages outside the exception class
(TRY003)
64-66: Avoid specifying long messages outside the exception class
(TRY003)
🔇 Additional comments (5)
@@ -89,7 +90,63 @@ def _ensure_ist(dt: datetime) -> datetime:return _ist_localize(dt)⚠️ Potential issue | 🔴 Critical
Percent-encode DB credentials before composing
DATABASE_URL.When
POSTGRES_PASSWORD(or the username) contains reserved characters like@,:, or/, the URL you build here becomes invalid (e.g.,postgresql://user:pa@ss@…), causing asyncpg to reject the connection and the bot to fail startup. Please percent-encode the credentials before embedding them in the URL.📝 Committable suggestion
🤖 Prompt for AI Agents
⚠️ Potential issue | 🔴 Critical
Preserve credential encoding when normalizing the host.
urlparsereturns decodedusername/password, so rebuildingnetlocwith them drops percent-encoding and corrupts URLs that contain reserved characters (samepa@ssexample fails once normalization runs). Keep the original auth segment intact and only swap the host/port to avoid breaking valid URLs.📝 Committable suggestion
🤖 Prompt for AI Agents
✅ Addressed in commit
3d81b8d