Files
unstract/docker/README.md
ali 0c5997f9a9 UN-2470 [FEAT] Remove Django dependency from Celery workers with internal APIs (#1494)
* UN-2470 [MISC] Remove Django dependency from Celery workers

This commit introduces a new worker architecture that decouples
Celery workers from Django where possible, enabling support for
gevent/eventlet pool types and reducing worker startup overhead.

Key changes:
- Created separate worker modules (api-deployment, callback, file_processing, general)
- Added internal API endpoints for worker communication
- Implemented Django-free task execution where appropriate
- Added shared utilities and client facades
- Updated container configurations for new worker architecture

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix pre-commit issues: file permissions and ruff errors

Setup the docker for new workers

- Add executable permissions to worker entrypoint files
- Fix import order in namespace package __init__.py
- Remove unused variable api_status in general worker
- Address ruff E402 and F841 errors

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactoreed, Dockerfiles,fixes

* flexibility on celery run commands

* added debug logs

* handled filehistory for API

* cleanup

* cleanup

* cloud plugin structure

* minor changes in import plugin

* added notification and logger workers under new worker module

* add docker compatibility for new workers

* handled docker issues

* log consumer worker fixes

* added scheduler worker

* minor env changes

* cleanup the logs

* minor changes in logs

* resolved scheduler worker issues

* cleanup and refactor

* ensuring backward compatibbility to existing wokers

* added configuration internal apis and cache utils

* optimization

* Fix API client singleton pattern to share HTTP sessions

- Fix flawed singleton implementation that was trying to share BaseAPIClient instances
- Now properly shares HTTP sessions between specialized clients
- Eliminates 6x BaseAPIClient initialization by reusing the same underlying session
- Should reduce API deployment orchestration time by ~135ms (from 6 clients to 1 session)
- Added debug logging to verify singleton pattern activation

* cleanup and structuring

* cleanup in callback

* file system connectors  issue

* celery env values changes

* optional gossip

* variables for sync, mingle and gossip

* Fix for file type check

* Task pipeline issue resolving

* api deployement failed response handled

* Task pipline fixes

* updated file history cleanup with active file execution

* pipline status update and workflow ui page execution

* cleanup and resolvinf conflicts

* remove unstract-core from conenctoprs

* Commit uv.lock changes

* uv locks updates

* resolve migration issues

* defer connector-metadtda

* Fix connector migration for production scale

- Add encryption key handling with defer() to prevent decryption failures
- Add final cleanup step to fix duplicate connector names
- Optimize for large datasets with batch processing and bulk operations
- Ensure unique constraint in migration 0004 can be created successfully

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* hitl fixes

* minor fixes on hitl

* api_hub related changes

* dockerfile fixes

* api client cache fixes with actual response class

* fix: tags and llm_profile_id

* optimized clear cache

* cleanup

* enhanced logs

* added more handling on is file dir and added loggers

* cleanup the runplatform script

* internal apis are excempting from csrf

* sonal cloud issues

* sona-cloud issues

* resolving sonar cloud issues

* resolving sonar cloud issues

* Delta: added Batch size fix in workers

* comments addressed

* celery configurational changes for new workers

* fiixes in callback regaurding the pipline type check

* change internal url registry logic

* gitignore changes

* gitignore changes

* addressng pr cmmnets and cleanup the codes

* adding missed profiles for v2

* sonal cloud blocker issues resolved

* imlement otel

* Commit uv.lock changes

* handle execution time and some cleanup

* adding user_data in metadata Pr: https://github.com/Zipstack/unstract/pull/1544

* scheduler backward compatibitlity

* replace user_data with custom_data

* Commit uv.lock changes

* celery worker command issue resolved

* enhance package imports in connectors by changing to lazy imports

* Update runner.py by removing the otel from it

Update runner.py by removing the otel from it

Signed-off-by: ali <117142933+muhammad-ali-e@users.noreply.github.com>

* added delta changes

* handle erro to destination db

* resolve tool instances id validation and hitl queu name in API

* handled direct execution from workflow page to worker and logs

* handle cost logs

* Update health.py

Signed-off-by: Ritwik G <100672805+ritwik-g@users.noreply.github.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* minor log changes

* introducing log consumer scheduler to bulk create, and socket .emit from worker for ws

* Commit uv.lock changes

* time limit or timeout celery config cleanup

* implemented redis client class in worker

* pipline status enum mismatch

* notification worker fixes

* resolve uv lock conflicts

* workflow log fixes

* ws channel name issue resolved. and handling redis down in status tracker, and removing redis keys

* default TTL changed for unified logs

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: ali <117142933+muhammad-ali-e@users.noreply.github.com>
Signed-off-by: Ritwik G <100672805+ritwik-g@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Ritwik G <100672805+ritwik-g@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-10-03 11:24:07 +05:30

5.2 KiB

Docker Commands

Docker Build

# Build all services
VERSION=dev docker compose -f docker-compose.build.yaml build

# Build a specific service alone
VERSION=dev docker compose -f docker-compose.build.yaml build frontend

# Build optional services also
VERSION=dev docker compose -f docker-compose.build.yaml --profile optional build

Docker Run

NOTE: First copy sample.*.env files to *.env and update as required.

# Up all services
VERSION=dev docker compose -f docker-compose.yaml up -d

# Up a specific service alone
VERSION=dev docker compose -f docker-compose.yaml up -d frontend

# Up optional services also
VERSION=dev docker compose -f docker-compose.yaml --profile optional up -d

Now access frontend at http://frontend.unstract.localhost

V2 Workers (Optional)

V2 workers use a unified container architecture and are disabled by default.

# Default: Run with legacy workers only
VERSION=dev docker compose -f docker-compose.yaml up -d

# Enable V2 workers (unified container)
VERSION=dev docker compose -f docker-compose.yaml --profile workers-v2 up -d

# Or use the platform script
./run-platform.sh --workers-v2

V2 workers available: api-deployment, callback, file-processing, general, notification, log-consumer, scheduler

Overriding a service's config

By making use of the merge compose files feature its possible to override some configuration that's used by the services.

Copy and rename the sample.compose.override.yaml to compose.override.yaml and update it as necessary.

cp sample.compose.override.yaml compose.override.yaml

# Configuration in docker-compose.yaml gets overridden
VERSION=dev docker compose -f docker-compose.yaml -f compose.override.yaml up -d

This can be useful during development to:

  • Not run some memory intensive services
  • Use commands with different arguments to save resources
  • Mount additional volumes or define additional env to configure behaviour

Development with Docker Compose Watch

Docker Compose Watch (available in Docker Compose v2.22.0+) enables a streamlined development workflow by automatically syncing code changes to containers and restarting services as needed.

Setting Up Watch Mode

  1. Ensure you're using Docker Compose v2.22.0 or higher

    docker compose version
    
  2. Create your compose.override.yaml with watch configurations

    cp sample.compose.override.yaml compose.override.yaml
    
  3. Start services with watch mode enabled

    VERSION=dev docker compose -f docker-compose.yaml -f compose.override.yaml watch
    

Note

: Make sure to specify the build definitions also in your compose.override.yaml file or specify docker-compose.build.yaml while running the above command.

Example Workflow

  1. Start services with watch mode:

    VERSION=dev docker compose -f docker-compose.yaml -f compose.override.yaml watch
    
  2. Make changes to your code in your local editor

  3. Changes are automatically synced to the container and services restart as needed

  4. 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.
     {
       "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"
       }
     }
    
    • Set breakpoints in your code
    • Trigger the code path and the debugger will pause at your breakpoints
  5. View logs in real-time:

    docker compose logs -f [service_name]
    

This workflow eliminates the need to rebuild containers or manually restart services during development, significantly improving productivity.

src Folder Layout and gunicorn

For the following project structure:

scheduler
  |- src
  |   |- unstract
  |       |- scheduler
  |           |- main.py
  |- uv.lock
  |- pyproject.toml

This will install the project to:

.venv/lib/python3.12/site-packages/unstract/scheduler/main.py

This will allow gunicorn to refer the package directly as:

$ gunicorn "-c" "python:unstract.scheduler.config.gunicorn" "unstract.scheduler.main:app"