File size: 3,212 Bytes
be4a6f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# ─────────────────────────────────────────────────────
# OneOCR on Linux — Dockerfile
# 
# Uses Wine to run the native Windows DLL on Linux.
# Result: 100% accuracy (identical to Windows DLL).
#
# Build:
#   docker build -t oneocr .
#
# Run OCR on a single image:
#   docker run --rm -v $(pwd)/working_space:/data oneocr \
#     python main.py --image /data/input/test.png --output /data/output/
#
# Interactive:
#   docker run --rm -it -v $(pwd)/working_space:/data oneocr bash
# ─────────────────────────────────────────────────────

FROM ubuntu:24.04

LABEL maintainer="MattyMroz"
LABEL description="OneOCR — Windows DLL on Linux via Wine (100% accuracy)"

# Avoid interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
ENV WINEDEBUG=-all

# ── 1. Install Wine + MinGW cross-compiler ─────────
RUN dpkg --add-architecture amd64 && \
    apt-get update && \
    apt-get install -y --no-install-recommends \
        wine64 \
        wine \
        mingw-w64 \
        python3 \
        python3-pip \
        python3-venv \
        python3-dev \
        && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# ── 2. Initialize Wine prefix (64-bit) ────────────
RUN WINEPREFIX=/root/.wine WINEARCH=win64 wineboot --init 2>/dev/null; \
    sleep 2

# ── 3. Copy project ───────────────────────────────
WORKDIR /app
COPY . /app/

# ── 4. Install Python dependencies ────────────────
RUN python3 -m venv /app/.venv && \
    /app/.venv/bin/pip install --no-cache-dir \
        pillow \
        numpy \
        onnxruntime

# ── 5. Cross-compile Wine loader ──────────────────
RUN x86_64-w64-mingw32-gcc -O2 \
    -o /app/tools/oneocr_loader.exe \
    /app/tools/oneocr_loader.c \
    || echo "Will compile on first run"

# ── 6. Write the C source for compilation ─────────
RUN /app/.venv/bin/python -c "\
from tools.wine_bridge import WINE_LOADER_C; \
from pathlib import Path; \
Path('/app/tools/oneocr_loader.c').write_text(WINE_LOADER_C)" && \
    x86_64-w64-mingw32-gcc -O2 \
    -o /app/tools/oneocr_loader.exe \
    /app/tools/oneocr_loader.c \
    2>/dev/null || true

# ── 7. Environment ────────────────────────────────
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONPATH="/app"

# ── 8. Healthcheck ────────────────────────────────
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
    CMD python3 -c "from tools.wine_bridge import WineBridge; \
                     b = WineBridge(); c = b.check_requirements(); \
                     exit(0 if c.get('wine_found') else 1)"

# ── Default command ───────────────────────────────
CMD ["python3", "main.py", "--help"]