Fix circular imports. Fix force recreate nginx after rebuild services.
This commit is contained in:
parent
d1bbaf8da3
commit
569a452bb6
5 changed files with 28 additions and 11 deletions
10
deploy/nginx/Dockerfile
Normal file
10
deploy/nginx/Dockerfile
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# Edge nginx image: bake the TLS template so that template changes produce a
|
||||||
|
# new image and `docker compose up -d --build` recreates the container.
|
||||||
|
# (With a bind-mounted template, envsubst renders only at container start and
|
||||||
|
# compose never recreates on file-content changes — forcing --force-recreate.)
|
||||||
|
#
|
||||||
|
# Baking exactly ONE template: rendering both would duplicate `upstream api`.
|
||||||
|
# The VPS override (deploy/vps/) shadows this file by bind-mounting
|
||||||
|
# contract-check-http.conf.template at the same target path.
|
||||||
|
FROM nginx:alpine
|
||||||
|
COPY templates/contract-check.conf.template /etc/nginx/templates/contract-check.conf.template
|
||||||
|
|
@ -11,6 +11,7 @@ services:
|
||||||
ports: !override
|
ports: !override
|
||||||
- "127.0.0.1:8081:80"
|
- "127.0.0.1:8081:80"
|
||||||
volumes: !override
|
volumes: !override
|
||||||
# Same target path as the base file's TLS template bind — overrides it,
|
# Shadows the TLS template baked into the image (deploy/nginx/Dockerfile)
|
||||||
# so only ONE template is rendered (both define `upstream api`).
|
# at the same target path, so only ONE template is rendered (both define
|
||||||
|
# `upstream api`). HTTP-only: the host front.conf terminates TLS.
|
||||||
- ./deploy/nginx/templates/contract-check-http.conf.template:/etc/nginx/templates/contract-check.conf.template:ro
|
- ./deploy/nginx/templates/contract-check-http.conf.template:/etc/nginx/templates/contract-check.conf.template:ro
|
||||||
|
|
|
||||||
|
|
@ -299,16 +299,22 @@ services:
|
||||||
# /api/v1/*, /admin/*, /metrics, /healthz, /readyz to the api service.
|
# /api/v1/*, /admin/*, /metrics, /healthz, /readyz to the api service.
|
||||||
nginx:
|
nginx:
|
||||||
profiles: ["edge"]
|
profiles: ["edge"]
|
||||||
image: nginx:alpine
|
# The conf template is BAKED into this image (deploy/nginx/Dockerfile), so
|
||||||
|
# template edits → new image → `up -d --build` recreates and re-renders it.
|
||||||
|
# The VPS override (deploy/vps/) swaps in contract-check-http.conf.template
|
||||||
|
# via a bind mount at the same target path.
|
||||||
|
build:
|
||||||
|
context: ./deploy/nginx
|
||||||
|
dockerfile: Dockerfile
|
||||||
container_name: contract_check-nginx
|
container_name: contract_check-nginx
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
api:
|
||||||
|
condition: service_healthy
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
- "443:443"
|
- "443:443"
|
||||||
volumes:
|
volumes:
|
||||||
# Mount exactly ONE template — rendering both would duplicate `upstream api`.
|
|
||||||
# The VPS override (deploy/vps/) swaps in contract-check-http.conf.template here.
|
|
||||||
- ./deploy/nginx/templates/contract-check.conf.template:/etc/nginx/templates/contract-check.conf.template:ro
|
|
||||||
- certbot-data:/etc/letsencrypt:ro
|
- certbot-data:/etc/letsencrypt:ro
|
||||||
- certbot-webroot:/var/www/certbot:ro
|
- certbot-webroot:/var/www/certbot:ro
|
||||||
environment:
|
environment:
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ from __future__ import annotations
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from ..logging import get_logger
|
from ..logging import get_logger
|
||||||
from .extractor import ExtractionError
|
|
||||||
|
|
||||||
log = get_logger(__name__)
|
log = get_logger(__name__)
|
||||||
|
|
||||||
|
|
@ -57,6 +56,11 @@ def ocr_pdf(path: str | Path, *, lang: str = "rus+eng") -> str:
|
||||||
|
|
||||||
stripped = "\n".join(parts).strip()
|
stripped = "\n".join(parts).strip()
|
||||||
if len(stripped) < 100:
|
if len(stripped) < 100:
|
||||||
|
# Imported lazily: `analysis.extractor` imports `extraction.formats`,
|
||||||
|
# whose package init used to import this module — a module-level
|
||||||
|
# import here would close a circular-import chain.
|
||||||
|
from .extractor import ExtractionError
|
||||||
|
|
||||||
raise ExtractionError(
|
raise ExtractionError(
|
||||||
f"OCR тоже дал мало текста ({len(stripped)} симв.). "
|
f"OCR тоже дал мало текста ({len(stripped)} симв.). "
|
||||||
"Файл, видимо, не содержит распознаваемого текста."
|
"Файл, видимо, не содержит распознаваемого текста."
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ it in the factory — no domain/pipeline changes.
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from ..analysis.ocr import OCRError as _OCRError # re-export for classify()
|
|
||||||
from .adapters.docx_mammoth import MammothDocxExtractor
|
from .adapters.docx_mammoth import MammothDocxExtractor
|
||||||
from .adapters.ocr_tesseract import TesseractOcrExtractor
|
from .adapters.ocr_tesseract import TesseractOcrExtractor
|
||||||
from .adapters.pdf_pymupdf import PyMuPDFExtractor
|
from .adapters.pdf_pymupdf import PyMuPDFExtractor
|
||||||
|
|
@ -41,9 +40,6 @@ __all__ = [
|
||||||
"get_factory",
|
"get_factory",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Re-exported under its canonical name (imported by worker_extract.handler.classify).
|
|
||||||
OCRError = _OCRError
|
|
||||||
|
|
||||||
|
|
||||||
def extract_document(data: bytes, *, mime: str = "", filename: str = "") -> ExtractedDocument:
|
def extract_document(data: bytes, *, mime: str = "", filename: str = "") -> ExtractedDocument:
|
||||||
"""High-level entry: pick adapter → extract → OCR fallback for scans.
|
"""High-level entry: pick adapter → extract → OCR fallback for scans.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue