fix: route compose db connections to postgres service #4

Merged
overspend1 merged 4 commits from codex/fix-dockerfile-and-compose-for-meme-wrangler-w3lgdz into main 2025-11-01 22:54:12 +01:00
overspend1 commented 2025-11-01 22:05:22 +01:00 (Migrated from github.com)

Summary

  • teach the bot to build or rewrite DATABASE_URL using POSTGRES_HOST/PORT so containerized runs stop dialing localhost
  • expand the docker compose env to expose POSTGRES_HOST/PORT defaults and document the new variables for Portainer stacks
  • extend the .ENV example with the compose-ready host defaults and update the README/deployment guide with the guidance

Testing

  • pytest

https://chatgpt.com/codex/tasks/task_e_69064e9bb8348320946392cb0b92f1a6

Summary by CodeRabbit

  • Documentation

    • Standardized environment file naming to .ENV and updated deployment guides and Portainer instructions
    • Expanded PostgreSQL setup guidance and examples
  • New Features

    • Added database health checks for Docker stacks
    • Improved environment variable defaults and handling, including POSTGRES host/port hints
    • Flexible environment-file detection (supports .ENV and .env)
  • Chores

    • Optimized container build and ensured backup directory is present
    • Simplified ignore rules for environment files and caches
## Summary - teach the bot to build or rewrite DATABASE_URL using POSTGRES_HOST/PORT so containerized runs stop dialing localhost - expand the docker compose env to expose POSTGRES_HOST/PORT defaults and document the new variables for Portainer stacks - extend the .ENV example with the compose-ready host defaults and update the README/deployment guide with the guidance ## Testing - pytest ------ https://chatgpt.com/codex/tasks/task_e_69064e9bb8348320946392cb0b92f1a6 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Standardized environment file naming to .ENV and updated deployment guides and Portainer instructions * Expanded PostgreSQL setup guidance and examples * **New Features** * Added database health checks for Docker stacks * Improved environment variable defaults and handling, including POSTGRES host/port hints * Flexible environment-file detection (supports .ENV and .env) * **Chores** * Optimized container build and ensured backup directory is present * Simplified ignore rules for environment files and caches <!-- end of auto-generated comment: release notes by coderabbit.ai -->
coderabbitai[bot] commented 2025-11-01 22:05:33 +01:00 (Migrated from github.com)

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

Cohort / File(s) Summary
Environment config & ignore files
\.ENV.example, \.gitignore, \.dockerignore
Adds sample .ENV.example with commented env vars and placeholders. Updates .gitignore to ignore both .env and .ENV. Simplifies .dockerignore to focus on Git, Python cache, and env files.
Docs & deployment guides
AGENTS.md, DOCKER_DEPLOY.md, README.md
Replaces .env references 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.
Container build
Dockerfile
Adds PYTHONDONTWRITEBYTECODE/PYTHONUNBUFFERED, installs system deps (build-essential, libpq-dev) with --no-install-recommends, refactors copy/install steps to include full source, ensures /app/backups exists, and consolidates ENV declarations.
Compose orchestration
docker-compose.yml
Adds env_file for 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 with condition: service_healthy.
Application logic
bot.py
Wraps telegram imports with try/except and provides lazy _MissingTelegramModule/_MissingFilters fallbacks; adds _build_database_url() and _normalize_database_url() functions; assigns DATABASE_URL = _build_database_url() and uses urlparse/urlunparse for normalization.
Deployment script
deploy.sh
Introduces ENV_FILE detection (.ENV preferred, fallback to .env), updates checks and upload steps to use $ENV_FILE, and adjusts messaging to reflect dual filename support.

Sequence Diagram

sequenceDiagram
    participant Bot as bot.py
    participant TG as telegram package
    participant Builder as _build_database_url
    participant Norm as _normalize_database_url

    Bot->>TG: attempt import
    alt telegram available
        TG-->>Bot: provide Filters, Client, etc.
    else telegram missing
        Bot-->>Bot: create _MissingTelegramModule/_MissingFilters proxies
    end

    Bot->>Builder: compute DATABASE_URL
    Builder-->>Bot: url or None

    alt URL present
        Bot->>Norm: normalize URL (rewrite localhost→POSTGRES_HOST)
        Norm-->>Bot: normalized DATABASE_URL
    end

    Bot->>Bot: set DATABASE_URL

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review focus:
    • 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 .ENV vs .env and subsequent use of $ENV_FILE.

