FROM python:3.12-slim
ARG API_DIR
RUN test -n "$API_DIR" || (echo "ERROR: API_DIR build arg is required" && false)
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.9.1 /lambda-adapter /opt/extensions/lambda-adapter
ENV PORT=8080
ENV AWS_LWA_READINESS_CHECK_PATH=/
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /var/task
# Copy pre-built runtime artifacts from build directory
# Everything needed for runtime is prepared by the API-specific justfile
# in ${API_DIR}/build/ (OpenAPI specs, Python files, pyproject.toml, patched fastmcp, etc.)
COPY ${API_DIR}/build/ ./
# Install dependencies (after copying build directory so we get pyproject.toml)
# Our patched fastmcp is already in /var/task/fastmcp/ and will be found first by Python
RUN uv pip install --system --no-cache -e .
# Pre-compile Python bytecode for faster cold starts
# - /usr/local/lib/python3.12/site-packages: pip-installed dependencies
# - /var/task: application code and patched fastmcp
RUN python -m compileall -b /usr/local/lib/python3.12/site-packages/ /var/task/ || true
CMD ["python", "runtime.py"]