LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
[MISC] Improve dev experience by adding a compose debug override (#1765)
Chandrasekharan M6795e981f33e
diff --git a/docker/README.md b/docker/README.mdindex 9461511d3..8f99042f6 100644--- a/docker/README.md+++ b/docker/README.md@@ -100,56 +100,55 @@ This can be useful during development to:VERSION=dev docker compose -f docker-compose.yaml -f compose.override.yaml watch```-1. Make changes to your code in your local editor-1. Changes are automatically synced to the container and services restart as needed-1. For debugging:- - Configure IDE to connect to the appropriate debugpy port- Here's an example `launch.json` (for VSCode) to attach to a the `backend` container on port 5678.- It assumes that a workspace involving unstract and unstract-sdk is setup.- For more information on this refer [VSCode docs](https://code.visualstudio.com/docs/devcontainers/attach-container#_attach-to-a-docker-container).-- ```json- {- "name": "Docker: Backend Remote Debug",- "type": "debugpy",- "request": "attach",- "connect": {- "host": "localhost",- "port": 5678- },- "pathMappings": [- {- "localRoot": "${workspaceFolder:unstract}/backend",- "remoteRoot": "/app"- },- {- "localRoot": "${workspaceFolder:unstract}/unstract",- "remoteRoot": "/unstract"- },- // Uncomment below to use and debug local version of unstract-sdk- // {- // "localRoot": "${workspaceFolder:unstract-sdk}/src/unstract/sdk",- // "remoteRoot": "/unstract-sdk/src/unstract/sdk"- // },- ],- "justMyCode": false,- "django": true,- "presentation": {- "group": "docker-debug"- }- }- ```+2. Make changes to your code - they're automatically synced and services restart as needed- - Set breakpoints in your code- - Trigger the code path and the debugger will pause at your breakpoints+3. View logs: `docker compose logs -f [service_name]`-1. View logs in real-time:+## Debugging Containers- ```bash- docker compose logs -f [service_name]- ```+Enable debugpy by adding `compose.debug.yaml`:++```bash+VERSION=dev docker compose -f docker-compose.yaml -f compose.override.yaml -f compose.debug.yaml watch+```++Debug ports per service:++| Service | Port |+|---------|------|+| backend | 5678 |+| runner | 5679 |+| platform-service | 5680 |+| prompt-service | 5681 |+| **V2 Workers** | |+| worker-file-processing-v2 | 5682 |+| worker-callback-v2 | 5683 |+| worker-api-deployment-v2 | 5684 |+| worker-general-v2 | 5685 |+| worker-notification-v2 | 5686 |+| worker-log-consumer-v2 | 5687 |+| worker-scheduler-v2 | 5688 |++### VSCode Configuration++Example `launch.json` to attach to the `backend` container:++```json+{+ "name": "Docker: Backend Remote Debug",+ "type": "debugpy",+ "request": "attach",+ "connect": { "host": "localhost", "port": 5678 },+ "pathMappings": [+ { "localRoot": "${workspaceFolder:unstract}/backend", "remoteRoot": "/app" },+ { "localRoot": "${workspaceFolder:unstract}/unstract", "remoteRoot": "/unstract" }+ ],+ "justMyCode": false,+ "django": true+}+```-This workflow eliminates the need to rebuild containers or manually restart services during development, significantly improving productivity.+See [VSCode docs](https://code.visualstudio.com/docs/devcontainers/attach-container#_attach-to-a-docker-container) for more details.## `src` Folder Layout and `gunicorn`diff --git a/docker/compose.debug.yaml b/docker/compose.debug.yamlnew file mode 100644index 000000000..66d247997--- /dev/null+++ b/docker/compose.debug.yaml@@ -0,0 +1,211 @@+# Debug layer - adds debugpy to services+#+# Usage:+# VERSION=test docker compose -f docker-compose.yaml -f compose.override.yaml -f compose.debug.yaml watch+#+# Debug Port Map:+# 5678 - backend+# 5679 - runner+# 5680 - platform-service+# 5681 - prompt-service+# 5682 - worker-file-processing-v2+# 5683 - worker-callback-v2+# 5684 - worker-api-deployment-v2+# 5685 - worker-general-v2+# 5686 - worker-notification-v2+# 5687 - worker-log-consumer-v2+# 5688 - worker-scheduler-v2++services:+ #########################################################################################################+ # Python Services with debugpy++ backend:+ ports:+ - "5678:5678"+ command: [+ "uv run python -Xfrozen_modules=off -m debugpy --listen 0.0.0.0:5678 .venv/bin/gunicorn+ --bind 0.0.0.0:8000+ --workers 1+ --threads 2+ --worker-class gthread+ --log-level debug+ --timeout 900+ --graceful-timeout 5 backend.wsgi:application"+ ]++ runner:+ ports:+ - "5679:5679"+ command: [+ "uv run python -Xfrozen_modules=off -m debugpy --listen 0.0.0.0:5679 .venv/bin/gunicorn+ --bind 0.0.0.0:5002+ --workers 1+ --threads 2+ --worker-class gthread+ --log-level debug+ --timeout 900+ --access-logfile -+ --graceful-timeout 5 unstract.runner:app"+ ]++ platform-service:+ ports:+ - "3001:3001"+ - "5680:5680"+ command: [+ "uv run python -Xfrozen_modules=off -m debugpy --listen 0.0.0.0:5680 .venv/bin/gunicorn+ --bind 0.0.0.0:3001+ --workers 1+ --threads 2+ --worker-class gthread+ --log-level debug+ --timeout 900+ --access-logfile -+ --graceful-timeout 5 unstract.platform_service.run:app"+ ]++ prompt-service:+ ports:+ - "5681:5681"+ command: [+ "uv run python -Xfrozen_modules=off -m debugpy --listen 0.0.0.0:5681 .venv/bin/gunicorn+ --bind 0.0.0.0:3003+ --workers 1+ --threads 2+ --worker-class gthread+ --log-level debug+ --timeout 900+ --access-logfile -+ --graceful-timeout 5 unstract.prompt_service.run:app"+ ]++ #########################################################################################################+ # V2 Workers with debugpy+ # Using --pool=threads for debugpy compatibility (prefork doesn't work well with debugpy)++ worker-file-processing-v2:+ user: root+ ports:+ - "5682:5682"+ entrypoint: ["bash", "-c"]+ command: [+ "uv run python -m debugpy --listen 0.0.0.0:5682 -m celery+ -A worker worker+ --queues=file_processing,api_file_processing,file_processing_priority+ --loglevel=INFO+ --pool=threads+ --concurrency=2+ --prefetch-multiplier=1+ --without-gossip+ --without-mingle+ --without-heartbeat"+ ]++ worker-callback-v2:+ user: root+ ports:+ - "5683:5683"+ entrypoint: ["bash", "-c"]+ command: [+ "uv run python -m debugpy --listen 0.0.0.0:5683 -m celery+ -A worker worker+ --queues=file_processing_callback,api_file_processing_callback+ --loglevel=INFO+ --pool=threads+ --concurrency=2+ --prefetch-multiplier=1+ --without-gossip+ --without-mingle+ --without-heartbeat"+ ]++ worker-api-deployment-v2:+ user: root+ ports:+ - "5684:5684"+ entrypoint: ["bash", "-c"]+ command: [+ "uv run python -m debugpy --listen 0.0.0.0:5684 -m celery+ -A worker worker+ --queues=celery_api_deployments+ --loglevel=INFO+ --pool=threads+ --concurrency=2+ --prefetch-multiplier=1+ --without-gossip+ --without-mingle+ --without-heartbeat"+ ]++ worker-general-v2:+ user: root+ ports:+ - "5685:5685"+ entrypoint: ["bash", "-c"]+ command: [+ "uv run python -m debugpy --listen 0.0.0.0:5685 -m celery+ -A worker worker+ --queues=celery+ --loglevel=INFO+ --pool=threads+ --concurrency=2+ --prefetch-multiplier=1+ --without-gossip+ --without-mingle+ --without-heartbeat"+ ]++ worker-notification-v2:+ user: root+ ports:+ - "5686:5686"+ entrypoint: ["bash", "-c"]+ command: [+ "uv run python -m debugpy --listen 0.0.0.0:5686 -m celery+ -A worker worker+ --queues=notifications,notifications_webhook,notifications_email,notifications_sms,notifications_priority+ --loglevel=INFO+ --pool=threads+ --concurrency=2+ --prefetch-multiplier=1+ --without-gossip+ --without-mingle+ --without-heartbeat"+ ]++ worker-log-consumer-v2:+ user: root+ ports:+ - "5687:5687"+ entrypoint: ["bash", "-c"]+ command: [+ "uv run python -m debugpy --listen 0.0.0.0:5687 -m celery+ -A worker worker+ --queues=celery_log_task_queue,celery_periodic_logs+ --loglevel=INFO+ --pool=threads+ --concurrency=2+ --prefetch-multiplier=1+ --without-gossip+ --without-mingle+ --without-heartbeat"+ ]++ worker-scheduler-v2:+ user: root+ ports:+ - "5688:5688"+ entrypoint: ["bash", "-c"]+ command: [+ "uv run python -m debugpy --listen 0.0.0.0:5688 -m celery+ -A worker worker+ --queues=scheduler+ --loglevel=INFO+ --pool=threads+ --concurrency=2+ --prefetch-multiplier=1+ --without-gossip+ --without-mingle+ --without-heartbeat"+ ]diff --git a/docker/sample.compose.override.yaml b/docker/sample.compose.override.yamlindex c81b4c5f5..eeb728c82 100644--- a/docker/sample.compose.override.yaml+++ b/docker/sample.compose.override.yaml@@ -1,196 +1,337 @@-# Refer https://docs.docker.com/compose/how-tos/multiple-compose-files/merge/-# Minimize celery workers to reduce memory usage of Unstract (aids development)-services:- worker:- command: "-A backend worker --loglevel=info -Q celery,celery_api_deployments,celery_periodic_logs,celery_log_task_queue,file_processing,api_file_processing,file_processing_callback,api_file_processing_callback --autoscale=${WORKER_AUTOSCALE}"-- worker-logging:- profiles:- - high_memory-- worker-file-processing:- profiles:- - high_memory-- worker-file-processing-callback:- profiles:- - high_memory+# Development override - NO debugpy (use compose.debug.yaml for debugging)+#+# Usage:+# Normal dev: VERSION=test docker compose -f docker-compose.yaml -f compose.override.yaml watch+# With debug: VERSION=test docker compose -f docker-compose.yaml -f compose.override.yaml -f compose.debug.yaml watch+#+# Memory-optimized settings: reduced workers/threads for local development+#+# Requirements:+# - Docker Compose 2.24.4+ (for !override directive support)-# Watch configuration-# Refer https://docs.docker.com/compose/how-tos/file-watch/+services:+ #########################################################################################################+ # Frontend - React dev server with hot reloadfrontend:+ image: unstract/frontend:${VERSION}build:dockerfile: docker/dockerfiles/frontend.Dockerfilecontext: ..target: development+ depends_on: !override+ - reverse-proxyenv_file:- ../frontend/.envdevelop:watch:- # Sync the frontend directory with the container- - action: sync- path: ../frontend/- target: /app- ignore: node_modules/- # Rebuild when dependencies change- - action: rebuild- path: ../frontend/package-lock.json- - action: rebuild- path: ../frontend/package.json+ - action: sync+ path: ../frontend/+ target: /app+ ignore:+ - node_modules/+ - build/+ - action: rebuild+ path: ../frontend/package-lock.json+ - action: rebuild+ path: ../frontend/package.json+ labels:+ - traefik.http.services.frontend.loadbalancer.server.port=3000+ #########################################################################################################+ # Backend - Gunicorn with reload (memory optimized: 1 worker, 2 threads)backend:+ image: unstract/backend:${VERSION}build:dockerfile: docker/dockerfiles/backend.Dockerfilecontext: ..+ depends_on: !override+ - db+ - redis+ - reverse-proxy+ - minio+ - platform-service+ init: trueentrypoint: ["bash", "-c"]command: [- "source .venv/bin/activate && \- uv sync --all-groups && \- python /tmp/debugpy --listen 0.0.0.0:5678 .venv/bin/gunicorn \- --bind 0.0.0.0:8000 \- --workers 2 \- --threads 4 \- --worker-class gthread \- --log-level debug \- --timeout 900 \- --access-logfile - \- --reload --graceful-timeout 5 backend.wsgi:application"+ "uv run python -Xfrozen_modules=off .venv/bin/gunicorn+ --bind 0.0.0.0:8000+ --workers 1+ --threads 2+ --worker-class gthread+ --log-level debug+ --timeout 900+ --access-logfile -+ --graceful-timeout 5 backend.wsgi:application"]develop:watch:- # Sync the backend directory with the container- - action: sync+restart- path: ../backend/- target: /app- ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]- - action: sync+restart- path: ../unstract/- target: /unstract- ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]- # Rebuild when dependencies change- - action: rebuild- path: ./dockerfiles/*- - action: rebuild- path: ../backend/uv.lock- ## Uncomment below lines to use local version of unstract-sdk- ## NOTE: Restart the containers on code change though- # environment:- # - PYTHONPATH=/unstract-sdk/src- # volumes:- # - <path_to_unstract_sdk>/unstract-sdk:/unstract-sdk+ - action: sync+restart+ path: ../backend/+ target: /app+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: sync+restart+ path: ../unstract/+ target: /unstract+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ labels:+ - traefik.http.services.backend.loadbalancer.server.port=8000+ #########################################################################################################+ # Runner (memory optimized: 1 worker, 2 threads)runner:+ image: unstract/runner:${VERSION}build:dockerfile: docker/dockerfiles/runner.Dockerfilecontext: ..entrypoint: ["bash", "-c"]command: [- "source .venv/bin/activate && \- uv sync --all-groups && \- python /tmp/debugpy --listen 0.0.0.0:5681 .venv/bin/gunicorn \- --bind 0.0.0.0:5002 \- --workers 2 \- --threads 2 \- --worker-class gthread \- --log-level debug \- --timeout 900 \- --access-logfile - \- --reload --graceful-timeout 5 unstract.runner:app"+ "uv run python -Xfrozen_modules=off .venv/bin/gunicorn+ --bind 0.0.0.0:5002+ --workers 1+ --threads 2+ --worker-class gthread+ --log-level debug+ --timeout 900+ --access-logfile -+ --graceful-timeout 5 unstract.runner:app"]develop:watch:- # Sync the runner directory with the container- - action: sync+restart- path: ../runner/- target: /app- ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]- # Rebuild when dependencies change- - action: rebuild- path: ../runner/uv.lock+ - action: sync+restart+ path: ../runner/+ target: /app+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: rebuild+ path: ../runner/uv.lock+ #########################################################################################################+ # Platform Service (memory optimized: 1 worker, 2 threads)platform-service:+ image: unstract/platform-service:${VERSION}build:dockerfile: docker/dockerfiles/platform.Dockerfilecontext: ..+ ports:+ - "3001:3001"entrypoint: ["bash", "-c"]command: [- "source .venv/bin/activate && \- uv sync --all-groups && \- python /tmp/debugpy --listen 0.0.0.0:5679 .venv/bin/gunicorn \- --bind 0.0.0.0:3001 \- --workers 2 \- --threads 2 \- --worker-class gevent \- --log-level debug \- --timeout 900 \- --access-logfile - \- --reload --graceful-timeout 5 unstract.platform_service.run:app"+ "uv run python -Xfrozen_modules=off .venv/bin/gunicorn+ --bind 0.0.0.0:3001+ --workers 1+ --threads 2+ --worker-class gthread+ --log-level debug+ --timeout 900+ --access-logfile -+ --graceful-timeout 5 unstract.platform_service.run:app"]develop:watch:- # Sync the platform-service directory with the container- - action: sync+restart- path: ../platform-service/- target: /app- ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]- # Rebuild when dependencies change- - action: rebuild- path: ../platform-service/uv.lock+ - action: sync+restart+ path: ../platform-service/+ target: /app+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: sync+restart+ path: ../unstract/+ target: /unstract+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: rebuild+ path: ../platform-service/uv.lock+ #########################################################################################################+ # Prompt Service (memory optimized: 1 worker, 2 threads)prompt-service:+ image: unstract/prompt-service:${VERSION}build:dockerfile: docker/dockerfiles/prompt.Dockerfilecontext: ..entrypoint: ["bash", "-c"]command: [- "source .venv/bin/activate && \- uv sync --all-groups && \- python /tmp/debugpy --listen 0.0.0.0:5680 .venv/bin/gunicorn \- --bind 0.0.0.0:3003 \- --workers 2 \- --threads 2 \- --worker-class gthread \- --log-level debug \- --timeout 900 \- --access-logfile - \- --reload --graceful-timeout 5 unstract.prompt_service.run:app"+ "uv run python -Xfrozen_modules=off .venv/bin/gunicorn+ --bind 0.0.0.0:3003+ --workers 1+ --threads 2+ --worker-class gthread+ --log-level debug+ --timeout 900+ --access-logfile -+ --graceful-timeout 5 unstract.prompt_service.run:app"]develop:watch:- # Sync the prompt-service directory with the container- - action: sync+restart- path: ../prompt-service/- target: /app- ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]- # Rebuild when dependencies change- - action: rebuild- path: ../prompt-service/uv.lock+ - action: sync+restart+ path: ../prompt-service/+ target: /app+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/, node_modules/]+ - action: sync+restart+ path: ../unstract/+ target: /unstract+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: rebuild+ path: ../prompt-service/uv.lock+ #########################################################################################################+ # X2Text Servicex2text-service:+ image: unstract/x2text-service:${VERSION}+ profiles:+ - optionalbuild:dockerfile: docker/dockerfiles/x2text.Dockerfilecontext: ..- entrypoint: ["bash", "-c"]- command: [- "source .venv/bin/activate && \- uv sync --all-groups && \- python /tmp/debugpy --listen 0.0.0.0:5682 .venv/bin/gunicorn \- --bind 0.0.0.0:3004 \- --workers 2 \- --threads 2 \- --worker-class gthread \- --log-level debug \- --timeout 900 \- --access-logfile - \- --reload --graceful-timeout 5 unstract.x2text_service.run:app"- ]++ #########################################################################################################+ # Tool Sidecar+ tool-sidecar:+ image: unstract/tool-sidecar:${VERSION}+ profiles:+ - tools+ build:+ dockerfile: docker/dockerfiles/tool-sidecar.Dockerfile+ context: ..++ #########################################################################################################+ # V2 Workers - Build configurations with memory-optimized settings+ # All use --pool=threads and --concurrency=2 for lower memory footprint++ worker-api-deployment-v2:+ build:+ dockerfile: docker/dockerfiles/worker-unified.Dockerfile+ context: ..develop:watch:- # Sync the x2text-service directory with the container- - action: sync+restart- path: ../x2text-service/- target: /app- ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]- # Rebuild when dependencies change- - action: rebuild- path: ../x2text-service/uv.lock+ - action: sync+restart+ path: ../workers/+ target: /app+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: sync+restart+ path: ../unstract/+ target: /unstract+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: rebuild+ path: ../workers/uv.lock++ worker-callback-v2:+ build:+ dockerfile: docker/dockerfiles/worker-unified.Dockerfile+ context: ..+ develop:+ watch:+ - action: sync+restart+ path: ../workers/+ target: /app+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: sync+restart+ path: ../unstract/+ target: /unstract+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: rebuild+ path: ../workers/uv.lock++ worker-file-processing-v2:+ build:+ dockerfile: docker/dockerfiles/worker-unified.Dockerfile+ context: ..+ develop:+ watch:+ - action: sync+restart+ path: ../workers/+ target: /app+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: sync+restart+ path: ../unstract/+ target: /unstract+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: rebuild+ path: ../workers/uv.lock++ worker-general-v2:+ build:+ dockerfile: docker/dockerfiles/worker-unified.Dockerfile+ context: ..+ develop:+ watch:+ - action: sync+restart+ path: ../workers/+ target: /app+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: sync+restart+ path: ../unstract/+ target: /unstract+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: rebuild+ path: ../workers/uv.lock++ worker-notification-v2:+ build:+ dockerfile: docker/dockerfiles/worker-unified.Dockerfile+ context: ..+ develop:+ watch:+ - action: sync+restart+ path: ../workers/+ target: /app+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: sync+restart+ path: ../unstract/+ target: /unstract+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: rebuild+ path: ../workers/uv.lock++ worker-log-consumer-v2:+ build:+ dockerfile: docker/dockerfiles/worker-unified.Dockerfile+ context: ..+ develop:+ watch:+ - action: sync+restart+ path: ../workers/+ target: /app+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: sync+restart+ path: ../unstract/+ target: /unstract+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: rebuild+ path: ../workers/uv.lock++ # No develop.watch - runs bash scheduler script, not Python code+ worker-log-history-scheduler-v2:+ build:+ dockerfile: docker/dockerfiles/worker-unified.Dockerfile+ context: ..++ worker-scheduler-v2:+ build:+ dockerfile: docker/dockerfiles/worker-unified.Dockerfile+ context: ..+ develop:+ watch:+ - action: sync+restart+ path: ../workers/+ target: /app+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: sync+restart+ path: ../unstract/+ target: /unstract+ ignore: [.venv/, __pycache__/, "*.pyc", .pytest_cache/, .mypy_cache/]+ - action: rebuild+ path: ../workers/uv.lock++ # V1 workers disabled by default (use workers-v2 profile instead)+ worker:+ profiles:+ - workers-v1++ worker-file-processing:+ profiles:+ - workers-v1++ worker-file-processing-callback:+ profiles:+ - workers-v1++ worker-logging:+ profiles:+ - workers-v1