# Build stage
FROM python:3.14-slim as builder

# Install Git
RUN apt-get update && apt-get install -y --no-install-recommends git \
    && rm -rf /var/lib/apt/lists/*

# Copy uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Set up build environment
WORKDIR /build

# Copy only the files needed for building
COPY ./ ./

# Install build dependencies using uv
RUN uv pip install --system --no-cache \
    build \
    setuptools-scm

# Build the wheel
RUN python -m build --wheel --no-isolation

# Final stage
FROM python:3.14-slim

# Copy uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Create app directory
WORKDIR /app

# Copy the wheel from builder
COPY --from=builder /build/dist/*.whl .

# Get the exact wheel filename
RUN WHEEL_FILE=$(ls *.whl) \
    && echo "WHEEL_FILE=$WHEEL_FILE" > /tmp/wheel_env

# Run the application directly from the wheel
# The package name is 'hnmastodonbot' as defined in pyproject.toml
CMD . /tmp/wheel_env && uv tool run --with "$WHEEL_FILE" hnmastodonbot

