|
| 1 | +# This is an example Dockerfile template and docker compose for deploying your agent in CVAT. |
| 2 | + |
| 3 | + |
| 4 | +## The general Dockerfile approach is: |
| 5 | + |
| 6 | +1. Select base image to use with your agent. |
| 7 | +2. Install necessary packages with a package manager. |
| 8 | +For example YOLO needs libxcb1, libgl1, libglib2.0-0 |
| 9 | +3. Install cvat-cli, and if you need any Python dependencies, you may put them to requirements.txt |
| 10 | +4. You should have `func.py` file that acts as adapter between your agent and CVAT. |
| 11 | +You can refer to existing adapters for YOLO, SAM2 or transformers for inspiration. (`/ai-models/detector/yolo/func.py`, |
| 12 | +`/ai-models/tracker/sam2/func.py`, `/ai-models/transformers/func.py`) |
| 13 | +5. Consider supporting some build args like `$USE_GPU` to allow users to choose between CPU and GPU |
| 14 | + versions of the image. |
| 15 | +For the models that we've implemented as agents we rely on `pytorch` CPU or GPU wheels. |
| 16 | +6. Your image should implement the following functionality |
| 17 | + - Register function that will be powered by your agent in CVAT. |
| 18 | + - Run agent that will be polling CVAT for new tasks (Entrypoint). |
| 19 | + - Deregister function in CVAT when it is not needed anymore. |
| 20 | + |
| 21 | +All three capabilities are powered by cvat-cli that authenticates in CVAT with provided API key and allows to |
| 22 | +register/deregister functions and run agents. |
| 23 | +Please refer to scripts [`entrypoint.sh`](./entrypoint.sh), [`function_registration.sh`](./function_registration.sh) |
| 24 | +and [`function_deregistration.sh`](./function_deregistration.sh) for examples of how to use cvat-cli to implement |
| 25 | +these capabilities. |
| 26 | + |
| 27 | +### General recommendations |
| 28 | +- Run your container with a non-root user. |
| 29 | +- Use lightweight base images to reduce the size of your image and speed up deployment. |
| 30 | +- Keep the frequently changing layers of your Docker closer to the end of your Dockerfile to take advantage of caching. |
| 31 | +- Always pin the versions of your dependencies. |
| 32 | + |
| 33 | +## Docker compose |
| 34 | +Once your image is built, use Docker Compose to manage the agent lifecycle. |
| 35 | +All services use the same image. |
| 36 | + |
| 37 | +1. It runs function registration script in the container (`cvat-function-register` service). |
| 38 | +2. `cvat-function-register` service creates a file on shared volume. |
| 39 | +3. `cvat-agent` service runs agents that connect to CVAT function that was created in step 1. |
| 40 | +4. When agent is not needed user should run `cvat-function-deregister` service manually to delete function from CVAT. |
| 41 | + (docker compose run --rm cvat-function-deregister) |
| 42 | + |
| 43 | +It's easy to configure docker compose using [`.env`](./.env) file that should be located in the same folder as `docker-compose.yaml` |
0 commit comments