Fundamental_Analysis/services/data-persistence-service/Dockerfile
Lv, Qi ceffa0d95c chore(build): unify Dockerfiles and root .dockerignore; fix services after deps upgrade
- secrecy: migrate Secret<String> -> SecretString across services; adjust usages
- warnings: clean unused imports/structs (no behavior change)
- docker-compose: remove unnecessary host port mappings; rely on app-network; keep frontend only
- build: set build.context to repo root; reference per-service Dockerfiles
- add: root .dockerignore to exclude target/node_modules/ref/archive/docs and logs
- data-persistence-service: refine cargo-chef with path deps; slim context; copy correct targets
- Dockerfiles: normalize multi-stage builds; fix WORKDIR and release binary paths
- nats: resolve 4222 conflict by not binding to host
- verified: all rust services build successfully with new flow
2025-11-16 23:34:28 +08:00

35 lines
1.6 KiB
Docker

FROM rust:1.90-bookworm AS chef
WORKDIR /app
RUN cargo install cargo-chef
FROM chef AS planner
WORKDIR /app/services/data-persistence-service
# 仅复制必要的 Cargo 清单,避免大体积上下文
COPY services/common-contracts/Cargo.toml /app/services/common-contracts/Cargo.toml
COPY services/data-persistence-service/Cargo.toml /app/services/data-persistence-service/Cargo.toml
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
ENV SQLX_OFFLINE=true
WORKDIR /app/services/data-persistence-service
COPY --from=planner /app/services/data-persistence-service/recipe.json /app/services/data-persistence-service/recipe.json
# 为了支持 path 依赖,先拷贝依赖源码再 cook
COPY services/common-contracts /app/services/common-contracts
RUN cargo chef cook --release --recipe-path /app/services/data-persistence-service/recipe.json
# 复制服务源码用于实际构建
COPY services/common-contracts /app/services/common-contracts
COPY services/data-persistence-service /app/services/data-persistence-service
RUN cargo build --release --bin data-persistence-service-server
FROM debian:bookworm-slim AS runtime
WORKDIR /app
RUN groupadd --system --gid 1001 appuser && \
useradd --system --uid 1001 --gid 1001 appuser
USER appuser
COPY --from=builder /app/services/data-persistence-service/target/release/data-persistence-service-server /usr/local/bin/data-persistence-service-server
COPY services/data-persistence-service/migrations ./migrations
ENV HOST=0.0.0.0
ENV PORT=3000
EXPOSE 3000
ENTRYPOINT ["/usr/local/bin/data-persistence-service-server"]