mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-06 12:55:05 -05:00
Prisma's generated `types.py` file is 57,000+ lines with complex recursive TypedDict definitions that exhaust Pyright's type inference budget. This causes random type errors and makes the type checker unreliable. ### Changes 🏗️ - Add `gen_prisma_types_stub.py` script that generates a lightweight `.pyi` stub file - The stub preserves safe types (Literal, TypeVar) while collapsing complex TypedDicts to `dict[str, Any]` - Integrate stub generation into all workflows that run `prisma generate`: - `platform-backend-ci.yml` - `claude.yml` - `claude-dependabot.yml` - `copilot-setup-steps.yml` - `docker-compose.platform.yml` - `Dockerfile` - `Makefile` (migrate & reset-db targets) - `linter.py` (lint & format commands) - Add `gen-prisma-stub` poetry script entry - Fix two pre-existing type errors that were previously masked: - `store/db.py`: Replace private type `_StoreListingVersion_version_OrderByInput` with dict literal - `airtable/_webhook.py`: Add cast for `Serializable` type ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Run `poetry run format` - passes with 0 errors (down from 57+) - [x] Run `poetry run lint` - passes with 0 errors - [x] Run `poetry run gen-prisma-stub` - generates stub successfully - [x] Verify stub file is created at correct location with proper content #### For configuration changes: - [x] `.env.default` is updated or already compatible with my changes - [x] `docker-compose.yml` is updated or already compatible with my changes - [x] I have included a list of my configuration changes in the PR description (under **Changes**) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Added a lightweight Prisma type-stub generator and integrated it into build, lint, CI/CD, and container workflows. * Build, migration, formatting, and lint steps now generate these stubs to improve type-checking performance and reduce overhead during builds and deployments. * Exposed a project command to run stub generation manually. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
108 lines
3.8 KiB
Docker
108 lines
3.8 KiB
Docker
FROM debian:13-slim AS builder
|
|
|
|
# Set environment variables
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
WORKDIR /app
|
|
|
|
RUN echo 'Acquire::http::Pipeline-Depth 0;\nAcquire::http::No-Cache true;\nAcquire::BrokenProxy true;\n' > /etc/apt/apt.conf.d/99fixbadproxy
|
|
|
|
# Install Node.js repository key and setup
|
|
RUN apt-get update --allow-releaseinfo-change --fix-missing \
|
|
&& apt-get install -y curl ca-certificates gnupg \
|
|
&& mkdir -p /etc/apt/keyrings \
|
|
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
|
|
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
|
|
|
|
# Update package list and install Python, Node.js, and build dependencies
|
|
RUN apt-get update \
|
|
&& apt-get install -y \
|
|
python3.13 \
|
|
python3.13-dev \
|
|
python3.13-venv \
|
|
python3-pip \
|
|
build-essential \
|
|
libpq5 \
|
|
libz-dev \
|
|
libssl-dev \
|
|
postgresql-client \
|
|
nodejs \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
ENV POETRY_HOME=/opt/poetry
|
|
ENV POETRY_NO_INTERACTION=1
|
|
ENV POETRY_VIRTUALENVS_CREATE=true
|
|
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
|
|
ENV PATH=/opt/poetry/bin:$PATH
|
|
|
|
RUN pip3 install poetry --break-system-packages
|
|
|
|
# Copy and install dependencies
|
|
COPY autogpt_platform/autogpt_libs /app/autogpt_platform/autogpt_libs
|
|
COPY autogpt_platform/backend/poetry.lock autogpt_platform/backend/pyproject.toml /app/autogpt_platform/backend/
|
|
WORKDIR /app/autogpt_platform/backend
|
|
RUN poetry install --no-ansi --no-root
|
|
|
|
# Generate Prisma client
|
|
COPY autogpt_platform/backend/schema.prisma ./
|
|
COPY autogpt_platform/backend/backend/data/partial_types.py ./backend/data/partial_types.py
|
|
COPY autogpt_platform/backend/gen_prisma_types_stub.py ./
|
|
RUN poetry run prisma generate && poetry run gen-prisma-stub
|
|
|
|
FROM debian:13-slim AS server_dependencies
|
|
|
|
WORKDIR /app
|
|
|
|
ENV POETRY_HOME=/opt/poetry \
|
|
POETRY_NO_INTERACTION=1 \
|
|
POETRY_VIRTUALENVS_CREATE=true \
|
|
POETRY_VIRTUALENVS_IN_PROJECT=true \
|
|
DEBIAN_FRONTEND=noninteractive
|
|
ENV PATH=/opt/poetry/bin:$PATH
|
|
|
|
# Install Python without upgrading system-managed packages
|
|
RUN apt-get update && apt-get install -y \
|
|
python3.13 \
|
|
python3-pip \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy only necessary files from builder
|
|
COPY --from=builder /app /app
|
|
COPY --from=builder /usr/local/lib/python3* /usr/local/lib/python3*
|
|
COPY --from=builder /usr/local/bin/poetry /usr/local/bin/poetry
|
|
# Copy Node.js installation for Prisma
|
|
COPY --from=builder /usr/bin/node /usr/bin/node
|
|
COPY --from=builder /usr/lib/node_modules /usr/lib/node_modules
|
|
COPY --from=builder /usr/bin/npm /usr/bin/npm
|
|
COPY --from=builder /usr/bin/npx /usr/bin/npx
|
|
COPY --from=builder /root/.cache/prisma-python/binaries /root/.cache/prisma-python/binaries
|
|
|
|
ENV PATH="/app/autogpt_platform/backend/.venv/bin:$PATH"
|
|
|
|
RUN mkdir -p /app/autogpt_platform/autogpt_libs
|
|
RUN mkdir -p /app/autogpt_platform/backend
|
|
|
|
COPY autogpt_platform/autogpt_libs /app/autogpt_platform/autogpt_libs
|
|
|
|
COPY autogpt_platform/backend/poetry.lock autogpt_platform/backend/pyproject.toml /app/autogpt_platform/backend/
|
|
|
|
WORKDIR /app/autogpt_platform/backend
|
|
|
|
FROM server_dependencies AS migrate
|
|
|
|
# Migration stage only needs schema and migrations - much lighter than full backend
|
|
COPY autogpt_platform/backend/schema.prisma /app/autogpt_platform/backend/
|
|
COPY autogpt_platform/backend/backend/data/partial_types.py /app/autogpt_platform/backend/backend/data/partial_types.py
|
|
COPY autogpt_platform/backend/migrations /app/autogpt_platform/backend/migrations
|
|
|
|
FROM server_dependencies AS server
|
|
|
|
COPY autogpt_platform/backend /app/autogpt_platform/backend
|
|
RUN poetry install --no-ansi --only-root
|
|
|
|
ENV PORT=8000
|
|
|
|
CMD ["poetry", "run", "rest"]
|