Skip to content

Move to gunicorn#735

Merged
myakove merged 7 commits intomainfrom
gunicorn
Apr 26, 2025
Merged

Move to gunicorn#735
myakove merged 7 commits intomainfrom
gunicorn

Conversation

@myakove
Copy link
Copy Markdown
Collaborator

@myakove myakove commented Apr 26, 2025

Switch to gunicorn from uvicorn.

gunicorn support on_starting hook which can run code before the server starts.

Summary by CodeRabbit

  • New Features

    • Added a Gunicorn configuration file to improve server startup and management.
    • Introduced a startup hook to initialize repository and webhook settings automatically when the server starts.
  • Refactor

    • Simplified the server entrypoint process by removing conditional logic and switching to direct Gunicorn invocation.
    • Refactored GitHub repository and webhook settings logic for better modularity and reuse.
    • Modified GitHub check runs to allow re-running checks even if a previous run is still in progress.
  • Chores

    • Updated dependencies to include Gunicorn and Uvicorn worker.
    • Removed an unused environment variable from the example Docker Compose configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 26, 2025

## Walkthrough

This update modifies the server startup process by introducing a Gunicorn configuration file and changing the Dockerfile and entrypoint script to launch the FastAPI application using Gunicorn via the `uv` tool instead of `uvicorn` and a shell script. It adds dependencies for Gunicorn and its Uvicorn worker, removes the `DEVELOPMENT` environment variable from the example Docker Compose file, and refactors utility logic for repository and webhook settings into a reusable function. A new server startup hook is added to initialize repository and webhook settings on server launch.

## Changes

| Files/Paths                                       | Change Summary                                                                                              |
|-------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| Dockerfile, entrypoint.sh, gunicorn.conf.py      | Switched server startup from `uvicorn` via shell script to `gunicorn` via `uv` with config file; added Gunicorn config; removed entrypoint.sh script. |
| pyproject.toml                                   | Added dependencies: `gunicorn` and `uvicorn-worker`.                                                        |
| docker-compose-example.yaml                      | Removed `DEVELOPMENT=false` environment variable; added `WEBHOOK_SERVER_IP_BIND` and `WEBHOOK_SERVER_PORT`.  |
| webhook_server/app.py                            | Added `on_starting(server)` function to run repository and webhook setup at server startup.                  |
| webhook_server/utils/github_repository_and_webhook_settings.py | Refactored main execution logic into new `repository_and_webhook_settings()` function for reuse.             |
| webhook_server/libs/github_api.py                | Modified check run methods to re-run checks even if previously marked in progress, updating log messages accordingly. |

## Possibly related PRs

- myk-org/github-webhook-server#579: Both PRs modify the Dockerfile and entrypoint.sh to switch the server startup mechanism to use `uv` and Gunicorn, focusing on replacing `poetry` with `uv` for running the FastAPI app.

## Suggested labels

`verified`

## Suggested reviewers

- rnetser

