Files
bttoxin-pipeline/docker/dockerfiles/Dockerfile.traefik
zly 9835b6e341 feat(deploy): fix docker deployment and add backend i18n
- Docker Deployment Fixes:
  - Switch base images to docker.m.daocloud.io to resolve registry 401 errors
  - Add Postgres and Redis services to docker-compose.traefik.yml
  - Fix frontend build: replace missing icons (Globe->Location, Chart->TrendCharts)
  - Fix frontend build: resolve pnpm CI/TTY issues and frozen lockfile errors
  - Add missing backend dependencies (sqlalchemy, psycopg2, redis-py, celery, docker-py) in pixi.toml
  - Ensure database tables are created on startup (lifespan event)

- Backend Internationalization (i18n):
  - Add backend/app/core/i18n.py for locale handling
  - Update API endpoints (jobs, tasks, uploads, results) to return localized messages
  - Support 'Accept-Language' header (en/zh)

- Documentation:
  - Update DOCKER_DEPLOYMENT.md with new architecture and troubleshooting
  - Update AGENTS.md with latest stack details and deployment steps
  - Update @fix_plan.md status

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-14 12:38:54 +08:00

91 lines
2.5 KiB
Docker

# BtToxin Pipeline - Production Dockerfile (No Nginx)
# This version is designed to work with Traefik as the reverse proxy.
# FastAPI serves both the API and the frontend static files.
# ===========================
# Stage 1: Install dependencies using pixi
# ===========================
FROM ghcr.io/prefix-dev/pixi:latest AS builder
WORKDIR /app
# Copy project files
COPY pixi.toml .
COPY pyproject.toml .
COPY scripts/ scripts/
COPY bttoxin/ bttoxin/
COPY backend/ backend/
COPY Data/ Data/
# Install all pixi environments
RUN pixi install
# Create shell hook for webbackend environment
RUN pixi shell-hook -e webbackend > /shell-hook.sh
RUN echo 'exec "$@"' >> /shell-hook.sh
# ===========================
# Stage 2: Build frontend
# ===========================
FROM docker.m.daocloud.io/library/node:latest AS frontend-builder
WORKDIR /app
# Set CI environment variable to prevent pnpm TTY error
ENV CI=true
# Copy frontend source
COPY frontend/ .
RUN npm install -g pnpm && \
pnpm install --no-frozen-lockfile && \
pnpm build
# ===========================
# Stage 3: Production (FastAPI only)
# ===========================
FROM docker.m.daocloud.io/library/ubuntu:20.04 AS production
WORKDIR /app
# Install runtime dependencies (only curl for healthcheck)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy pixi executable from builder
COPY --from=builder /usr/local/bin/pixi /usr/local/bin/pixi
RUN chmod +x /usr/local/bin/pixi
# Copy backend environment from builder
COPY --from=builder /app/.pixi /app/.pixi
COPY --from=builder /shell-hook.sh /shell-hook.sh
# Copy backend code
COPY --from=builder /app/backend /app/backend
COPY --from=builder /app/Data /app/Data
COPY --from=builder /app/bttoxin /app/bttoxin
COPY --from=builder /app/scripts /app/scripts
COPY --from=builder /app/pixi.toml /app/pixi.toml
# Copy built frontend
COPY --from=frontend-builder /app/dist /app/frontend/dist
# Create jobs directory
RUN mkdir -p /app/jobs && chmod 777 /app/jobs
# Expose port for FastAPI (will be used by Traefik)
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Entrypoint
ENTRYPOINT ["/bin/bash", "/shell-hook.sh"]
# Command: Start FastAPI backend
# FastAPI will serve both API and frontend static files
# Note: Using backend.app.main_spa for SPA static file support
CMD ["uvicorn", "backend.app.main_spa:app", "--host", "0.0.0.0", "--port", "8000"]