diff --git a/Dockerfile b/Dockerfile index 4c9aa96..d267347 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,16 @@ -# docker build . --platform linux/amd64 --push -t leafdev.top/models/nailong-detector:v0.0.2 +# docker build . --platform linux/amd64 --push -t leafdev.top/leaf/icp-api:v0.0.1 #FROM python:3.12.7 FROM docker.io/pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime -# WORKDIR /app COPY requirements.txt /app RUN pip install --no-cache-dir --upgrade -r requirements.txt -RUN apt update && apt-get install ffmpeg libsm6 libxext6 -y -RUN rm -rf /var/cache/apt/archives /var/lib/apt/lists/*. -# + +# 移除 onnxruntime 并重新安装 +RUN pip uninstall onnxruntime onnxruntime-gpu -y && pip install onnxruntime-gpu + +# 拷贝剩下的文件 COPY . /app # diff --git a/main.py b/main.py index 4eb63e4..22023da 100644 --- a/main.py +++ b/main.py @@ -3,21 +3,20 @@ import json import requests import hashlib import time -import os from urllib import parse import uuid from fastapi import FastAPI, HTTPException, Query -from fastapi.responses import JSONResponse -from pydantic import BaseModel, Field -from typing import List, Optional +import uvicorn from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend +from pydantic import BaseModel +from starlette import status + from detect import Detect import functools import logging from models import QueryResponse from cache import save_to_cache, load_from_cache -import random import re # 配置日志 @@ -52,6 +51,31 @@ app = FastAPI( version="1.0.0" ) +class HealthCheck(BaseModel): + """Response model to validate and return when performing a health check.""" + + status: str = "OK" +@app.get( + "/health", + tags=["healthcheck"], + summary="Perform a Health Check", + response_description="Return HTTP Status Code 200 (OK)", + status_code=status.HTTP_200_OK, + response_model=HealthCheck, +) +def get_health() -> HealthCheck: + """ + ## Perform a Health Check + Endpoint to perform a healthcheck on. This endpoint can primarily be used Docker + to ensure a robust container orchestration and management is in place. Other + services which rely on proper functioning of the API service will not deploy if this + endpoint returns any other HTTP status code except 200 (OK). + Returns: + HealthCheck: Returns a JSON response with the health status + """ + return HealthCheck(status="OK") + + @retry_with_backoff(retries=3) def auth(): @@ -314,5 +338,4 @@ async def query_api( raise HTTPException(status_code=500, detail=str(e)) if __name__ == "__main__": - import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000) \ No newline at end of file diff --git a/manifest.yaml b/manifest.yaml new file mode 100644 index 0000000..d1214cf --- /dev/null +++ b/manifest.yaml @@ -0,0 +1,67 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: icp-api + namespace: tool-apis +spec: + selector: + matchLabels: + app: icp-api + tier: backend + template: + metadata: + labels: + app: icp-api + tier: backend + spec: + imagePullSecrets: + - name: registry-secret + runtimeClassName: "nvidia" + containers: + - name: icp-api + image: leafdev.top/leaf/icp-api:v0.0.1 + ports: + - containerPort: 80 + protocol: TCP + name: http + readinessProbe: + httpGet: + path: /health + port: 80 + initialDelaySeconds: 5 + resources: + limits: + nvidia.com/gpu: "1" + nvidia.com/gpumem: "1000" +--- +apiVersion: v1 +kind: Service +metadata: + name: icp-api + namespace: tool-apis +spec: + selector: + app: icp-api + tier: backend + type: ClusterIP + ports: + - port: 80 + targetPort: 80 + protocol: TCP + name: http +--- +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: icp-api-http + namespace: tool-apis +spec: + hostnames: + - icp-api-testing.leaflow.cn + parentRefs: + - name: http-gw + namespace: networking + rules: + - backendRefs: + - name: icp-api + port: 80 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 0a86692..afa57c6 100644 Binary files a/requirements.txt and b/requirements.txt differ