From cb8fb74dd00fdfe956bc2e13ef25b9c045857317 Mon Sep 17 00:00:00 2001 From: GeoDerp <18461782+GeoDerp@users.noreply.github.com> Date: Sun, 25 Feb 2024 00:29:02 +1030 Subject: [PATCH] Docker, Develop, backport support --- Dockerfile | 11 +++++++---- docs/develop.md | 28 ++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 15da6ab0..00b90e4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,10 +53,12 @@ RUN apt-get update \ #copy config file (on all builds) COPY config_emhass.yaml /app/ +# Make sure data directory exists +RUN mkdir -p /app/data/ + #------------------------- -#EMHASS-ADDON Default +#EMHASS-ADDON Default (this has no emhass packadge) FROM base as addon -COPY ./requirements_addon.txt /app/requirements.txt LABEL \ io.hass.name="emhass" \ @@ -70,7 +72,9 @@ ENTRYPOINT [ "python3", "-m", "emhass.web_server","--addon", "True", "--url", "h #----------- #EMHASS-ADD-ON Testing with pip emhass (closest testing reference) FROM addon as addon-pip -RUN pip3 install --no-cache-dir --break-system-packages --upgrade --upgrade-strategy=only-if-needed -U emhass +#set build arg for pip version +ARG build_pip_version="" +RUN pip3 install --no-cache-dir --break-system-packages --upgrade --upgrade-strategy=only-if-needed -U emhass${build_pip_version} COPY options.json /app/ @@ -105,7 +109,6 @@ WORKDIR /tmp/emhass #Branch RUN git checkout $build_branch RUN mkdir -p /app/src/emhass/ -RUN mkdir -p /app/data/ RUN cp -r /tmp/emhass/src/emhass/. /app/src/emhass/ RUN cp /tmp/emhass/data/opt_res_latest.csv /app/data/ RUN cp /tmp/emhass/setup.py /app/ diff --git a/docs/develop.md b/docs/develop.md index f697c5e9..027dbe7a 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -7,7 +7,7 @@ _Note: It is preferred to run both addon mode, standalone mode and unitest once ## Step 1 - Fork -_With your preferred git tool of choice:_ +_With your preferred Git tool of choice:_ Fork the EMHASS github repository into your own account, then clone the forked repository into your local development platform. (ie. PC or Codespace) ## Step 2 - Develop @@ -154,9 +154,9 @@ docker run -it -p 5000:5000 --name emhass-container -v $(pwd)/config_emhass.yaml _Standalone mode requires `secrets_emhass.yaml` to be set and passed in on operate. Copy `secrets_emhass(example).yaml` for an example._ -#### Docker run add-on with git or pip: +#### Docker run add-on with Git or pip: -If you would like to test with the current production/master versions of emhass, you can do so via pip or git. With git, you can also specify other repos/branches outside of `davidusb-geek/emhass:master`. +If you would like to test with the current production/master versions of emhass, you can do so via pip or Git. With Git, you can also specify other repos/branches outside of `davidusb-geek/emhass:master`. **addon-pip** will be the closest environment to the production emhass-add-on. However, both come with the disadvantage of not easily being able to edit the emhass package itself. @@ -188,8 +188,28 @@ docker build -t emhass/docker --build-arg build_version=addon-pip . docker run -it -p 5000:5000 --name emhass-container -e LAT="45.83" -e LON="6.86" -e ALT="4807.8" -e TIME_ZONE="Europe/Paris" -v $(pwd)/options.json:/app/options.json emhass/docker --url YOURHAURLHERE --key YOURHAKEYHERE ``` +To build with specific pip version, set with build arg: `build_pip_version`: +```bash +docker build -t emhass/docker --build-arg build_version=addon-pip --build-arg build_pip_version='==0.7.7' . + +docker run -it -p 5000:5000 --name emhass-container -e LAT="45.83" -e LON="6.86" -e ALT="4807.8" -e TIME_ZONE="Europe/Paris" -v $(pwd)/options.json:/app/options.json emhass/docker --url YOURHAURLHERE --key YOURHAKEYHERE +``` +
+ +_You can add or remove file volume mounts with the `-v` tag, this should override the file in the container (ex. options.json)_ + +#### EMHASS older then **0.7.9** +For older versions of EMHASS, you may wish to specify the _config_, _data_ and _options_ paths to avoid errors: +```bash +docker run ... -e OPTIONS_PATH='/app/options.json' -e CONFIG_PATH='/app/config_emhass.yaml' -e DATA_PATH='/app/data/' ... +``` +For example pip: +```bash +docker build -t emhass/docker --build-arg build_version=addon-pip . + +docker run -it -p 5000:5000 --name emhass-container -e LAT="45.83" -e LON="6.86" -e ALT="4807.8" -e TIME_ZONE="Europe/Paris" -e CONFIG_PATH='/app/config_emhass.yaml' -e DATA_PATH='/app/data/' -e OPTIONS_PATH='/app/options.json' -v $(pwd)/options.json:/app/options.json emhass/docker --url YOURHAURLHERE --key YOURHAKEYHERE +``` -_You can add or remove file volume mounts with the `-v` tag, this should override the file in the container (ex.options.json)_ #### Delete built Docker image