# Build stage
FROM python:3.14-slim AS builder

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

RUN apt update && apt install --yes git

# Set up build environment
WORKDIR /build

# Copy only the files needed for building
COPY . .
# Install build dependencies using uv
RUN ls -la .git && uv sync --dev

# Build the wheel
RUN uv build

# 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

