Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN mkdir -p $BIN_DIR \
&& mkdir -p $DATA_DIR \
&& mkdir -p $DATA_DIR/logs

COPY entrypoint.sh pyproject.toml uv.lock README.md $APP_DIR/
COPY gunicorn.conf.py pyproject.toml uv.lock README.md $APP_DIR/
COPY webhook_server $APP_DIR/webhook_server/

RUN usermod --add-subuids 100000-165535 --add-subgids 100000-165535 $USERNAME \
Expand Down Expand Up @@ -66,4 +66,4 @@ RUN uv sync

HEALTHCHECK CMD curl --fail http://127.0.0.1:5000/webhook_server/healthcheck || exit 1

ENTRYPOINT ["./entrypoint.sh"]
ENTRYPOINT ["uv", "run", "gunicorn", "webhook_server.app:FASTAPI_APP", "-c", "./gunicorn.conf.py"]
3 changes: 2 additions & 1 deletion docker-compose-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ services:
- PUID=1000
- PGID=1000
- TZ=Asia/Jerusalem
- DEVELOPMENT=false # Set to true when developing.
- UVICORN_MAX_WORKERS=50 # Defaults to 10 if not set and running in production
- WEBHOOK_SERVER_IP_BIND=0.0.0.0 # IP to listen
- WEBHOOK_SERVER_PORT=5000 # Port to listen
ports:
- "5000:5000"
privileged: true
Expand Down
14 changes: 0 additions & 14 deletions entrypoint.sh

This file was deleted.

8 changes: 8 additions & 0 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os

bind = f"{os.environ.get('WEBHOOK_SERVER_IP_BIND', '0.0.0.0')}:{os.environ.get('WEBHOOK_SERVER_PORT', 5000)}"
worker_class = "uvicorn.workers.UvicornWorker"
workers = int(os.environ.get("UVICORN_WORKERS", 10))
on_starting = "webhook_server.app.on_starting"
accesslog = "-"
timeout = 0 # Disable workers timeout, some operation can take long time.
39 changes: 20 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.coverage.run]
omit = [ "tests/*" ]
omit = ["tests/*"]

[tool.coverage.report]
fail_under = 35
Expand All @@ -14,8 +14,8 @@ line-length = 120
fix = true
output-format = "grouped"

[tool.ruff.format]
exclude = [ ".git", ".venv", ".mypy_cache", ".tox", "__pycache__" ]
[tool.ruff.format]
exclude = [".git", ".venv", ".mypy_cache", ".tox", "__pycache__"]

[tool.mypy]
check_untyped_defs = true
Expand All @@ -31,10 +31,10 @@ warn_unused_configs = true
warn_redundant_casts = true

[tool.hatch.build.targets.wheel]
packages = [ "webhook_server" ]
packages = ["webhook_server"]

[tool.uv]
dev-dependencies = [ "ipdb>=0.13.13", "ipython>=8.12.3" ]
dev-dependencies = ["ipdb>=0.13.13", "ipython>=8.12.3"]

