Files
bttoxin-pipeline/docker/dockerfiles/Dockerfile.traefik
zly 452e15c806 Fix(docker): optimize pnpm build and explicitly set image tag
- Update Dockerfile:
  - Add `package-import-method copy` to pnpm config to resolve EAGAIN errors during build.
  - Optimize pnpm network concurrency settings.
- Update docker-compose.yml:
  - Explicitly set `image: hotwa/bttoxin-app:latest` for services.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-21 00:40:34 +08:00

83 lines
2.7 KiB
Docker

# BtToxin Pipeline - Production Dockerfile
# Optimized for Traefik deployment with unified context
# ===========================
# Stage 1: Builder (Environment & Code)
# ===========================
FROM ghcr.io/prefix-dev/pixi:latest AS builder
WORKDIR /app
# Copy entire project context (filtered by .dockerignore)
COPY . .
# Install dependencies
RUN pixi install
# Setup external database for BtToxin_Digger
# Using the copy from tools directory included in COPY . .
RUN DIGGER_PREFIX=$(pixi info --json | grep -A 5 '"name": "digger"' | grep '"prefix":' | cut -d '"' -f 4) && \
mkdir -p $DIGGER_PREFIX/bin/BTTCMP_db/bt_toxin && \
rm -rf $DIGGER_PREFIX/bin/BTTCMP_db/bt_toxin/* && \
cp -r /app/tools/bttoxin_digger/external_dbs/bt_toxin/* $DIGGER_PREFIX/bin/BTTCMP_db/bt_toxin/ && \
echo "Overwrote internal database with version from external_dbs"
# Create shell hook for webbackend environment
RUN pixi shell-hook -e webbackend > /shell-hook.sh && \
echo 'exec "$@"' >> /shell-hook.sh
# ===========================
# Stage 2: Frontend Builder
# ===========================
FROM node:20 AS frontend-builder
WORKDIR /app
ENV CI=true
# Optimization: Copy package files first to leverage Docker cache
COPY frontend/package.json frontend/pnpm-lock.yaml* ./
# Optimization: Limit concurrency to avoid EAGAIN errors
RUN npm install -g pnpm && \
pnpm config set registry https://registry.npmmirror.com && \
pnpm config set network-concurrency 1 && \
pnpm config set package-import-method copy && \
pnpm install --no-frozen-lockfile
# Copy remaining source code
COPY frontend/ .
RUN pnpm build
# ===========================
# Stage 3: Production (Runtime)
# ===========================
FROM ghcr.io/prefix-dev/pixi:latest AS production
WORKDIR /app
# Install runtime dependencies
RUN apt-get clean && \
apt-get update -o Acquire::CompressionTypes::Order::=gz -o Acquire::http::No-Cache=True -o Acquire::http::Pipeline-Depth=0 && \
apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy entire prepared application directory (Code + Environment + Data)
COPY --from=builder /app /app
# Copy shell hook
COPY --from=builder /shell-hook.sh /shell-hook.sh
# Copy built frontend assets
COPY --from=frontend-builder /app/dist /app/frontend/dist
# Set permissions and cleanup
RUN chmod -R 755 /app/frontend/dist && \
mkdir -p /app/jobs && chmod 777 /app/jobs
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
ENTRYPOINT ["/bin/bash", "/shell-hook.sh"]
CMD ["uvicorn", "backend.app.main_spa:app", "--host", "0.0.0.0", "--port", "8000"]