Docker: фикс прав на /srv/.cache для appuser; X-Trace-Id в раннем 413

This commit is contained in:
2026-10-07 14:27:31 +03:00
parent 7ee49e8c9f
commit 7002c496dc
2 changed files with 6 additions and 1 deletions
+3
View File
@@ -27,6 +27,9 @@ WORKDIR /srv
COPY --from=builder /install /usr/local COPY --from=builder /install /usr/local
COPY app ./app COPY app ./app
# /srv принадлежит root: кэш под веса создаём и передаём appuser до USER
RUN mkdir -p /srv/.cache/torch && chown -R appuser:appuser /srv
USER appuser USER appuser
# Кэш torch.hub (код dinov2 + веса ~84 МБ) запекаем в образ: # Кэш torch.hub (код dinov2 + веса ~84 МБ) запекаем в образ:
+3 -1
View File
@@ -105,12 +105,14 @@ def _register_middleware(app: FastAPI) -> None:
content_length = request.headers.get("Content-Length") content_length = request.headers.get("Content-Length")
limit = app.state.config.max_body_bytes limit = app.state.config.max_body_bytes
if content_length and content_length.isdigit() and int(content_length) > limit: if content_length and content_length.isdigit() and int(content_length) > limit:
return error_response( response = error_response(
413, 413,
"PAYLOAD_TOO_LARGE", "PAYLOAD_TOO_LARGE",
f"тело запроса {content_length} байт, максимум {limit}", f"тело запроса {content_length} байт, максимум {limit}",
request.state.trace_id, request.state.trace_id,
) )
response.headers["X-Trace-Id"] = request.state.trace_id
return response
started = time.perf_counter() started = time.perf_counter()
response = await call_next(request) response = await call_next(request)
response.headers["X-Trace-Id"] = request.state.trace_id response.headers["X-Trace-Id"] = request.state.trace_id