Poem

🐰 From .env to .ENV I hop with glee,
Lazy guards for Telegram keep imports free,
URLs reborn so Postgres finds its way,
Compose checks pulse healthy every day.
Backups snug in burrows, safe and bright — hooray! 🐇

Pre-merge checks and finishing touches

Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Passed checks (2 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check Passed The pull request title "fix: route compose db connections to postgres service" directly aligns with the primary technical objective of this changeset. The core change is implementing DATABASE_URL derivation and normalization logic in bot.py (via _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 docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 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 63dc74e8a2 and 1cbb4513d7.

📒 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)
bot.py (3)

34-68: Lazy import pattern works well for optional Telegram dependency.

The try/except wrapper with placeholder classes allows the module to load without python-telegram-bot installed, deferring errors until Telegram features are actually invoked. The error messages clearly guide users to install the missing dependency.


93-110: URL derivation logic correctly handles credentials and component fallback.

The function properly:

  • Falls back to building from POSTGRES_* components when explicit DATABASE_URL is absent
  • Percent-encodes username and password to handle reserved characters (addressing the previous review)
  • Normalizes localhost references for containerized runs

Assuming the missing quote import is fixed, this implementation resolves the connection routing issue for Docker Compose environments.


113-146: Host normalization preserves credential encoding correctly.

The implementation addresses the previous review by extracting and reusing the original auth segment from parsed.netloc, avoiding the double-decode issue that would corrupt percent-encoded credentials. The IPv6 bracket wrapping and port fallback logic are both correct.


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 help to get the list of available commands and usage tips.

<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> ## 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 | Cohort / File(s) | Summary | |---|---| | **Environment config & ignore files** <br> `\.ENV.example`, `\.gitignore`, `\.dockerignore` | Adds sample `.ENV.example` with commented env vars and placeholders. Updates `.gitignore` to ignore both `.env` and `.ENV`. Simplifies `.dockerignore` to focus on Git, Python cache, and env files. | | **Docs & deployment guides** <br> `AGENTS.md`, `DOCKER_DEPLOY.md`, `README.md` | Replaces `.env` references 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. | | **Container build** <br> `Dockerfile` | Adds PYTHONDONTWRITEBYTECODE/PYTHONUNBUFFERED, installs system deps (`build-essential`, `libpq-dev`) with --no-install-recommends, refactors copy/install steps to include full source, ensures `/app/backups` exists, and consolidates ENV declarations. | | **Compose orchestration** <br> `docker-compose.yml` | Adds `env_file` for 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 with `condition: service_healthy`. | | **Application logic** <br> `bot.py` | Wraps telegram imports with try/except and provides lazy _MissingTelegramModule/_MissingFilters fallbacks; adds `_build_database_url()` and `_normalize_database_url()` functions; assigns `DATABASE_URL = _build_database_url()` and uses urlparse/urlunparse for normalization. | | **Deployment script** <br> `deploy.sh` | Introduces `ENV_FILE` detection (`.ENV` preferred, fallback to `.env`), updates checks and upload steps to use `$ENV_FILE`, and adjusts messaging to reflect dual filename support. | ## Sequence Diagram ```mermaid sequenceDiagram participant Bot as bot.py participant TG as telegram package participant Builder as _build_database_url participant Norm as _normalize_database_url Bot->>TG: attempt import alt telegram available TG-->>Bot: provide Filters, Client, etc. else telegram missing Bot-->>Bot: create _MissingTelegramModule/_MissingFilters proxies end Bot->>Builder: compute DATABASE_URL Builder-->>Bot: url or None alt URL present Bot->>Norm: normalize URL (rewrite localhost→POSTGRES_HOST) Norm-->>Bot: normalized DATABASE_URL end Bot->>Bot: set DATABASE_URL ``` ## Estimated code review effort 🎯 3 (Moderate) | ⏱️ ~25 minutes - Review focus: - `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 `.ENV` vs `.env` and subsequent use of `$ENV_FILE`. ## Poem > 🐰 From `.env` to `.ENV` I hop with glee, > Lazy guards for Telegram keep imports free, > URLs reborn so Postgres finds its way, > Compose checks pulse healthy every day. > Backups snug in burrows, safe and bright — hooray! 🐇✨ <!-- walkthrough_end --> <!-- pre_merge_checks_walkthrough_start --> ## Pre-merge checks and finishing touches <details> <summary>❌ Failed checks (1 warning)</summary> | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :------------------------------------------------------------------------------------ | :----------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. | You can run `@coderabbitai generate docstrings` to improve docstring coverage. | </details> <details> <summary>✅ Passed checks (2 passed)</summary> | Check name | Status | Explanation | | :---------------: | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. | | Title Check | ✅ Passed | The pull request title "fix: route compose db connections to postgres service" directly aligns with the primary technical objective of this changeset. The core change is implementing DATABASE_URL derivation and normalization logic in bot.py (via `_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. | </details> <!-- pre_merge_checks_walkthrough_end --> <!-- finishing_touch_checkbox_start --> <details> <summary>✨ Finishing touches</summary> - [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate docstrings <details> <summary>🧪 Generate unit tests (beta)</summary> - [ ] <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} --> Create PR with unit tests - [ ] <!-- {"checkboxId": "07f1e7d6-8a8e-4e23-9900-8731c2c87f58", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} --> Post copyable unit tests in a comment - [ ] <!-- {"checkboxId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} --> Commit unit tests in branch `codex/fix-dockerfile-and-compose-for-meme-wrangler-w3lgdz` </details> </details> <!-- finishing_touch_checkbox_end --> --- <details> <summary>📜 Recent review details</summary> **Configuration used**: CodeRabbit UI **Review profile**: CHILL **Plan**: Pro <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 63dc74e8a2718ea406970b0c9abf9c44ceca9b6b and 1cbb4513d7e0f364744af91b4fd01e93f7d963ce. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `bot.py` (3 hunks) </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🪛 Ruff (0.14.2)</summary> <details> <summary>bot.py</summary> 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) </details> </details> </details> <details> <summary>🔇 Additional comments (3)</summary><blockquote> <details> <summary>bot.py (3)</summary><blockquote> `34-68`: **Lazy import pattern works well for optional Telegram dependency.** The try/except wrapper with placeholder classes allows the module to load without `python-telegram-bot` installed, deferring errors until Telegram features are actually invoked. The error messages clearly guide users to install the missing dependency. --- `93-110`: **URL derivation logic correctly handles credentials and component fallback.** The function properly: - Falls back to building from `POSTGRES_*` components when explicit `DATABASE_URL` is absent - Percent-encodes username and password to handle reserved characters (addressing the previous review) - Normalizes localhost references for containerized runs Assuming the missing `quote` import is fixed, this implementation resolves the connection routing issue for Docker Compose environments. --- `113-146`: **Host normalization preserves credential encoding correctly.** The implementation addresses the previous review by extracting and reusing the original auth segment from `parsed.netloc`, avoiding the double-decode issue that would corrupt percent-encoded credentials. The IPv6 bracket wrapping and port fallback logic are both correct. </blockquote></details> </blockquote></details> </details> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=overspend1/meme-wrangler&utm_content=4)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands and usage tips.</sub> <!-- tips_end --> <!-- internal state start --> <!-- DwQgtGAEAqAWCWBnSTIEM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fOIl6SMBWHPCZ+Pci4BbAGE7SVPJvE+AjRmJX0R6O8gkAMoQoaoCFAJByhLRJAbyGgHFC+RwsQoEgH6NDgqi0FocbyKFFoDVAlRvkHwOKG9GlwgolREUHQBihxQbJP8+iLYEsmASYomC2gIqD8jSgVgQoNADFHFBoB4oDAeBRFG2JKjOFV2WKAIEChhifADADiGgFCjaiGAKwEUHGKVGhRfIsY0uKFAyhoB6Fr87eXsATnKBSAmRboh4FZI0AhxEcm8d1OsUXzdEBAOsB4DI4cliJXAbyGPOAXzTdU8SMYLHMMVwYhxQoD+S0F0kGBwl9Ix0cUnDAFiixJYrMYxKURAA== --> <!-- internal state end -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-11-01 22:11:03 +01:00
coderabbitai[bot] (Migrated from github.com) left a comment

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 2d6c388a3e and 63dc74e8a2.

📒 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)
.ENV.example (1)

