topic-generator / Dockerfile
Namgyu-Youn's picture
Upload 6 files
ea9e2cb verified
FROM python:3.12.3-slim as builder
WORKDIR /app
# Install system dependencies required for building
RUN apt-get update && apt-get install -y \
protobuf-compiler \
gcc \
g++ \
cmake \
pkg-config \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Install poetry
RUN pip install poetry
# Copy dependency files
COPY pyproject.toml poetry.lock ./
# Configure poetry and install dependencies
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi --no-root
# Second stage
FROM python:3.12.3-slim
WORKDIR /app
# Copy installed dependencies from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages/ /usr/local/lib/python3.12/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/
# Install runtime system dependencies
RUN apt-get update && apt-get install -y \
protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
# Copy application code
COPY . .
# Create non-root user
RUN useradd -m appuser && \
chown -R appuser:appuser /app
USER appuser
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/ || exit 1
CMD ["poetry", "run", "python", "app.py"]