feat: implement lab3 API load balancing and failover

This commit is contained in:
sashadugina06
2026-11-06 01:43:33 +03:00
parent 0ab3a341aa
commit 7088791d5c
116 changed files with 7971 additions and 38 deletions
+30
View File
@@ -0,0 +1,30 @@
FROM python:3.11.16-slim-bookworm
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV APP_HOST=0.0.0.0
ENV APP_PORT=8080
WORKDIR /app
COPY requirements.txt .
RUN python -m pip install --no-cache-dir -r requirements.txt
RUN useradd --uid 10001 --create-home --shell /usr/sbin/nologin appuser
COPY --chown=appuser:appuser src/ ./src/
COPY --chown=appuser:appuser db/ ./db/
COPY --chown=appuser:appuser contracts/openapi.json ./contracts/openapi.json
USER appuser
EXPOSE 8080
STOPSIGNAL SIGTERM
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 CMD python -c "import os,urllib.request; urllib.request.urlopen('http://127.0.0.1:' + os.getenv('APP_PORT', '8080') + '/health/ready', timeout=2).read()"
CMD ["python", "-m", "uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8080", "--timeout-graceful-shutdown", "4", "--timeout-keep-alive", "2"]