diff --git a/.gitea/workflows/package.yml b/.gitea/workflows/package.yml new file mode 100644 index 0000000..ade3d04 --- /dev/null +++ b/.gitea/workflows/package.yml @@ -0,0 +1,21 @@ +name: Server CI/CD v2 + +on: + push: + tags: + - "v*" + workflow_dispatch: {} + +jobs: + build-test-publish-and-deploy: + uses: OrgTJWater/ci-templates/.gitea/workflows/container-cd.yml@main + with: + image_name: gitea.waternetwork.cn/orgtjwater/tjwater-backend + dockerfile: Dockerfile + build_context: . + deploy_service: backend + deploy_host: 192.168.1.114 + secrets: + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + DEV_DEPLOY_SSH_KEY: ${{ secrets.DEV_DEPLOY_SSH_KEY }} diff --git a/Dockerfile b/Dockerfile index b2358ce..e2e530d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,4 +21,7 @@ ENV PYTHONPATH=/app EXPOSE 8000 +HEALTHCHECK --interval=10s --timeout=3s --start-period=30s --retries=6 \ + CMD python -c "from urllib.request import urlopen; urlopen('http://127.0.0.1:8000/health', timeout=2)" || exit 1 + CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"] diff --git a/app/main.py b/app/main.py index 153a447..074ee34 100644 --- a/app/main.py +++ b/app/main.py @@ -63,6 +63,11 @@ app = FastAPI( ) +@app.get("/health", include_in_schema=False) +async def health() -> dict[str, bool]: + return {"ok": True} + + # Include Routers app.include_router(api_router, prefix="/api/v1") # Legcy Routers without version prefix