From 413070a105dc59e8842fb97af530c3ef23ed239c Mon Sep 17 00:00:00 2001 From: Sayer Tindall <73977638+sayerrrr@users.noreply.github.com> Date: Tue, 13 May 2025 00:28:37 -0500 Subject: [PATCH 1/2] Add health check, rename --- Dockerfile | 55 +++++++++++++++++++++++++++++++++ config.yaml | 19 ++++++++++++ github_processor_node/config.py | 2 -- github_processor_node/server.py | 5 +++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 config.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4f3cb1b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +FROM python:3.12-slim AS build + +# Install build dependencies and UV +RUN apt-get update && \ + apt-get install -y build-essential curl && \ + pip install --no-cache-dir uv && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Copy only requirements file first to leverage Docker cache +COPY requirements.txt* ./ + +# Install dependencies using UV for faster installation +RUN if [ -f "requirements.txt" ]; then \ + uv pip install --system -r requirements.txt; \ + fi + +# Final stage +FROM python:3.12-slim + +# Accept module name and port as build arguments +ARG MODULE_NAME +ARG PORT=8011 + +# Set environment variables from build args +ENV PORT=$PORT +ENV MODULE_NAME=github_processor_node + +WORKDIR /app + +# Install only runtime dependencies (curl for healthcheck) +RUN apt-get update && \ + apt-get install -y curl && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Copy installed dependencies from build stage +COPY --from=build /usr/local/lib/python3.12/site-packages/ /usr/local/lib/python3.12/site-packages/ +COPY --from=build /usr/local/bin/ /usr/local/bin/ + +# Copy project files and source code +COPY . /app/ + +# Expose port for container +EXPOSE $PORT + +# Configure healthcheck +HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ + CMD curl --fail http://localhost:$PORT/health || exit 1 + +# Start server using environment variables +# The module name is used to determine which server module to load +CMD uvicorn github_processor_node.server:app --host 0.0.0.0 --port $PORT diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..2c7a3e0 --- /dev/null +++ b/config.yaml @@ -0,0 +1,19 @@ +server: + host: 127.0.0.1 + port: 8011 + path: /koi-net +koi_net: + node_name: github-processor + node_rid: orn:koi-net.node:github-processor+0bf78f28-9f56-4d31-8377-a33f49a0828e + node_profile: + base_url: http://github-processor:8011/koi-net + node_type: FULL + provides: + event: [] + state: [] + cache_directory_path: .koi/github-processor/cache + event_queues_path: .koi/github-processor/queues.json + first_contact: http://coordinator:8080/koi-net +index_db_path: .koi/github-processor/index.db +env: + github_token: GITHUB_TOKEN diff --git a/github_processor_node/config.py b/github_processor_node/config.py index e32081e..03039c0 100644 --- a/github_processor_node/config.py +++ b/github_processor_node/config.py @@ -3,8 +3,6 @@ from pydantic import Field - - class GitCredentialsEnvConfig(EnvConfig): """Environment variables configuration for Git credentials.""" github_token: str | None = "GITHUB_TOKEN" diff --git a/github_processor_node/server.py b/github_processor_node/server.py index 9cee610..bdf3b98 100644 --- a/github_processor_node/server.py +++ b/github_processor_node/server.py @@ -84,6 +84,11 @@ class StatusResponse(BaseModel): title="GitHub Processor API" ) +@app.get("/health", tags=["System"]) +async def health_check(): + """Basic health check for the service.""" + return {"status": "healthy", "node_id": str(node.identity.rid) if node.identity else "uninitialized"} + # Standard router for processor-specific endpoints router = APIRouter(prefix="/api/processor/github", tags=["GitHub Processor"]) From 864dac3421e775a3f2c413e3fba440c80a588d53 Mon Sep 17 00:00:00 2001 From: Sayer Tindall <73977638+sayerrrr@users.noreply.github.com> Date: Fri, 16 May 2025 15:48:07 -0500 Subject: [PATCH 2/2] Fix init logs --- github_processor_node/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_processor_node/__init__.py b/github_processor_node/__init__.py index d746aed..590b158 100644 --- a/github_processor_node/__init__.py +++ b/github_processor_node/__init__.py @@ -36,7 +36,7 @@ logger.addHandler(file_handler) logger.info( - f"Logging initialized for HackMD Processor Node. Level: {log_level.upper()}." + f"Logging initialized for Github Processor Node. Level: {log_level.upper()}." ) # Re-export the node instance