📜 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 56de02c and cbabc1a.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • pyproject.toml (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pyproject.toml
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: python-module-install
  • GitHub Check: tox
  • GitHub Check: build-container
  • GitHub Check: pre-commit

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@myakove-bot
Copy link
Copy Markdown
Collaborator

Report bugs in Issues

The following are automatically added:

  • Add reviewers from OWNER file (in the root of the repository) under reviewers section.
  • Set PR size label.
  • New issue is created for the PR. (Closed when PR is merged/closed)
  • Run pre-commit if .pre-commit-config.yaml exists in the repo.

Available user actions:

  • To mark PR as WIP comment /wip to the PR, To remove it from the PR comment /wip cancel to the PR.
  • To block merging of PR comment /hold, To un-block merging of PR comment /hold cancel.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To cherry pick a merged PR comment /cherry-pick <target branch to cherry-pick to> in the PR.
    • Multiple target branches can be cherry-picked, separated by spaces. (/cherry-pick branch1 branch2)
    • Cherry-pick will be started when PR is merged
  • To build and push container image command /build-and-push-container in the PR (tag will be the PR number).
    • You can add extra args to the Podman build command
      • Example: /build-and-push-container --build-arg OPENSHIFT_PYTHON_WRAPPER_COMMIT=<commit_hash>
  • To add a label by comment use /<label name>, to remove, use /<label name> cancel
  • To assign reviewers based on OWNERS file use /assign-reviewers
  • To check if PR can be merged use /check-can-merge
  • to assign reviewer to PR use /assign-reviewer @<reviewer>

PR will be approved when the following conditions are met:

  • /approve from one of the approvers.
  • Minimum number of required /lgtm (2) is met.
Approvers and Reviewers
  • Approvers:

    • myakove
    • rnetser
  • Reviewers:

    • myakove
    • rnetser
Supported /retest check runs
  • /retest tox: Retest tox
  • /retest build-container: Retest build-container
  • /retest python-module-install: Retest python-module-install
  • /retest pre-commit: Retest pre-commit
  • /retest all: Retest all
Supported labels
  • hold
  • verified
  • wip
  • lgtm
  • approve

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
Dockerfile (1)

37-38: Remove unused entrypoint.sh from build artifacts

The Dockerfile still copies entrypoint.sh into the image but never uses it (the ENTRYPOINT now directly invokes Gunicorn). This redundant file increases image size and maintenance overhead. Consider removing entrypoint.sh from the COPY directive or deleting the file altogether.

entrypoint.sh (1)

3-3: Remove or utilize the unused SERVER_RUN_CMD variable

The SERVER_RUN_CMD variable is assigned but never referenced or exported (SC2034). Since the Dockerfile no longer uses this script as an entrypoint, consider deleting entrypoint.sh entirely or updating the script to actually execute "$SERVER_RUN_CMD".

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 3-3: SERVER_RUN_CMD appears unused. Verify use (or export if used externally).

(SC2034)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b252eb7 and 8b8afda.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • Dockerfile (2 hunks)
  • docker-compose-example.yaml (0 hunks)
  • entrypoint.sh (1 hunks)
  • gunicorn.conf.py (1 hunks)
  • pyproject.toml (1 hunks)
  • webhook_server/app.py (1 hunks)
  • webhook_server/utils/github_repository_and_webhook_settings.py (2 hunks)
💤 Files with no reviewable changes (1)
  • docker-compose-example.yaml
🧰 Additional context used
🧬 Code Graph Analysis (1)
gunicorn.conf.py (1)
webhook_server/app.py (1)
  • on_starting (18-19)
🪛 Shellcheck (0.10.0)
entrypoint.sh

[warning] 3-3: SERVER_RUN_CMD appears unused. Verify use (or export if used externally).

(SC2034)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: pre-commit
  • GitHub Check: python-module-install
  • GitHub Check: build-container
  • GitHub Check: tox
🔇 Additional comments (7)
pyproject.toml (1)

69-70: Dependencies added for gunicorn support.

The PR adds two new dependencies to support the migration from uvicorn to gunicorn:

  1. uvicorn-worker>=0.3.0 - Provides the Uvicorn worker class for Gunicorn
  2. gunicorn>=23.0.0 - The Gunicorn server itself

These are appropriate additions that align with the PR objective to leverage Gunicorn's on_starting hook.

webhook_server/utils/github_repository_and_webhook_settings.py (2)

21-46: Good refactoring to support server startup hook.

The code that was previously under if __name__ == "__main__": has been effectively extracted into a reusable function. This allows it to be called during server startup via Gunicorn's on_starting hook while preserving the ability to run it directly.

The function initializes logging, loads configuration, retrieves GitHub API instances, and performs the necessary repository settings and webhook creation operations.


48-49: Clean update to main block.

The main block now simply calls the refactored function, maintaining the original behavior when the script is run directly.

gunicorn.conf.py (1)

1-7: Well-structured Gunicorn configuration.

The configuration:

  1. Binds to all interfaces (0.0.0.0) on port 5000
  2. Uses Uvicorn's ASGI worker for FastAPI compatibility
  3. Sets worker count configurable via environment variable
  4. Configures the on_starting hook to initialize repository and webhook settings
  5. Directs access logs to stdout for container log capture

This configuration properly implements the PR objective of using Gunicorn's startup hook.

webhook_server/app.py (2)

10-10: New import for repository and webhook settings.

The import statement correctly references the refactored function that will be used in the on_starting hook.


18-20: Added Gunicorn startup hook function.

This function implements the core objective of the PR - using Gunicorn's on_starting hook to initialize repository and webhook settings before the server fully starts. The function signature matches what Gunicorn expects for this hook.

Dockerfile (1)

69-69:

Details

✅ Verification successful

Verify Gunicorn bind configuration matches exposed port

The ENTRYPOINT invokes Gunicorn with your custom config, but we need to ensure gunicorn.conf.py binds to 0.0.0.0:5000 (matching EXPOSE 5000). Without this, the container may not accept external connections.

Run the following script from the repo root to confirm the bind setting:


🏁 Script executed:

#!/bin/bash
# Check the bind address in gunicorn.conf.py
grep -R "bind\s*=" gunicorn.conf.py

Length of output: 59


Gunicorn bind configuration matches EXPOSE port
The bind = "0.0.0.0:5000" setting in gunicorn.conf.py aligns with EXPOSE 5000 in the Dockerfile. No changes are needed.

Comment thread gunicorn.conf.py Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
webhook_server/libs/github_api.py (4)

1332-1334: Ensure consistent logging level for re-running checks.

This newly added check for in-progress build container checks uses info level logging, while similar checks for TOX and pre-commit use debug level logging. Consider standardizing the log level across all similar check run messages.

-            self.logger.info(f"{self.log_prefix} Check run is in progress, re-running {BUILD_CONTAINER_STR}.")
+            self.logger.debug(f"{self.log_prefix} Check run is in progress, re-running {BUILD_CONTAINER_STR}.")

1340-1340: Ensure consistent logging level for re-running checks.

Similar to the above, this log message uses info level while other similar checks use debug. Consider standardizing for consistency.

-                self.logger.info(f"{self.log_prefix} Check run is in progress, re-running {BUILD_CONTAINER_STR}.")
+                self.logger.debug(f"{self.log_prefix} Check run is in progress, re-running {BUILD_CONTAINER_STR}.")

1421-1421: Ensure consistent logging level for re-running checks.

This log message uses info level while similar checks for TOX and pre-commit use debug. Consider standardizing for consistency.

-            self.logger.info(f"{self.log_prefix} Check run is in progress, re-running {PYTHON_MODULE_INSTALL_STR}.")
+            self.logger.debug(f"{self.log_prefix} Check run is in progress, re-running {PYTHON_MODULE_INSTALL_STR}.")

2175-2177: Ensure consistent logging level for re-running checks.

The log message for conventional title check re-run uses info level while similar checks for TOX and pre-commit use debug. Consider standardizing for consistency.

-            self.logger.info(f"{self.log_prefix} Check run is in progress, re-running {CONVENTIONAL_TITLE_STR}.")
+            self.logger.debug(f"{self.log_prefix} Check run is in progress, re-running {CONVENTIONAL_TITLE_STR}.")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ef1125 and 56de02c.

📒 Files selected for processing (2)
  • gunicorn.conf.py (1 hunks)
  • webhook_server/libs/github_api.py (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • gunicorn.conf.py
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: python-module-install
  • GitHub Check: build-container
  • GitHub Check: pre-commit
  • GitHub Check: tox
🔇 Additional comments (2)
webhook_server/libs/github_api.py (2)

960-960: Changed log message reflects new behavior of re-running checks instead of skipping.

The logging message now correctly indicates that the check is being re-run even when it's already in progress, which aligns with the new behavior of not returning early from the function.


995-995: Changed log message reflects new behavior of re-running checks instead of skipping.

Similar to the TOX check, this log message has been updated to reflect that the pre-commit check will be re-run rather than skipped when already in progress.

Comment thread webhook_server/libs/github_api.py
@myakove
Copy link
Copy Markdown
Collaborator Author

myakove commented Apr 26, 2025

/verified

@myakove myakove merged commit a790a17 into main Apr 26, 2025
8 of 9 checks passed
@myakove myakove deleted the gunicorn branch April 26, 2025 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants