Skip to content

fix: resolve database connectivity issues in Docker setup and optimize container configuration#73

Merged
asternic merged 4 commits into
asternic:mainfrom
guilhermejansen:feature/docker-improvements
May 15, 2025
Merged

fix: resolve database connectivity issues in Docker setup and optimize container configuration#73
asternic merged 4 commits into
asternic:mainfrom
guilhermejansen:feature/docker-improvements

Conversation

@guilhermejansen

Copy link
Copy Markdown
Contributor

Changes made

This pull request improves the Docker configuration:

  • Added health checks for the database service
  • Configured wuzapi-server to wait for the database to be healthy before starting
  • Set proper restart policies for containers
  • Ensured DB_HOST is correctly set to use the container name

Dockerfile improvements:

  • Cleaned up the Dockerfile by removing unnecessary COPY commands
  • Optimized the build process for better efficiency
  • Improved the container startup process

Testing

The application now starts correctly with docker-compose up, and the wuzapi-server can successfully connect to the PostgreSQL database.

…lth checks for the database service, and ensure service dependencies are healthy before starting. Clean up Dockerfile by removing unnecessary COPY commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @guilhermejansen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

Hello! Gemini here, providing a summary of this pull request to help everyone quickly understand the changes. This PR focuses on improving the Docker setup for the application, specifically addressing potential database connectivity issues during startup and optimizing container configuration. Key changes include adding health checks for the PostgreSQL database, ensuring the main application server waits for the database to be healthy before attempting to connect, and configuring appropriate restart policies for resilience. Additionally, the Dockerfile for the server has been cleaned up, and the PostgreSQL version has been updated.

Highlights

  • Database Health Checks: A health check has been added to the db service in docker-compose.yml using pg_isready to verify the database is ready to accept connections. This improves the reliability of the setup.
  • Server Waits for Healthy Database: The wuzapi-server service's depends_on configuration in docker-compose.yml has been updated to use condition: service_healthy for the db service. This ensures the server container will not start until the database reports itself as healthy, preventing connection errors during startup.
  • Container Restart Policies: Restart policies have been added to both services in docker-compose.yml: on-failure for wuzapi-server and always for db. This helps ensure the application recovers automatically from failures.
  • Dockerfile Cleanup: Several unnecessary COPY commands for directories like migrations, files, repository, and dbdata have been removed from the Dockerfile, streamlining the image build process.
  • PostgreSQL Version Update: The PostgreSQL image used for the db service in docker-compose.yml has been updated from version 15 to 16.

Changelog

  • Dockerfile
    • Removed COPY --from=builder commands for /app/migrations, /app/files, /app/repository, and /app/dbdata (lines 29-32).
  • docker-compose.yml
    • Updated wuzapi-server service's depends_on for db to specify condition: service_healthy (lines 20-21).
    • Added restart: on-failure to the wuzapi-server service (line 24).
    • Updated the db service image from postgres:15 to postgres:16 (line 27).
    • Added a healthcheck configuration to the db service using pg_isready (lines 38-42).
    • Added restart: always to the db service (line 43).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Database starts slow,
Server waits for health check green,
Containers now hum.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several valuable improvements to the Docker setup, particularly enhancing the robustness of service startup and management with health checks, explicit dependencies, and restart policies. The cleanup in the Dockerfile is also a good step towards optimization.

My main concern, detailed in the comments, revolves around the removal of COPY commands in the Dockerfile for the /app/migrations and /app/repository directories. Confirmation is needed to ensure these are genuinely no longer required at runtime (e.g., because their contents are embedded in the binary) to prevent potential runtime issues. The PostgreSQL version upgrade is also noted for confirmation.

Summary of Findings

  • Dockerfile: Potential missing runtime dependencies: Removed COPY commands for /app/migrations and /app/repository. If these directories contain files needed at runtime (e.g., SQL migration scripts) and are not embedded into the application binary, this change could cause runtime failures. Confirmation is requested.
  • docker-compose.yml: PostgreSQL version upgrade: The PostgreSQL image was upgraded from version 15 to 16. Confirmation is requested that this was intentional and tested for compatibility.
  • docker-compose.yml: Healthcheck configuration (Low Severity - Not Commented): The database healthcheck command pg_isready -U wuzapi hardcodes the username. While currently consistent with POSTGRES_USER=wuzapi, if the environment variable for the username changes, the healthcheck command would need to be updated manually. This is a minor observation and was not commented on due to review settings.

Merge Readiness

The pull request introduces significant improvements to the Docker configuration. However, due to the high severity concern regarding the Dockerfile changes (potential missing runtime dependencies for migrations) and the medium severity query about the PostgreSQL version upgrade, I recommend addressing these points before merging. Specifically, clarification on how migrations are handled after the COPY removal is crucial.

I am not authorized to approve pull requests, but based on this review, changes are requested. Once these points are clarified and confirmed to be safe, the PR will be in a much better state for merging.

@asternic asternic merged commit 22afd61 into asternic:main May 15, 2025
maxHSG pushed a commit to maxHSG/wuzapi that referenced this pull request Jan 28, 2026
…provements

fix: resolve database connectivity issues in Docker setup and optimize container configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants