init commit
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
# Build stage
|
||||
FROM golang:1.24-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
RUN apk add --no-cache git build-base
|
||||
|
||||
# 通过构建参数接收敏感信息
|
||||
ARG GOPRIVATE_ARG
|
||||
ARG GOPROXY_ARG
|
||||
ARG GOSUMDB_ARG=off
|
||||
|
||||
# 设置Go环境变量
|
||||
ENV GOPRIVATE=${GOPRIVATE_ARG}
|
||||
ENV GOPROXY=${GOPROXY_ARG}
|
||||
ENV GOSUMDB=${GOSUMDB_ARG}
|
||||
|
||||
# Copy go mod and sum files
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
ENV CGO_ENABLED=1
|
||||
# Install migrate tool
|
||||
RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the application
|
||||
RUN make build-prod
|
||||
|
||||
# Final stage
|
||||
FROM alpine:3.17
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install runtime dependencies
|
||||
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/edge/main' > /etc/apk/repositories
|
||||
RUN apk update --allow-untrusted
|
||||
RUN apk upgrade --allow-untrusted
|
||||
RUN apk add --no-cache build-base postgresql17-client mysql-client ca-certificates tzdata sed curl bash supervisor vim wget curl --allow-untrusted
|
||||
|
||||
# Copy the binary from the builder stage
|
||||
COPY --from=builder /app/WeKnora .
|
||||
COPY --from=builder /app/config ./config
|
||||
COPY --from=builder /app/scripts ./scripts
|
||||
COPY --from=builder /app/migrations ./migrations
|
||||
COPY --from=builder /app/dataset/samples ./dataset/samples
|
||||
|
||||
# Copy migrate tool from builder stage
|
||||
COPY --from=builder /go/bin/migrate /usr/local/bin/
|
||||
COPY --from=builder /go/pkg/mod/github.com/yanyiwu /go/pkg/mod/github.com/yanyiwu/
|
||||
|
||||
# Make scripts executable
|
||||
RUN chmod +x ./scripts/*.sh
|
||||
|
||||
# Setup supervisor configuration
|
||||
RUN mkdir -p /etc/supervisor.d/
|
||||
COPY docker/config/supervisord.conf /etc/supervisor.d/supervisord.conf
|
||||
|
||||
# Expose ports
|
||||
EXPOSE 8080
|
||||
|
||||
# Set environment variables
|
||||
ENV CGO_ENABLED=1
|
||||
|
||||
# Create a non-root user and switch to it
|
||||
RUN mkdir -p /data/files && \
|
||||
adduser -D -g '' appuser && \
|
||||
chown -R appuser:appuser /app /data/files
|
||||
|
||||
# Run supervisor instead of direct application start
|
||||
CMD ["supervisord", "-c", "/etc/supervisor.d/supervisord.conf"]
|
||||
# CMD ["sh", "/app/scripts/start_app.sh"]
|
||||
# CMD ["sleep", "infinity"]
|
||||
@@ -0,0 +1,132 @@
|
||||
ARG PLATFORM=linux/amd64
|
||||
|
||||
# 构建阶段
|
||||
FROM --platform=${PLATFORM} python:3.9-slim AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 安装构建依赖
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gcc \
|
||||
python3-dev \
|
||||
libjpeg-dev \
|
||||
zlib1g-dev \
|
||||
libpq-dev \
|
||||
libffi-dev \
|
||||
libgl1-mesa-glx \
|
||||
libglib2.0-0 \
|
||||
wget \
|
||||
antiword \
|
||||
curl \
|
||||
unzip \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 安装 protoc
|
||||
RUN curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-linux-x86_64.zip && \
|
||||
unzip protoc-3.19.4-linux-x86_64.zip -d /usr/local && \
|
||||
chmod +x /usr/local/bin/protoc && \
|
||||
rm protoc-3.19.4-linux-x86_64.zip
|
||||
|
||||
# 复制依赖文件
|
||||
COPY services/docreader/requirements.txt .
|
||||
|
||||
# 安装依赖
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# 预下载 PP-OCRv5 模型
|
||||
RUN mkdir -p /root/.paddlex/official_models
|
||||
|
||||
RUN wget https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/PP-OCRv5_server_det_infer.tar \
|
||||
-O /root/.paddlex/official_models/PP-OCRv5_server_det_infer.tar && \
|
||||
wget https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0.0/PP-OCRv5_server_rec_infer.tar \
|
||||
-O /root/.paddlex/official_models/PP-OCRv5_server_rec_infer.tar
|
||||
|
||||
# 解压模型文件
|
||||
RUN tar -xf /root/.paddlex/official_models/PP-OCRv5_server_det_infer.tar -C /root/.paddlex/official_models/ && \
|
||||
tar -xf /root/.paddlex/official_models/PP-OCRv5_server_rec_infer.tar -C /root/.paddlex/official_models/
|
||||
|
||||
# 复制源代码和生成脚本
|
||||
COPY services/docreader/src/ /app/src/
|
||||
COPY services/docreader/scripts/ /app/scripts/
|
||||
|
||||
# 使用正确的Python模块路径运行ocr.py
|
||||
# RUN cd /app && PYTHONPATH=/app python -m src.parser.ocr
|
||||
|
||||
# 确保模型目录存在
|
||||
RUN ls -la /root/.paddlex/official_models
|
||||
|
||||
# 生成 protobuf 代码
|
||||
RUN chmod +x /app/scripts/generate_proto.sh && /app/scripts/generate_proto.sh
|
||||
|
||||
# 运行阶段
|
||||
FROM --platform=${PLATFORM} python:3.9-slim AS runner
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 安装运行时依赖
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libjpeg62-turbo \
|
||||
libpq5 \
|
||||
wget \
|
||||
gnupg \
|
||||
libgl1-mesa-glx \
|
||||
libglib2.0-0 \
|
||||
antiword \
|
||||
supervisor \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 安装所需依赖
|
||||
RUN apt-get update && apt-get install -y \
|
||||
wget \
|
||||
vim \
|
||||
tar \
|
||||
dpkg \
|
||||
libxinerama1 \
|
||||
libfontconfig1 \
|
||||
libdbus-glib-1-2 \
|
||||
libcairo2 \
|
||||
libcups2 \
|
||||
libglu1-mesa \
|
||||
libsm6 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 下载并安装最新版本的 LibreOffice 25.2.4
|
||||
RUN mkdir -p /tmp/libreoffice && \
|
||||
cd /tmp/libreoffice && \
|
||||
wget -q https://mirrors.tuna.tsinghua.edu.cn/libreoffice/libreoffice/stable/25.2.4/deb/x86_64/LibreOffice_25.2.4_Linux_x86-64_deb.tar.gz && \
|
||||
tar -xzf LibreOffice_25.2.4_Linux_x86-64_deb.tar.gz && \
|
||||
cd LibreOffice_25.2.4*_Linux_x86-64_deb/DEBS && \
|
||||
dpkg -i *.deb && \
|
||||
cd / && \
|
||||
rm -rf /tmp/libreoffice
|
||||
|
||||
# 设置 LibreOffice 环境变量
|
||||
ENV LIBREOFFICE_PATH=/opt/libreoffice25.2/program/soffice
|
||||
|
||||
# 从构建阶段复制已安装的依赖和生成的代码
|
||||
COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
|
||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||
|
||||
# 复制 PaddleOCR 模型到运行阶段
|
||||
COPY --from=builder /root/.paddlex/official_models /root/.paddlex/official_models
|
||||
|
||||
# 安装 Playwright 浏览器
|
||||
RUN python -m playwright install webkit
|
||||
RUN python -m playwright install-deps webkit
|
||||
|
||||
COPY --from=builder /app/src /app/src
|
||||
|
||||
# 设置 Python 路径
|
||||
ENV PYTHONPATH=/app/src
|
||||
|
||||
RUN cd /app/src && python -m download_deps
|
||||
|
||||
# 创建supervisor配置
|
||||
RUN mkdir -p /etc/supervisor/conf.d
|
||||
COPY services/docreader/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
|
||||
# 暴露 gRPC 端口
|
||||
EXPOSE 50051
|
||||
|
||||
# 使用supervisor启动服务
|
||||
CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
||||
@@ -0,0 +1,31 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
logfile=/var/log/supervisord.log
|
||||
logfile_maxbytes=50MB
|
||||
logfile_backups=10
|
||||
loglevel=info
|
||||
pidfile=/var/run/supervisord.pid
|
||||
user=root
|
||||
|
||||
[program:WeKnora]
|
||||
command=/app/WeKnora
|
||||
directory=/app
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=5
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/WeKnora.log
|
||||
stdout_logfile_maxbytes=50MB
|
||||
stdout_logfile_backups=10
|
||||
environment=CGO_ENABLED=1
|
||||
user=appuser
|
||||
|
||||
[unix_http_server]
|
||||
file=/var/run/supervisor.sock
|
||||
chmod=0700
|
||||
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///var/run/supervisor.sock
|
||||
@@ -0,0 +1,29 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
container_name: WeKnora-minio
|
||||
ports:
|
||||
- "9000:9000"
|
||||
- "9001:9001"
|
||||
volumes:
|
||||
- minio-data:/data
|
||||
environment:
|
||||
- MINIO_ROOT_USER=${MINIO_ACCESS_KEY_ID}
|
||||
- MINIO_ROOT_PASSWORD=${MINIO_SECRET_ACCESS_KEY}
|
||||
command: server --console-address ":9001" /data
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
|
||||
interval: 30s
|
||||
timeout: 20s
|
||||
retries: 3
|
||||
networks:
|
||||
- WeKnora-network
|
||||
|
||||
volumes:
|
||||
minio-data:
|
||||
|
||||
networks:
|
||||
WeKnora-network:
|
||||
external: true
|
||||
Reference in New Issue
Block a user