Initial curated ITWorx_MCP_Hub source from 368fba691ea8d23403b4d56b53b5ec670d7c5020
This commit is contained in:
commit
cb5be898ea
663 files changed
+82674
No files matched your search
@@ -0,0 +1,58 @@
|
||||
# syntax=docker/dockerfile:1.7
|
||||
FROM node:24.18.1-bookworm-slim@sha256:235600a8101ab264e117b1768e925532262668dc9b581ef1dd7d96ced463b8e7 AS web-build
|
||||
|
||||
WORKDIR /workspace
|
||||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
||||
COPY apps/web/package.json apps/web/package.json
|
||||
COPY packages/ui/package.json packages/ui/package.json
|
||||
RUN npm install --global pnpm@10.33.0 \
|
||||
&& pnpm install --frozen-lockfile --filter @itworx-mcp-hub/web...
|
||||
COPY apps/web apps/web
|
||||
RUN pnpm --filter @itworx-mcp-hub/web build
|
||||
|
||||
FROM python:3.13.14-slim@sha256:6771159cd4fa5d9bba1258caf0b82e6b73458c694d178ad97c5e925c2d0e1a91
|
||||
|
||||
COPY infrastructure/images/install-base-security-updates.sh /tmp/install-base-security-updates.sh
|
||||
RUN sh /tmp/install-base-security-updates.sh \
|
||||
&& rm /tmp/install-base-security-updates.sh
|
||||
|
||||
ARG SERVICE_NAME=itworx-mcp-hub-service
|
||||
ARG GIT_REVISION
|
||||
ARG SOURCE_DATE_EPOCH
|
||||
ARG BUILD_DATE
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PATH=/opt/venv/bin:$PATH \
|
||||
SERVICE_NAME=${SERVICE_NAME}
|
||||
|
||||
RUN groupadd --gid 10001 hub \
|
||||
&& useradd --uid 10001 --gid 10001 --create-home --shell /usr/sbin/nologin hub
|
||||
|
||||
COPY pyproject.toml uv.lock /opt/hub/
|
||||
RUN python -m pip install --no-cache-dir uv==0.10.0 \
|
||||
&& cd /opt/hub \
|
||||
&& UV_PROJECT_ENVIRONMENT=/opt/venv uv sync --locked --no-dev --no-install-project \
|
||||
&& /usr/local/bin/python -m pip uninstall --yes uv
|
||||
|
||||
COPY packages /opt/hub/packages
|
||||
COPY services /opt/hub/services
|
||||
COPY scripts /opt/hub/scripts
|
||||
COPY connectors /opt/hub/connectors
|
||||
COPY catalog /opt/hub/catalog
|
||||
COPY contracts /opt/hub/contracts
|
||||
COPY plugins/itworx-gitea /opt/hub/plugins/itworx-gitea
|
||||
COPY infrastructure/database /opt/hub/infrastructure/database
|
||||
COPY --from=web-build /workspace/apps/web/dist /opt/hub/web-dist
|
||||
RUN chown -R 10001:10001 /opt/hub
|
||||
|
||||
LABEL org.opencontainers.image.title="itworx-mcp-hub-${SERVICE_NAME}" \
|
||||
org.opencontainers.image.revision="${GIT_REVISION}" \
|
||||
org.opencontainers.image.source="https://gitea.example.com/jens/itworx-mcp-hub" \
|
||||
org.opencontainers.image.created="${BUILD_DATE}" \
|
||||
org.opencontainers.image.vendor="ITWorx"
|
||||
|
||||
WORKDIR /opt/hub
|
||||
USER 10001:10001
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["python", "-m", "services.runtime"]
|
||||
@@ -0,0 +1,129 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from http import HTTPStatus
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
|
||||
from packages.hub_observability import build_telemetry, trace_from_headers, valid_trace_id
|
||||
from packages.hub_runtime.secret_files import SecretFileError, validate_required_secret_paths
|
||||
from services.observability.health import DependencyHealth, aggregate_health
|
||||
|
||||
|
||||
def _validate_startup() -> None:
|
||||
try:
|
||||
validate_required_secret_paths(os.environ.get("REQUIRED_SECRET_FILES", ""))
|
||||
except (SecretFileError, ValueError):
|
||||
sys.stderr.write("required runtime secret validation failed\n")
|
||||
raise SystemExit(78) from None
|
||||
|
||||
|
||||
_validate_startup()
|
||||
|
||||
_telemetry = build_telemetry(os.environ.get("SERVICE_NAME", "unknown"))
|
||||
|
||||
|
||||
def _trace_id(handler: BaseHTTPRequestHandler) -> str:
|
||||
candidate = handler.headers.get("X-Trace-Id", "")
|
||||
if valid_trace_id(candidate):
|
||||
return candidate.lower()
|
||||
return trace_from_headers({"traceparent": handler.headers.get("traceparent", "")}).trace_id
|
||||
|
||||
|
||||
def _dependencies() -> list[DependencyHealth]:
|
||||
raw = os.environ.get("DEPENDENCY_HEALTH_JSON", "")
|
||||
if not raw:
|
||||
return [DependencyHealth(os.environ.get("SERVICE_NAME", "unknown"), "healthy")]
|
||||
try:
|
||||
document = json.loads(raw)
|
||||
except ValueError:
|
||||
return [
|
||||
DependencyHealth(
|
||||
"configuration", "unhealthy", detail="invalid dependency health configuration"
|
||||
)
|
||||
]
|
||||
if not isinstance(document, dict):
|
||||
return [
|
||||
DependencyHealth(
|
||||
"configuration", "unhealthy", detail="dependency health must be an object"
|
||||
)
|
||||
]
|
||||
values = []
|
||||
for name, value in document.items():
|
||||
if not isinstance(value, dict):
|
||||
continue
|
||||
values.append(
|
||||
DependencyHealth(
|
||||
str(name)[:64],
|
||||
str(value.get("status", "unknown")),
|
||||
bool(value.get("required", True)),
|
||||
bool(value.get("authoritative", True)),
|
||||
str(value.get("detail", "")),
|
||||
)
|
||||
)
|
||||
return values or [
|
||||
DependencyHealth("configuration", "unhealthy", detail="no dependencies configured")
|
||||
]
|
||||
|
||||
|
||||
class HealthHandler(BaseHTTPRequestHandler):
|
||||
server_version = "ITWorxHealth/0.2"
|
||||
|
||||
def do_GET(self) -> None: # noqa: N802
|
||||
trace_id = _trace_id(self)
|
||||
if self.path == "/metrics":
|
||||
body = _telemetry.metrics.render_prometheus().encode("utf-8")
|
||||
self._write(HTTPStatus.OK, body, "text/plain; version=0.0.4", trace_id)
|
||||
return
|
||||
if self.path == "/health/aggregate":
|
||||
aggregate = aggregate_health(_dependencies())
|
||||
status = (
|
||||
HTTPStatus.OK if aggregate.status != "unhealthy" else HTTPStatus.SERVICE_UNAVAILABLE
|
||||
)
|
||||
self._write_json(
|
||||
status,
|
||||
aggregate.payload(
|
||||
service=os.environ.get("SERVICE_NAME", "unknown"), trace_id=trace_id
|
||||
),
|
||||
trace_id,
|
||||
)
|
||||
return
|
||||
if self.path not in {"/health", "/healthz", "/ready"}:
|
||||
self.send_error(HTTPStatus.NOT_FOUND)
|
||||
return
|
||||
_telemetry.metrics.inc("itworx_health_requests_total", labels={"path": self.path})
|
||||
_telemetry.logger.emit("HEALTH_REQUEST", trace_id, fields={"path": self.path})
|
||||
self._write_json(
|
||||
HTTPStatus.OK,
|
||||
{
|
||||
"status": "ok",
|
||||
"service": os.environ.get("SERVICE_NAME", "unknown"),
|
||||
"traceId": trace_id,
|
||||
},
|
||||
trace_id,
|
||||
)
|
||||
|
||||
def _write_json(self, status: HTTPStatus, payload: dict[str, object], trace_id: str) -> None:
|
||||
self._write(
|
||||
status,
|
||||
json.dumps(payload, separators=(",", ":")).encode("utf-8"),
|
||||
"application/json",
|
||||
trace_id,
|
||||
)
|
||||
|
||||
def _write(self, status: HTTPStatus, body: bytes, content_type: str, trace_id: str) -> None:
|
||||
self.send_response(status)
|
||||
self.send_header("Content-Type", content_type)
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.send_header("X-Trace-Id", trace_id)
|
||||
self.end_headers()
|
||||
if body:
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, _format: str, *_args: object) -> None:
|
||||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ThreadingHTTPServer(("0.0.0.0", 8080), HealthHandler).serve_forever() # noqa: S104
|
||||
Reference in new issue
Block a user