# Python 3.10 Docker container for running logcli
FROM python:3.10-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Install tiup and tidb:v8.5.5
RUN curl -fsSL https://tiup-mirrors.pingcap.com/install.sh | sh \
    && ~/.tiup/bin/tiup install tidb:v8.5.5

# Copy requirements first for better caching
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the entire application
COPY . .

# Create output directory
RUN mkdir -p /app/local

# Set PYTHONPATH to include the project root
ENV PYTHONPATH=/app

# Copy and set entrypoint scripts
COPY entrypoint.sh /app/entrypoint.sh
COPY entrypoint_decode.sh /app/entrypoint_decode.sh
RUN chmod +x /app/entrypoint.sh /app/entrypoint_decode.sh

# Start tidb-server in background then run the main app
ENTRYPOINT ["/app/entrypoint.sh"]
