Skip to content

Commit

Permalink
Docker, Develop, backport support
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoDerp committed Feb 24, 2024
1 parent 0bc6f03 commit cb8fb74
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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/

Expand Down Expand Up @@ -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/
Expand Down
28 changes: 24 additions & 4 deletions docs/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
```
</br>

_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

Expand Down

0 comments on commit cb8fb74

Please sign in to comment.