Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migrate from Poetry to UV, added health checkpoint, and improved dockerimage #15

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

spa5k
Copy link

@spa5k spa5k commented Mar 4, 2025

  • Add .dockerignore to optimize Docker build context
  • Refactor docker-compose files for CPU and GPU modes to add health check.
  • Update Dockerfile with multi-stage build and improved caching
  • Add Makefile for simplified project management
  • Implement health check endpoint in document converter route
  • Optimize container runtime and model download process
  • Improve documentation and setup instructions

spa5k added 3 commits March 3, 2025 23:13
- Add .dockerignore to optimize Docker build context
- Refactor docker-compose files for CPU and GPU modes
- Update Dockerfile with multi-stage build and improved caching
- Add Makefile for simplified project management
- Implement health check endpoint in document converter route
- Optimize container runtime and model download process
- Improve documentation and setup instructions
@spa5k spa5k marked this pull request as ready for review March 5, 2025 07:55
@spa5k
Copy link
Author

spa5k commented Mar 5, 2025

@drmingler do you mind taking a look?

@spa5k spa5k changed the title chore: Migrate from Poetry to UV and update project configuration chore: Migrate from Poetry to UV, added health checkpoint, and improved dockerimage Mar 5, 2025
@drmingler
Copy link
Owner

@drmingler do you mind taking a look?

@spa5k Awesome work! Thank you. I will have a look and get back. Meanwhile can we have a unified lint rule so that we can avoid modifying the code formatting?

@spa5k
Copy link
Author

spa5k commented Mar 5, 2025

Sure, I tried not to change much formatting, will reset wherever it happened. UV also provides a formatter, maybe it can be used

@spa5k
Copy link
Author

spa5k commented Mar 5, 2025

What about this? Let's merge this, then I will create a PR to implement Ruff, as a GitHub action, and a pre commit in next PR, otherwise, there will be too many changes in this PR.

@drmingler

@drmingler
Copy link
Owner

What about this? Let's merge this, then I will create a PR to implement Ruff, as a GitHub action, and a pre commit in next PR, otherwise, there will be too many changes in this PR.

@drmingler

Okay that makes sense. I will merge this over the weekend. Thank you

spa5k added 2 commits March 7, 2025 23:01
…type safety and API documentation

- Add comprehensive response examples and status codes
- Introduce JobStatus and ImageType enums for better type safety
- Enhance route error handling and status reporting
- Add detailed field descriptions and validation
- Improve health check endpoint with more granular service status reporting
@spa5k
Copy link
Author

spa5k commented Mar 8, 2025

Thanks, the PR is now in quite good stage, I tested the caching, and schema changes, including generating SDK using it for Go, and everything seems to be working well.

@drmingler drmingler self-requested a review March 8, 2025 16:07
```bash
curl -sSL https://install.python-poetry.org | python3 -
curl -LsSf https://astral.sh/uv/install.sh | sh
Copy link
Owner

@drmingler drmingler Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add instructions on how to install uv for those using windows or add a link to the uv installation doc? @spa5k

README.md Outdated
Comment on lines 165 to 169
make docker-run-gpu

# Or build and run with multiple workers
make docker-run-gpu WORKER_COUNT=3
```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "docker-start-cpu" not "docker-run-gpu"

Copy link
Owner

@drmingler drmingler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-03-08 at 18 59 04 It doesn't work on GPU but works on CPU. Modules are not installed during docker build.

spa5k added 3 commits March 10, 2025 08:30
…build and runtime performance

- Simplify Dockerfile with single-stage build
- Improve PyTorch and EasyOCR model installation based on system architecture
- Update docker-compose files to remove runtime target
- Add auto-detection for CPU/GPU docker start in Makefile
- Enhance .dockerignore with additional Python-related exclusions
- Add entrypoint script for consistent container startup
- Introduce detect_gpu.sh script for dynamic GPU and Docker configuration detection
- Update docker-compose.cpu.yml and docker-compose.gpu.yml to use uv for running commands
- Enhance Dockerfile with multi-stage build, improved GPU/CPU detection, and model downloading
- Add NVIDIA GPU capabilities and platform configuration in Docker Compose files
- Improve runtime and build performance with better caching and environment setup
@spa5k
Copy link
Author

spa5k commented Mar 10, 2025

Can you check the GPU part now? If it is not working, please move the pytorch and model downloads part to the runtime stage

Comment on lines +160 to +186
try:
result = document_converter_service.get_single_document_task_result(job_id)

# Return 202 Accepted if job is still in progress
if result.status in ["IN_PROGRESS"]:
return JSONResponse(
status_code=status.HTTP_202_ACCEPTED,
content=result.dict(exclude_none=True)
)

# Return 422 for failed jobs
if result.status == "FAILURE":
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
content=result.dict(exclude_none=True)
)

# Return 200 OK for successful jobs
return JSONResponse(
status_code=status.HTTP_200_OK,
content=result.dict(exclude_none=True)
)
except KeyError:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Job not found: {job_id}"
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take this off, during job processing we do not raise errors, we return a status of FAILURE if the job failed and the reason for the failure in the error field. It was intentionally done that way.

Comment on lines +248 to +279
result = document_converter_service.get_batch_conversion_task_result(job_id)

# Return 202 Accepted if the batch job or any sub-job is still in progress
if result.status in ["IN_PROGRESS"] or any(
job.status in ["IN_PROGRESS"]
for job in result.conversion_results
):
return JSONResponse(
status_code=status.HTTP_202_ACCEPTED,
content=result.dict(exclude_none=True)
)

# Return 422 for failed batch jobs
if result.status == "FAILURE" or any(
job.status == "FAILURE"
for job in result.conversion_results
):
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
content=result.dict(exclude_none=True)
)

# Return 200 OK for successful batch jobs (all success)
return JSONResponse(
status_code=status.HTTP_200_OK,
content=result.dict(exclude_none=True)
)
except KeyError:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Batch job not found: {job_id}"
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@drmingler
Copy link
Owner

Can you check the GPU part now? If it is not working, please move the pytorch and model downloads part to the runtime stage

I will test on gpu and get back to you. @spa5k

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants