feat: add production Docker deployment

This commit is contained in:
2026-07-20 13:29:24 +08:00
parent 75abc7bfe1
commit 70e97ae8b9
5 changed files with 145 additions and 8 deletions

View File

@@ -1,18 +1,22 @@
FROM python:3.10-slim
ARG DEBIAN_MIRROR=http://deb.debian.org
ARG PYPI_INDEX_URL=https://pypi.org/simple
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1
RUN apt-get update \
RUN sed -i "s|http://deb.debian.org|${DEBIAN_MIRROR}|g" /etc/apt/sources.list.d/debian.sources \
&& apt-get update \
&& apt-get install -y --no-install-recommends ffmpeg libsndfile1 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt ./
RUN pip install --upgrade pip \
&& pip install torch==2.8.0 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cpu \
&& pip install -r requirements.txt
RUN pip install --index-url "${PYPI_INDEX_URL}" --upgrade pip
RUN pip install torch==2.8.0 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cpu
RUN pip install --index-url "${PYPI_INDEX_URL}" -r requirements.txt
COPY app.py ./

84
compose.deploy.yml Normal file
View File

@@ -0,0 +1,84 @@
name: teaching-feedback
x-api-base: &api-base
image: teaching-feedback-api:0.1.0
services:
funasr:
image: teaching-feedback-funasr:1.0.0
build:
context: ./asr-service
dockerfile: Dockerfile
args:
DEBIAN_MIRROR: http://mirrors.ustc.edu.cn
PYPI_INDEX_URL: https://mirrors.ustc.edu.cn/pypi/simple
environment:
ASR_MODEL: paraformer-zh
ASR_VAD_MODEL: fsmn-vad
ASR_PUNC_MODEL: ct-punc
ASR_DEVICE: cpu
ASR_MAX_CONCURRENCY: "1"
ASR_BATCH_SIZE_SECONDS: "300"
MODELSCOPE_CACHE: /models
volumes:
- funasr-model-cache:/models
restart: unless-stopped
init: true
healthcheck:
test:
- CMD
- python
- -c
- "import urllib.request; urllib.request.urlopen('http://127.0.0.1:10095/health', timeout=3)"
interval: 15s
timeout: 5s
retries: 80
start_period: 10m
shm_size: 1gb
migrate:
<<: *api-base
env_file:
- ./server/.env
command:
- migrate
restart: "no"
healthcheck:
disable: true
api:
<<: *api-base
build:
context: ./server
dockerfile: Dockerfile
args:
DEBIAN_MIRROR: http://mirrors.ustc.edu.cn
env_file:
- ./server/.env
environment:
HOST: 0.0.0.0
PORT: "8080"
AUDIO_STORAGE_DIR: /data/audio
ASR_PROVIDER: local
LOCAL_ASR_URL: http://funasr:10095
ASR_REQUEST_TIMEOUT_SECONDS: "1800"
ASR_WORKER_CONCURRENCY: "1"
ASR_JOB_LEASE_SECONDS: "3600"
DATABASE_MAX_CONNECTIONS: "5"
ports:
- "39180:8080"
volumes:
- audio-data:/data/audio
restart: unless-stopped
init: true
depends_on:
migrate:
condition: service_completed_successfully
funasr:
condition: service_healthy
volumes:
funasr-model-cache:
name: teaching-feedback-funasr-model-cache
audio-data:
name: teaching-feedback-audio

9
server/.dockerignore Normal file
View File

@@ -0,0 +1,9 @@
.env
.env.*
!.env.example
target/
data/
graphify-out/
API.md
API_GUIDE.md
*.log

40
server/Dockerfile Normal file
View File

@@ -0,0 +1,40 @@
FROM rust:1.85-bookworm AS builder
WORKDIR /build
COPY Cargo.toml Cargo.lock ./
COPY migrations ./migrations
COPY src ./src
RUN cargo build --locked --release \
--bin teaching-feedback-api \
--bin migrate
FROM debian:bookworm-slim AS runtime
ARG DEBIAN_MIRROR=http://deb.debian.org
RUN sed -i "s|http://deb.debian.org|${DEBIAN_MIRROR}|g" /etc/apt/sources.list.d/debian.sources \
&& apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd --system --gid 10001 app \
&& useradd --system --uid 10001 --gid app --home-dir /nonexistent --shell /usr/sbin/nologin app \
&& install -d -o app -g app /data/audio
COPY --from=builder /build/target/release/teaching-feedback-api /usr/local/bin/teaching-feedback-api
COPY --from=builder /build/target/release/migrate /usr/local/bin/migrate
ENV HOST=0.0.0.0 \
PORT=8080 \
AUDIO_STORAGE_DIR=/data/audio \
RUST_LOG=info
USER app
EXPOSE 8080
HEALTHCHECK --interval=15s --timeout=5s --start-period=30s --retries=10 \
CMD ["curl", "-fsS", "http://127.0.0.1:8080/health"]
CMD ["teaching-feedback-api"]

View File

@@ -39,10 +39,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
speech: speech.clone(),
summary: summary::SummaryService::new(config.summary.clone()),
};
if let Some(pool) = state.pool.clone()
&& speech.configured()
{
transcription_worker::spawn(pool, speech);
if let Some(pool) = state.pool.clone() {
if speech.configured() {
transcription_worker::spawn(pool, speech);
}
}
let app = build_app(state, config.cors_allowed_origin.as_deref())?;
let address = std::net::SocketAddr::from((config.host, config.port));