1-12: Static analysis false positive: logical grouping is appropriate.

The dotenv-linter UnorderedKey warnings suggest alphabetical ordering, but the current logical grouping—Telegram settings, then PostgreSQL credentials, then backup configuration—provides superior clarity for users. This organization improves usability compared to alphabetical sorting.

README.md (1)

13-16: Comprehensive documentation update aligns with new compose-based deployment model.

The expanded guidance on line 16 clearly explains the .ENV-to-.ENV.example switch, POSTGRES_HOST targeting, and how the bot handles localhost rewriting. The Portainer subsection (line 28) provides practical instructions for orchestrator deployments. However, ensure that bot.py actually implements the DATABASE_URL rewriting/normalization logic described ("bot rewrites any localhost URLs").

Also applies to: 28-28

deploy.sh (1)

29-42: Environment file detection provides backward compatibility and clear error guidance.

The updated logic gracefully handles the transition from .env to .ENV by checking both in order (prefer .ENV, fall back to .env), and provides users with clear guidance referencing .ENV.example when neither is found. The variable substitution at line 52 ensures the correct file is uploaded regardless of which exists.

Also applies to: 52-52

docker-compose.yml (1)

1-9: Compose configuration correctly establishes env file anchor, service coordination, and DATABASE_URL defaults.

