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

feat: Remove docker_py usage and add docker_cli_wrapper.py #33

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

Conversation

angela-ko
Copy link
Contributor

@angela-ko angela-ko commented Feb 25, 2025

Relevant issue or PR

Fixes #10
Also #8

Description of changes

  • Created a new docker_cli_wrapper.py file that contains a DockerWrapper class that is a custom python wrapper over docker_cli that mimics the interface of docker_py. This wrapper only sees Tesseract related objects and not other docker objects.
    • The new DockerWrapper class has two subclasses, Container and Image.
    • It has a list of all Images that gets updated on get_image or get_all_images call.
    • It has a dict of container_id to Container object that gets updated on get_container or get_all_containers call
    • It has a map of project_id to all the containers that are part of the project
    • These member variables make existing functions we have easier to deal with.
  • Removed a lot of functions from existing files and all mentions of docker_client with the new docker_wrapper, as well as any mentions of docker errors.
  • docker errors are replaced with generic subprocess called errors or Runtime/Value Errors, where the messages are parsed to handle specific errors.
  • teardown function in cli has the most amount of changes as handling of --all flag is moved to engine.teardown instead as we no longer need to filter through all the projects in docker and parse which ones belong to tesseract as our DockerWrapper class already knows all the projects that are Tesseract.
  • Renamed _display_container_meta to _display_project_meta as I think it's more fitting to the function since we are listing the metadata of all the containers in a project, aka the project's metadata.
  • Migrated all calls to subprocess that already existed into the DockerWrapper class (docker_compose_up, docker_compose_down, docker_buildx)
    • pruning in docker_buildx is replaced with --no-cache in the build call
  • Replaced the mocked_docker from mocked docker_py to a mocked version of our own class.
  • Modified some unit tests to fit the new mocked class. (Note: For the get_all_images class, I'm not even sure why the original one was expecting len to be 1 when the mocked docker class had 2 images?)

Testing done

Unit tests + Manually tested commands:
serve build ps list teardown teardown --all apidoc

Remaining issues:

[ ] test_needs_docker fails because I can't properly create the RuntimeError side effect no matter what format I've tried to trigger it in.
[ ] Log handling may be incorrect in buildx since I'm not sure if we are streaming the build error logs correctly or not

License

  • [ x] By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • [ x] I sign the Developer Certificate of Origin below by adding my name and email address to the Signed-off-by line.
Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Signed-off-by: [Angela Ko] [email protected]

@angela-ko angela-ko added the enhancement New feature or request label Feb 25, 2025
@angela-ko
Copy link
Contributor Author

Found the problem with the print statements -- it was because of my docker_info function printing everything out, oops.

Fixing some end to end tests / issues after migrating the code. Will update soon.

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

Attention: Patch coverage is 24.80818% with 294 lines in your changes missing coverage. Please review.

Project coverage is 65.21%. Comparing base (2eb0d2e) to head (9d6b565).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tesseract_core/sdk/docker_client.py 21.86% 241 Missing and 2 partials ⚠️
tesseract_core/sdk/cli.py 12.82% 34 Missing ⚠️
tesseract_core/sdk/engine.py 58.53% 13 Missing and 4 partials ⚠️

❗ There is a different number of reports uploaded between BASE (2eb0d2e) and HEAD (9d6b565). Click for more details.

HEAD has 15 uploads less than BASE
Flag BASE (2eb0d2e) HEAD (9d6b565)
22 7
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #33       +/-   ##
===========================================
- Coverage   76.49%   65.21%   -11.29%     
===========================================
  Files          26       27        +1     
  Lines        2608     2823      +215     
  Branches      390      428       +38     
===========================================
- Hits         1995     1841      -154     
- Misses        452      835      +383     
+ Partials      161      147       -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@angela-ko
Copy link
Contributor Author

@xalelax Thank you for helping with the docker info issue... Mocks confuse me so much haha.

Will fix the rest of the failing tests (I think it's because i tried to remove the skip volume mount tests from the unit tests since I thought we were ready for that now, but might need some fine tuning or do in a separate PR)

@angela-ko angela-ko force-pushed the ako/docker branch 5 times, most recently from fb55fe6 to 7ff0d6a Compare March 10, 2025 17:33
@angela-ko angela-ko force-pushed the ako/docker branch 2 times, most recently from 0d71246 to 507f51e Compare March 28, 2025 14:21
@angela-ko angela-ko force-pushed the ako/docker branch 3 times, most recently from 8cea7bd to 0350a01 Compare April 1, 2025 17:50
    Replace prune cache with build --no-cache

    Fix unit tests - needs_docker test failing

Fix end to end tests and docker info

Testing unit tesseract tests since it's so slow on my machine

Switch from monkeypatched fixture to mocking actual method

Fix unused import

Reinsert mocked_docker fixture in test_needs_docker

Fix args which were missed in refactor

Fix run bug

Fix end to end tests

Handle empty docker result

Fix linter

Fixed end to end tests except one volume test

Put the skip mounts back

add arg to build tesseract

Add short id to container

Fix volume args

Handle cases where underlying resources may have been cleaned up already

Move all handling to update functions

Restructure docker cli

Update cli, engine, errors, and mocked

Revert test changes
Return raw str

Fix unit test again with updated container structure

Fix logs return type and decode

Fix log formatting and swap to serve in exampels test

change to stdout

Fix test_endtoend

Fix test examples

Reduce

In prog

Fix exit code

FIX FINAL UNIT TESTS BLESSSS

Prunes
@angela-ko angela-ko marked this pull request as ready for review April 4, 2025 05:44
@angela-ko angela-ko requested a review from xalelax as a code owner April 4, 2025 05:44
@dionhaefner
Copy link
Contributor

@angela-ko I had a closer look and fixed the issue with logging. I'll fix the remaining tests and smaller issues.

In the meantime, please apply the following adjustments:

  • Add extensive documentation (docstrings) outlining the scope + design philosophy of your CLI Docker client, essentially summarizing the discussion above.
  • Add unit tests against docker-py to increase confidence in the operational readiness of your implementation.

@xalelax
Copy link
Contributor

xalelax commented Apr 9, 2025

I had a brief look at the code + threads, and don't have much to add to this 👍 gj

@angela-ko angela-ko requested a review from dionhaefner April 11, 2025 05:24
@angela-ko
Copy link
Contributor Author

Fixed issue with a singular docker image with multiple tags and handling of short id.

Current unit tests fail only on github ci not locally so sorry about the incoming print statement spamming...

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

Successfully merging this pull request may close these issues.

Replace Docker Python SDK with Docker CLI
3 participants