[project]
name = "github-webhook-server"
Expand All @@ -45,7 +45,7 @@ readme = "README.md"
license = "Apache-2.0"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent"
"Operating System :: OS Independent",
]
dependencies = [
"build>=1.2.2.post1",
Expand All @@ -65,23 +65,24 @@ dependencies = [
"string-color>=1.2.3",
"timeout-sampler>=0.0.46",
"uvicorn>=0.31.0",
"uwsgi>=2.0.27"
"uvicorn-worker>=0.3.0",
"gunicorn>=23.0.0",
]

[[project.authors]]
name = "Meni Yakove"
email = " myakove@gmail.com"
[[project.authors]]
name = "Meni Yakove"
email = " myakove@gmail.com"

[[project.authors]]
name = "Ruth Netser"
email = "ruth.netser@gmail.com"
[[project.authors]]
name = "Ruth Netser"
email = "ruth.netser@gmail.com"

[project.urls]
homepage = "https://github.com/myakove/github-webhook-server"
repository = "https://github.com/myakove/github-webhook-server"
Download = "https://quay.io/repository/myakove/github-webhook-server"
"Bug Tracker" = "https://github.com/myakove/github-webhook-server/issues"
[project.urls]
homepage = "https://github.com/myakove/github-webhook-server"
repository = "https://github.com/myakove/github-webhook-server"
Download = "https://quay.io/repository/myakove/github-webhook-server"
"Bug Tracker" = "https://github.com/myakove/github-webhook-server/issues"

[build-system]
requires = [ "hatchling" ]
requires = ["hatchling"]
build-backend = "hatchling.build"
29 changes: 29 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions webhook_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
from fastapi import FastAPI, Request

from webhook_server.libs.github_api import ProcessGithubWehook
from webhook_server.utils.github_repository_and_webhook_settings import repository_and_webhook_settings
from webhook_server.utils.helpers import get_logger_with_params

FASTAPI_APP: FastAPI = FastAPI(title="webhook-server")
APP_URL_ROOT_PATH: str = "/webhook_server"
urllib3.disable_warnings()


def on_starting(server: Any) -> None:
repository_and_webhook_settings()


@FASTAPI_APP.get(f"{APP_URL_ROOT_PATH}/healthcheck")
def healthcheck() -> dict[str, Any]:
return {"status": requests.codes.ok, "message": "Alive"}
Expand Down
19 changes: 11 additions & 8 deletions webhook_server/libs/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,7 @@ def _run_tox(self) -> None:
return

if self.is_check_run_in_progress(check_run=TOX_STR):
self.logger.debug(f"{self.log_prefix} Check run is in progress, not running {TOX_STR}.")
return
self.logger.debug(f"{self.log_prefix} Check run is in progress, re-running {TOX_STR}.")

clone_repo_dir = f"{self.clone_repo_dir}-{uuid4()}"
python_ver = f"--python={self.tox_python_version}" if self.tox_python_version else ""
Expand Down Expand Up @@ -993,8 +992,7 @@ def _run_pre_commit(self) -> None:
return

if self.is_check_run_in_progress(check_run=PRE_COMMIT_STR):
self.logger.debug(f"{self.log_prefix} Check run is in progress, not running {PRE_COMMIT_STR}.")
return
self.logger.debug(f"{self.log_prefix} Check run is in progress, re-running {PRE_COMMIT_STR}.")

clone_repo_dir = f"{self.clone_repo_dir}-{uuid4()}"
cmd = f" uvx --directory {clone_repo_dir} {PRE_COMMIT_STR} run --all-files"
Expand Down Expand Up @@ -1331,13 +1329,15 @@ def _run_build_container(
if not self.build_and_push_container:
return

if self.is_check_run_in_progress(check_run=BUILD_CONTAINER_STR):
self.logger.info(f"{self.log_prefix} Check run is in progress, re-running {BUILD_CONTAINER_STR}.")

Comment thread
myakove marked this conversation as resolved.
clone_repo_dir = f"{self.clone_repo_dir}-{uuid4()}"
pull_request = hasattr(self, "pull_request")

if pull_request and set_check:
if self.is_check_run_in_progress(check_run=BUILD_CONTAINER_STR) and not is_merged:
self.logger.info(f"{self.log_prefix} Check run is in progress, not running {BUILD_CONTAINER_STR}.")
return
self.logger.info(f"{self.log_prefix} Check run is in progress, re-running {BUILD_CONTAINER_STR}.")

self.set_container_build_in_progress()

Expand Down Expand Up @@ -1418,8 +1418,7 @@ def _run_install_python_module(self) -> None:
return

if self.is_check_run_in_progress(check_run=PYTHON_MODULE_INSTALL_STR):
self.logger.info(f"{self.log_prefix} Check run is in progress, not running {PYTHON_MODULE_INSTALL_STR}.")
return
self.logger.info(f"{self.log_prefix} Check run is in progress, re-running {PYTHON_MODULE_INSTALL_STR}.")

clone_repo_dir = f"{self.clone_repo_dir}-{uuid4()}"
self.logger.info(f"{self.log_prefix} Installing python module")
Expand Down Expand Up @@ -2172,6 +2171,10 @@ def _run_conventional_title_check(self) -> None:
"summary": "",
"text": "",
}

if self.is_check_run_in_progress(check_run=CONVENTIONAL_TITLE_STR):
self.logger.info(f"{self.log_prefix} Check run is in progress, re-running {CONVENTIONAL_TITLE_STR}.")

self.set_conventional_title_in_progress()
allowed_names = self.conventional_title.split(",")
title = self.pull_request.title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_repository_api(repository: str) -> tuple[str, github.Github | None, str]
return repository, github_api, api_user


if __name__ == "__main__":
def repository_and_webhook_settings() -> None:
logger = get_logger_with_params(name="github-repository-and-webhook-settings")

config = Config()
Expand All @@ -43,3 +43,7 @@ def get_repository_api(repository: str) -> tuple[str, github.Github | None, str]
set_repositories_settings(config=config, apis_dict=apis_dict)
set_all_in_progress_check_runs_to_queued(repo_config=config, apis_dict=apis_dict)
create_webhook(config=config, apis_dict=apis_dict)


if __name__ == "__main__":
repository_and_webhook_settings()