The setup is well-structured: the env_file anchor provides flexible configuration, the postgres healthcheck ensures proper initialization, and the depends_on condition prevents race conditions. The DATABASE_URL construction via environment variables (line 41) provides sensible defaults that avoid localhost issues in containerized environments.

However, the PR objectives mention "Modify the bot to build or rewrite DATABASE_URL"—ensure bot.py implements normalization logic to handle externally-provided DATABASE_URL values that might still contain localhost, translating them to the internal postgres service name.

Also applies to: 16-21, 28-42

DOCKER_DEPLOY.md (1)

40-41: Deployment guide comprehensively covers .ENV adoption and Portainer integration.

The documentation consistently updates env file naming across all deployment paths, adds clear explanations of POSTGRES_HOST behavior and internal service name usage (line 62), and provides specific Portainer Stack guidance (lines 82-84) with the exact directory path Portainer will use. This addresses the PR's documentation objective well.

Verify that bot.py implements the localhost-rewriting logic described in line 62 ("bot rewrites into any localhost-style URLs") as a core part of the PR.

Also applies to: 52-62, 82-84

**Actionable comments posted: 2** <details> <summary>📜 Review details</summary> **Configuration used**: CodeRabbit UI **Review profile**: CHILL **Plan**: Pro <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 2d6c388a3e02052896374bc6f32cf69691458307 and 63dc74e8a2718ea406970b0c9abf9c44ceca9b6b. </details> <details> <summary>📒 Files selected for processing (10)</summary> * `.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) </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🪛 dotenv-linter (4.0.0)</summary> <details> <summary>.ENV.example</summary> [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) </details> </details> <details> <summary>🪛 Ruff (0.14.2)</summary> <details> <summary>bot.py</summary> 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) </details> </details> </details> <details> <summary>🔇 Additional comments (5)</summary><blockquote> <details> <summary>.ENV.example (1)</summary><blockquote> `1-12`: **Static analysis false positive: logical grouping is appropriate.** The dotenv-linter UnorderedKey warnings suggest alphabetical ordering, but the current logical grouping—Telegram settings, then PostgreSQL credentials, then backup configuration—provides superior clarity for users. This organization improves usability compared to alphabetical sorting. </blockquote></details> <details> <summary>README.md (1)</summary><blockquote> `13-16`: **Comprehensive documentation update aligns with new compose-based deployment model.** The expanded guidance on line 16 clearly explains the .ENV-to-.ENV.example switch, POSTGRES_HOST targeting, and how the bot handles localhost rewriting. The Portainer subsection (line 28) provides practical instructions for orchestrator deployments. However, ensure that bot.py actually implements the DATABASE_URL rewriting/normalization logic described ("bot rewrites any localhost URLs"). Also applies to: 28-28 </blockquote></details> <details> <summary>deploy.sh (1)</summary><blockquote> `29-42`: **Environment file detection provides backward compatibility and clear error guidance.** The updated logic gracefully handles the transition from .env to .ENV by checking both in order (prefer .ENV, fall back to .env), and provides users with clear guidance referencing .ENV.example when neither is found. The variable substitution at line 52 ensures the correct file is uploaded regardless of which exists. Also applies to: 52-52 </blockquote></details> <details> <summary>docker-compose.yml (1)</summary><blockquote> `1-9`: **Compose configuration correctly establishes env file anchor, service coordination, and DATABASE_URL defaults.** The setup is well-structured: the env_file anchor provides flexible configuration, the postgres healthcheck ensures proper initialization, and the depends_on condition prevents race conditions. The DATABASE_URL construction via environment variables (line 41) provides sensible defaults that avoid localhost issues in containerized environments. However, the PR objectives mention "Modify the bot to build or rewrite DATABASE_URL"—ensure bot.py implements normalization logic to handle externally-provided DATABASE_URL values that might still contain localhost, translating them to the internal `postgres` service name. Also applies to: 16-21, 28-42 </blockquote></details> <details> <summary>DOCKER_DEPLOY.md (1)</summary><blockquote> `40-41`: **Deployment guide comprehensively covers .ENV adoption and Portainer integration.** The documentation consistently updates env file naming across all deployment paths, adds clear explanations of POSTGRES_HOST behavior and internal service name usage (line 62), and provides specific Portainer Stack guidance (lines 82-84) with the exact directory path Portainer will use. This addresses the PR's documentation objective well. Verify that bot.py implements the localhost-rewriting logic described in line 62 ("bot rewrites into any localhost-style URLs") as a core part of the PR. Also applies to: 52-62, 82-84 </blockquote></details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@@ -89,7 +90,63 @@ def _ensure_ist(dt: datetime) -> datetime:
return _ist_localize(dt)
coderabbitai[bot] (Migrated from github.com) commented 2025-11-01 22:11:02 +01:00

⚠️ 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.

-from urllib.parse import urlparse, urlunparse
+from urllib.parse import quote, urlparse, urlunparse
@@
-    if not raw_url:
-        user = os.environ.get("POSTGRES_USER")
-        password = os.environ.get("POSTGRES_PASSWORD")
-        db_name = os.environ.get("POSTGRES_DB")
-        host = os.environ.get("POSTGRES_HOST", "localhost")
-        port = os.environ.get("POSTGRES_PORT", "5432")
-        if user and password and db_name:
-            raw_url = f"postgresql://{user}:{password}@{host}:{port}/{db_name}"
+    if not raw_url:
+        user = os.environ.get("POSTGRES_USER")
+        password = os.environ.get("POSTGRES_PASSWORD")
+        db_name = os.environ.get("POSTGRES_DB")
+        host = os.environ.get("POSTGRES_HOST", "localhost")
+        port = os.environ.get("POSTGRES_PORT", "5432")
+        if user and password and db_name:
+            raw_url = (
+                f"postgresql://{quote(user, safe='')}:{quote(password, safe='')}"
+                f"@{host}:{port}/{db_name}"
+            )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    raw_url = os.environ.get("DATABASE_URL") or os.environ.get("MEMEBOT_DB")
    if not raw_url:
        user = os.environ.get("POSTGRES_USER")
        password = os.environ.get("POSTGRES_PASSWORD")
        db_name = os.environ.get("POSTGRES_DB")
        host = os.environ.get("POSTGRES_HOST", "localhost")
        port = os.environ.get("POSTGRES_PORT", "5432")
        if user and password and db_name:
            raw_url = (
                f"postgresql://{quote(user, safe='')}:{quote(password, safe='')}"
                f"@{host}:{port}/{db_name}"
            )
🤖 Prompt for AI Agents
In bot.py around lines 96 to 105, the code builds DATABASE_URL by interpolating
POSTGRES_USER and POSTGRES_PASSWORD directly which breaks when those values
contain reserved URL characters; update the code to percent-encode the username
and password before composing raw_url (use urllib.parse.quote or quote_plus on
user and password, and import it at the top if missing), then build raw_url
using the encoded values (you can also encode db_name if desired) so the
resulting postgresql:// URL is valid for asyncpg.
_⚠️ 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. ```diff -from urllib.parse import urlparse, urlunparse +from urllib.parse import quote, urlparse, urlunparse @@ - if not raw_url: - user = os.environ.get("POSTGRES_USER") - password = os.environ.get("POSTGRES_PASSWORD") - db_name = os.environ.get("POSTGRES_DB") - host = os.environ.get("POSTGRES_HOST", "localhost") - port = os.environ.get("POSTGRES_PORT", "5432") - if user and password and db_name: - raw_url = f"postgresql://{user}:{password}@{host}:{port}/{db_name}" + if not raw_url: + user = os.environ.get("POSTGRES_USER") + password = os.environ.get("POSTGRES_PASSWORD") + db_name = os.environ.get("POSTGRES_DB") + host = os.environ.get("POSTGRES_HOST", "localhost") + port = os.environ.get("POSTGRES_PORT", "5432") + if user and password and db_name: + raw_url = ( + f"postgresql://{quote(user, safe='')}:{quote(password, safe='')}" + f"@{host}:{port}/{db_name}" + ) ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion raw_url = os.environ.get("DATABASE_URL") or os.environ.get("MEMEBOT_DB") if not raw_url: user = os.environ.get("POSTGRES_USER") password = os.environ.get("POSTGRES_PASSWORD") db_name = os.environ.get("POSTGRES_DB") host = os.environ.get("POSTGRES_HOST", "localhost") port = os.environ.get("POSTGRES_PORT", "5432") if user and password and db_name: raw_url = ( f"postgresql://{quote(user, safe='')}:{quote(password, safe='')}" f"@{host}:{port}/{db_name}" ) ``` </details> <!-- suggestion_end --> <details> <summary>🤖 Prompt for AI Agents</summary> ``` In bot.py around lines 96 to 105, the code builds DATABASE_URL by interpolating POSTGRES_USER and POSTGRES_PASSWORD directly which breaks when those values contain reserved URL characters; update the code to percent-encode the username and password before composing raw_url (use urllib.parse.quote or quote_plus on user and password, and import it at the top if missing), then build raw_url using the encoded values (you can also encode db_name if desired) so the resulting postgresql:// URL is valid for asyncpg. ``` </details> <!-- fingerprinting:phantom:medusa:sabertoothed --> <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] (Migrated from github.com) commented 2025-11-01 22:11:03 +01:00

