46 lines
1.2 KiB
Docker
46 lines
1.2 KiB
Docker
# Backend Dockerfile for Cosmo
|
|
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/python:3.12-slim
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Configure Debian mirrors (Aliyun)
|
|
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources && \
|
|
sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
gcc \
|
|
postgresql-client \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Configure pip to use Aliyun mirror
|
|
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
|
|
pip config set install.trusted-host mirrors.aliyun.com
|
|
|
|
# Copy requirements first for better caching
|
|
COPY requirements.txt .
|
|
|
|
# Install Python dependencies
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Create upload directory
|
|
RUN mkdir -p /app/upload /app/logs
|
|
|
|
# Set Python path
|
|
ENV PYTHONPATH=/app
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
CMD curl -f http://localhost:8000/health || exit 1
|
|
|
|
# Run the application
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]
|