From 3d20aab3a908721597e93e79755a9635c90d14bc Mon Sep 17 00:00:00 2001 From: RonanMorgan <49660557+RonanMorgan@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:24:19 +0100 Subject: [PATCH] Create an small size image (#227) * feat: change engine classe in order to use it with directory * feat: create a light Dockerfile image * feat: Engine refactor for ETL * make style * refactor * revert ETL part * engine.py from main * update-new-datamodel is the source --------- Co-authored-by: Ronan Co-authored-by: Ronan --- .dockerignore | 4 ++++ Dockerfile-cpu | 35 +++++++++++++++++++++++++++++++++++ Makefile | 10 ++++++++-- src/requirements-light.txt | 10 ++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile-cpu create mode 100644 src/requirements-light.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..edac926e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git +*.pyc +__pycache__ +*.log diff --git a/Dockerfile-cpu b/Dockerfile-cpu new file mode 100644 index 00000000..7db55a72 --- /dev/null +++ b/Dockerfile-cpu @@ -0,0 +1,35 @@ +FROM python:3.8.16-slim + +# set environment variables +ENV PATH="/usr/local/bin:$PATH" +ENV LANG="C.UTF-8" +ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 +# set work directory +WORKDIR /usr/src/app + +COPY ./setup.py /tmp/setup.py + +# install git +RUN apt-get update && apt-get install git -y + +RUN apt-get install ffmpeg libsm6 libxext6 -y\ + && pip install --upgrade --no-cache-dir pip setuptools wheel + +RUN pip install --no-cache-dir torch==2.3.1+cpu torchvision==0.18.1+cpu -f https://download.pytorch.org/whl/torch_stable.html + +COPY ./src/requirements-light.txt /tmp/requirements.txt +RUN pip install --default-timeout=500 -r /tmp/requirements.txt \ + && pip cache purge \ + && rm -rf /root/.cache/pip + +RUN pip install --no-cache-dir git+https://github.com/pyronear/pyro-api.git@92b9e28fe4b329aa28c7833b28f3bc89ab1b756c#subdirectory=client + +COPY ./pyroengine /tmp/pyroengine + +RUN pip install -e /tmp/. \ + && pip cache purge \ + && rm -rf /root/.cache/pip + +COPY ./src/run.py /usr/src/app/run.py +COPY ./src/control_reolink_cam.py /usr/src/app/control_reolink_cam.py diff --git a/Makefile b/Makefile index fa39487e..ace601e1 100644 --- a/Makefile +++ b/Makefile @@ -26,12 +26,18 @@ lock: cd src; poetry export -f requirements.txt --without-hashes --output requirements.txt # Build the docker -build-app: - $(info if you need to update the client change the hash in the .toml and use make lock before) +build-gpu-app: + $(info If you need to update the client change the hash in the .toml and use make lock before) docker build . -t pyronear/pyro-engine:latest +# Build the light docker +build-cpu-app: + $(info The pyro-client version is hardcoded in the Dockerfile) + docker build . -t pyronear/pyro-engine:latest -f Dockerfile-cpu + build-lib: pip install -e . + python setup.py sdist bdist_wheel build-optional-lib: pip install -e .[test] diff --git a/src/requirements-light.txt b/src/requirements-light.txt new file mode 100644 index 00000000..9bf2f45c --- /dev/null +++ b/src/requirements-light.txt @@ -0,0 +1,10 @@ +python-dotenv==1.0.1 ; python_version >= "3.8" and python_version < "4.0" +coloredlogs==15.0.1 ; python_version >= "3.8" and python_version < "4.0" +flatbuffers==24.3.25 ; python_version >= "3.8" and python_version < "4.0" +humanfriendly==10.0 ; python_version >= "3.8" and python_version < "4.0" +onnx==1.17.0 ; python_version >= "3.8" and python_version < "4.0" +onnxruntime==1.19.2 ; python_version >= "3.8" and python_version < "4.0" +protobuf==5.28.2 ; python_version >= "3.8" and python_version < "4.0" + +huggingface-hub==0.24.6 ; python_version >= "3.8" and python_version < "4" +ultralytics==8.2.50 ; python_version >= "3.8" and python_version < "4.0"