⚠️ Potential issue | 🔴 Critical

Preserve credential encoding when normalizing the host.

urlparse returns decoded username/password, so rebuilding netloc with them drops percent-encoding and corrupts URLs that contain reserved characters (same pa@ss example fails once normalization runs). Keep the original auth segment intact and only swap the host/port to avoid breaking valid URLs.

-    username = parsed.username or ""
-    password = parsed.password
-    auth = ""
-    if username:
-        auth = username
-        if password is not None:
-            auth += f":{password}"
-        auth += "@"
-
-    if parsed.port is not None:
-        port_fragment = f":{parsed.port}"
-    else:
-        port_env = os.environ.get("POSTGRES_PORT")
-        port_fragment = f":{port_env}" if port_env else ""
-
-    new_netloc = f"{auth}{host_override}{port_fragment}"
+    if "@" in parsed.netloc:
+        auth_prefix, _, _ = parsed.netloc.rpartition("@")
+        auth_segment = f"{auth_prefix}@"
+    else:
+        auth_segment = ""
+
+    if parsed.port is not None:
+        port_fragment = f":{parsed.port}"
+    else:
+        port_env = os.environ.get("POSTGRES_PORT")
+        port_fragment = f":{port_env}" if port_env else ""
+
+    target_host = host_override
+    if ":" in target_host and not target_host.startswith("["):
+        target_host = f"[{target_host}]"
+
+    new_netloc = f"{auth_segment}{target_host}{port_fragment}"
     rebuilt = parsed._replace(netloc=new_netloc)
     return urlunparse(rebuilt)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    if "@" in parsed.netloc:
        auth_prefix, _, _ = parsed.netloc.rpartition("@")
        auth_segment = f"{auth_prefix}@"
    else:
        auth_segment = ""

    if parsed.port is not None:
        port_fragment = f":{parsed.port}"
    else:
        port_env = os.environ.get("POSTGRES_PORT")
        port_fragment = f":{port_env}" if port_env else ""

    target_host = host_override
    if ":" in target_host and not target_host.startswith("["):
        target_host = f"[{target_host}]"

    new_netloc = f"{auth_segment}{target_host}{port_fragment}"
    rebuilt = parsed._replace(netloc=new_netloc)
    return urlunparse(rebuilt)
