From 7002c496dc1d8817f58cf8055a2df900212472ea Mon Sep 17 00:00:00 2001 From: bukan Date: Wed, 7 Oct 2026 14:27:31 +0300 Subject: [PATCH] =?UTF-8?q?Docker:=20=D1=84=D0=B8=D0=BA=D1=81=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=20=D0=BD=D0=B0=20/srv/.cache=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20appuser;=20X-Trace-Id=20=D0=B2=20=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D0=B5=D0=BC=20413?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 +++ app/main.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6c58f06..74904b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,9 @@ WORKDIR /srv COPY --from=builder /install /usr/local COPY app ./app +# /srv принадлежит root: кэш под веса создаём и передаём appuser до USER +RUN mkdir -p /srv/.cache/torch && chown -R appuser:appuser /srv + USER appuser # Кэш torch.hub (код dinov2 + веса ~84 МБ) запекаем в образ: diff --git a/app/main.py b/app/main.py index c9f15d4..9512d49 100644 --- a/app/main.py +++ b/app/main.py @@ -105,12 +105,14 @@ def _register_middleware(app: FastAPI) -> None: content_length = request.headers.get("Content-Length") limit = app.state.config.max_body_bytes if content_length and content_length.isdigit() and int(content_length) > limit: - return error_response( + response = error_response( 413, "PAYLOAD_TOO_LARGE", f"тело запроса {content_length} байт, максимум {limit}", request.state.trace_id, ) + response.headers["X-Trace-Id"] = request.state.trace_id + return response started = time.perf_counter() response = await call_next(request) response.headers["X-Trace-Id"] = request.state.trace_id