Fundamental_Analysis/docker/Dockerfile.backend.prod
Lv, Qi 15cdfb12e0 feat: fix provider test endpoints and update deployment scripts
- Finnhub: Add missing /test endpoint
- AlphaVantage: Fix test endpoint deserialization (handle null api_url)
- Mock Provider: Add /test endpoint and fix Zodios validation error by adding Mock enum
- Deployment: Remove Mock Provider from production deployment script
- Infrastructure: Add production Dockerfiles and compose configs
2025-12-01 02:05:00 +08:00

68 lines
2.0 KiB
Docker

# 1. Build Stage
FROM rust:1.90-bookworm as builder
ARG SERVICE_NAME
WORKDIR /usr/src/app
# Copy the entire workspace
COPY . .
# Build the specific service in release mode
ENV SQLX_OFFLINE=true
RUN cargo build --release --bin ${SERVICE_NAME}
# Prepare runtime assets directory
RUN mkdir -p /app/assets
# Conditionally copy potential asset folders if they exist for the service
# We use a shell loop or explicit checks. Docker COPY doesn't support conditionals well.
# So we do it in the builder stage using shell.
# 1. Migrations (e.g., data-persistence-service)
RUN if [ -d "services/${SERVICE_NAME}/migrations" ]; then \
mkdir -p /app/assets/migrations && \
cp -r services/${SERVICE_NAME}/migrations/* /app/assets/migrations/; \
fi
# 2. Templates (e.g., report-generator-service)
RUN if [ -d "services/${SERVICE_NAME}/templates" ]; then \
mkdir -p /app/assets/templates && \
cp -r services/${SERVICE_NAME}/templates/* /app/assets/templates/; \
fi
# 2.1 Cookies (e.g., report-generator-service)
RUN if [ -f "services/${SERVICE_NAME}/cookies.txt" ]; then \
cp services/${SERVICE_NAME}/cookies.txt /app/assets/cookies.txt; \
fi
# 3. Config folder (root level, needed by some services like data-persistence)
# We copy it to a specific location.
RUN cp -r config /app/config
# 4. Service Kit Mirror (needed by data-persistence-service build usually, but maybe runtime?)
# It was needed for build. Runtime usually doesn't need it unless it compiles code at runtime.
# 2. Runtime Stage
FROM debian:bookworm-slim
ARG SERVICE_NAME
ENV TZ=Asia/Shanghai
# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
libssl3 \
curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy binary
COPY --from=builder /usr/src/app/target/release/${SERVICE_NAME} /usr/local/bin/app
# Copy prepared assets
COPY --from=builder /app/assets /app/
COPY --from=builder /app/config /app/config
# Set the binary as the entrypoint
ENTRYPOINT ["/usr/local/bin/app"]