-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.micro
More file actions
115 lines (96 loc) · 2.65 KB
/
Copy pathDockerfile.micro
File metadata and controls
115 lines (96 loc) · 2.65 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 微型镜像 - 目标<500MB
# Micro image targeting <500MB
FROM python:3.9-alpine
# 构建参数
ARG BUILDTIME
ARG VERSION
ARG REVISION
# 设置标签
LABEL org.opencontainers.image.created=${BUILDTIME}
LABEL org.opencontainers.image.version=${VERSION}
LABEL org.opencontainers.image.revision=${REVISION}
LABEL org.opencontainers.image.title="Invoice OCR System - Micro"
LABEL org.opencontainers.image.description="微型发票识别系统 - 无pandas/numpy"
# 安装系统依赖(包含EasyOCR编译所需)
RUN apk add --no-cache \
# 基础编译工具
gcc \
g++ \
musl-dev \
linux-headers \
make \
cmake \
# Python开发包
python3-dev \
# 图像处理库
jpeg-dev \
libpng-dev \
freetype-dev \
zlib-dev \
# EasyOCR依赖
libffi-dev \
openssl-dev \
# 运行时库
libjpeg-turbo \
libpng \
freetype \
zlib \
# 工具
curl \
ca-certificates \
git && \
rm -rf /var/cache/apk/*
# 创建用户
RUN addgroup -g 1000 appuser && \
adduser -D -s /bin/sh -u 1000 -G appuser appuser
# 设置工作目录
WORKDIR /app
# 升级pip并分步安装依赖
RUN pip install --no-cache-dir --upgrade pip setuptools wheel
# 安装基础依赖
RUN pip install --no-cache-dir \
fastapi==0.104.1 \
uvicorn==0.24.0 \
python-multipart==0.0.6 \
aiofiles==23.2.0 \
jinja2==3.1.2 \
pydantic==2.5.0 \
requests==2.31.0
# 安装图像处理依赖
RUN pip install --no-cache-dir \
pillow==10.1.0
# 安装PDF处理依赖
RUN pip install --no-cache-dir \
pdfplumber==0.10.3
# 安装OCR依赖(最后安装,因为最大)
RUN pip install --no-cache-dir \
easyocr==1.7.0
# 清理pip缓存
RUN pip cache purge && \
# 清理编译工具(保留运行时库)
apk del gcc g++ musl-dev linux-headers make cmake python3-dev \
jpeg-dev libpng-dev freetype-dev zlib-dev libffi-dev openssl-dev git
# 复制应用代码
COPY --chown=appuser:appuser app/ ./app/
COPY --chown=appuser:appuser run.py ./
# 创建必要目录
RUN mkdir -p /app/data /app/invoices/pdf /app/invoices/imge /app/invoices/unrecognized /app/logs && \
chown -R appuser:appuser /app
# 暴露端口
EXPOSE 8000
# 切换用户
USER appuser
# 设置环境变量
ENV PATH="/home/appuser/.local/bin:$PATH" \
PYTHONPATH=/app \
INVOICE_DIR=/app/invoices \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
OMP_NUM_THREADS=1 \
# 使用CSV存储
STORAGE_TYPE=csv
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8000/api/invoices/health || exit 1
# 启动命令
CMD ["python", "run.py"]