🤖 Prompt for AI Agents
In bot.py around lines 126-143, the code rebuilds netloc using
parsed.username/parsed.password which are percent-decoded and thus drop original
credential encoding; instead, extract the auth segment from the original
parsed.netloc (take everything before the last '@' if present, preserving its
percent-encoding and trailing '@') and reuse that as the auth prefix when
composing the new_netloc, only replacing host and port (fall back to building
auth only when no original auth exists); keep port handling as-is and assemble
new_netloc = auth_segment + host_override + port_fragment before calling
parsed._replace and urlunparse.

Addressed in commit 3d81b8d

_⚠️ Potential issue_ | _🔴 Critical_ **Preserve credential encoding when normalizing the host.** `urlparse` returns decoded `username`/`password`, so rebuilding `netloc` with them drops percent-encoding and corrupts URLs that contain reserved characters (same `pa@ss` example fails once normalization runs). Keep the original auth segment intact and only swap the host/port to avoid breaking valid URLs. ```diff - username = parsed.username or "" - password = parsed.password - auth = "" - if username: - auth = username - if password is not None: - auth += f":{password}" - auth += "@" - - if parsed.port is not None: - port_fragment = f":{parsed.port}" - else: - port_env = os.environ.get("POSTGRES_PORT") - port_fragment = f":{port_env}" if port_env else "" - - new_netloc = f"{auth}{host_override}{port_fragment}" + if "@" in parsed.netloc: + auth_prefix, _, _ = parsed.netloc.rpartition("@") + auth_segment = f"{auth_prefix}@" + else: + auth_segment = "" + + if parsed.port is not None: + port_fragment = f":{parsed.port}" + else: + port_env = os.environ.get("POSTGRES_PORT") + port_fragment = f":{port_env}" if port_env else "" + + target_host = host_override + if ":" in target_host and not target_host.startswith("["): + target_host = f"[{target_host}]" + + new_netloc = f"{auth_segment}{target_host}{port_fragment}" rebuilt = parsed._replace(netloc=new_netloc) return urlunparse(rebuilt) ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion if "@" in parsed.netloc: auth_prefix, _, _ = parsed.netloc.rpartition("@") auth_segment = f"{auth_prefix}@" else: auth_segment = "" if parsed.port is not None: port_fragment = f":{parsed.port}" else: port_env = os.environ.get("POSTGRES_PORT") port_fragment = f":{port_env}" if port_env else "" target_host = host_override if ":" in target_host and not target_host.startswith("["): target_host = f"[{target_host}]" new_netloc = f"{auth_segment}{target_host}{port_fragment}" rebuilt = parsed._replace(netloc=new_netloc) return urlunparse(rebuilt) ``` </details> <!-- suggestion_end --> <details> <summary>🤖 Prompt for AI Agents</summary> ``` In bot.py around lines 126-143, the code rebuilds netloc using parsed.username/parsed.password which are percent-decoded and thus drop original credential encoding; instead, extract the auth segment from the original parsed.netloc (take everything before the last '@' if present, preserving its percent-encoding and trailing '@') and reuse that as the auth prefix when composing the new_netloc, only replacing host and port (fall back to building auth only when no original auth exists); keep port handling as-is and assemble new_netloc = auth_segment + host_override + port_fragment before calling parsed._replace and urlunparse. ``` </details> <!-- fingerprinting:phantom:medusa:sabertoothed --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 3d81b8d
Sign in to join this conversation.