kellerza / sunsynk

Deye/Sunsynk Inverter Python library and Home Assistant OS Addon
https://kellerza.github.io/sunsynk/
MIT License
206 stars 88 forks source link

ERROR [sunsynk-multi 3/5] COPY sunsynk sunsynk when trying to create a Docker Image #183

Closed WarrenFoxley closed 11 months ago

WarrenFoxley commented 1 year ago

Issue related to

Docker Standalone Sunsynk / mbusd Home Assistant Add-On

Describe the issue/bug

When following the instructions here to get the Sunsynk Addon running in a stand-alone docker I get the following:

When running BUILD_FROM=ghcr.io/home-assistant/armv7-base docker compose build sunsynk-multi

I get the following error:

 => ERROR [sunsynk-multi 3/5] COPY sunsynk sunsynk                                                                                                       0.0s
------
 > [sunsynk-multi 3/5] COPY sunsynk sunsynk:
------
failed to solve: failed to compute cache key: "/sunsynk" not found: not found

Expected behavior I was expecting the docker image to be built successfully.

Your environment

You configuration

options.yaml:


DRIVER: umodbus
INVERTERS:
- SERIAL_NR: '007'
  HA_PREFIX: SS
  MODBUS_ID: 1
  PORT: tcp://mbusd:502
SENSOR_DEFINITIONS: single-phase
SENSORS:
- total_pv_energy
- total_battery_charge
- total_battery_discharge
- total_grid_export
- total_grid_import
- battery_soc
SENSORS_FIRST_INVERTER: []
MANUFACTURER: Sunsynk
READ_SENSORS_BATCH_SIZE: 60
NUMBER_ENTITY_MODE: auto
MQTT_HOST: core-mosquitto
MQTT_PORT: 1883
MQTT_USERNAME: hass
MQTT_PASSWORD: ''
DEBUG: 0
DEBUG_DEVICE: "/dev/ttyAMA0"

Logs


=> [sunsynk-multi internal] load build definition from Dockerfile                                                                                       0.0s
 => => transferring dockerfile: 32B                                                                                                                      0.0s
 => [sunsynk-multi internal] load .dockerignore                                                                                                          0.0s
 => => transferring context: 2B                                                                                                                          0.0s
 => [sunsynk-multi internal] load metadata for ghcr.io/home-assistant/armv7-base:latest                                                                  0.5s
 => [sunsynk-multi internal] load build context                                                                                                          0.1s
 => => transferring context: 257B                                                                                                                        0.0s
 => CANCELED [sunsynk-multi 1/5] FROM ghcr.io/home-assistant/armv7-base@sha256:8e34aa723ed323140f01c7e6bbbed30de243b140ecaed5bf6311b6e33f5afaa8          0.1s
 => => resolve ghcr.io/home-assistant/armv7-base@sha256:8e34aa723ed323140f01c7e6bbbed30de243b140ecaed5bf6311b6e33f5afaa8                                 0.0s
 => => sha256:8e34aa723ed323140f01c7e6bbbed30de243b140ecaed5bf6311b6e33f5afaa8 947B / 947B                                                               0.0s
 => => sha256:89386b2d769642dacdd4ea159cb52648f1b0630eaf778ad090b4c00a916bad84 5.02kB / 5.02kB                                                           0.0s
 => CACHED [sunsynk-multi 2/5] RUN set -x     && apk add --no-cache --virtual .build-deps         build-base     && pip3 install --no-cache-dir --disab  0.0s
 => ERROR [sunsynk-multi 3/5] COPY sunsynk sunsynk                                                                                                       0.0s
------
 > [sunsynk-multi 3/5] COPY sunsynk sunsynk:
------
failed to solve: failed to compute cache key: "/sunsynk" not found: not found
WarrenFoxley commented 1 year ago

I think the offending line is /hass-addon-sunsynk-multi/Dockerfile#L22C1-L22C1.

But I am no Docker compose guru. so not sure why or how. 😞

kellerza commented 1 year ago

I've changed the build, but have not really taken the standalone docker builds into account yet.

In the official build, I do the following:

          mkdir -p hass-addon-sunsynk-multi/sunsynk
          cp -r src hass-addon-sunsynk-multi/sunsynk/
          cp setup.* README.md hass-addon-sunsynk-multi/sunsynk/

So your options are:

  1. Use an already-built image: like this. If the architecture matches. amd64 might work. The advantage here is that you are not building anything locally, simly pulling the correct pre-built image
  2. Use a modified Dockerfile, similar to the old one that pulls the package from pypi:
    # COPY sunsynk sunsynk
    pip install sunsynk[umodbus,pymodbus,solarman]==0.5.9
  3. Copy the sunsynk source to the correct folder, similar to what I do in the official builds see here
WarrenFoxley commented 1 year ago

Thanks @kellerza !

Tried out your option 1 (use already built image). But the container is failing to start. It seems it cannot find the linked .local.yaml file when starting up. I have linked this file to the options.yaml on the host pi as per the docker-compose file. 🤔

I pulled the pre-built image down and started a container from it with the volume settings lifted from the docker-compose file. This was all done in Portainer.

Full log:

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun sunsynk (no readiness notification)
s6-rc: info: service legacy-services successfully started
19:36:26 INFO    Local test mode
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/local/lib/python3.11/site-packages/ha_addon_sunsynk_multi/__main__.py", line 72, in <module>
    main()
  File "/usr/local/lib/python3.11/site-packages/ha_addon_sunsynk_multi/__main__.py", line 59, in main
    init_options()
  File "/usr/local/lib/python3.11/site-packages/ha_addon_sunsynk_multi/options.py", line 87, in init_options
    localf = Path(".local.yaml").resolve(True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/pathlib.py", line 993, in resolve
    s = os.path.realpath(self, strict=strict)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 416, in realpath
  File "<frozen posixpath>", line 451, in _joinrealpath
FileNotFoundError: [Errno 2] No such file or directory: '.local.yaml'
[19:36:26] WARNING: Halt add-on with exit code 1
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Any pointers on where I am going wrong? 😅

kellerza commented 1 year ago

The working dir must be different in the new build, since it does not use /src/app.

Can you try the edge tag on the container and then bind it to /data/options.yaml ?

https://github.com/kellerza/sunsynk/commit/4978907fa1ee0bfd68ec1dcbe3e1fcf905fbbbc6

WarrenFoxley commented 1 year ago

Good morning!

I gave that a bash this morning and still got the same errors as in my previous post... looking at your changes, maybe the image was built with the wrong code version? Because I see no more references to ".local.yaml" in the code but yet it still complained about that file. and I saw no new log printout that read "No configuration file found" when starting the container.

kellerza commented 1 year ago

Ok, so the latest edge or d49b09e contains these changes.

WarrenFoxley commented 1 year ago

Hey! That did it! Yay!

Thank you so much for your efforts! I appreciate it a ton!

kellerza commented 1 year ago

Great, you found a bug in the build as well 😉

If you can update the compose docs page I'd appreciate it!

Each page has a link to where you can fork/edit/create the PR... you should be able to modify a single page directly from the browser. Tbh, It might even make sense to inclue the entire dcoker-compose.yaml example on the docs page rather than in the repo as it is today. It's a fairly short file.

WarrenFoxley commented 1 year ago

Ye - sure. I'll take a look tonight and I'll get a PR up.

jpmeijers commented 11 months ago

The current standalone deployment is still broken.

I just reinstalled my setup on a Raspberry Pi 3, with the original standalone deployment docs are written for a Raspberry Pi 1.

The steps I had to follow are:

Install Docker

https://docs.docker.com/engine/install/debian/ https://docs.docker.com/engine/install/linux-postinstall/ https://docs.docker.com/config/containers/logging/json-file/

Install git and pull this repo

sudo apt install git
git clone https://github.com/kellerza/sunsynk.git
cd sunsynk/

Check architecture

uname -m - aarch64 on pi3

Docker compose changes

In docker-compose.yaml replace build with image, according to your architecture (aarch64 for pi3):

    image: ghcr.io/kellerza/hass-addon-sunsynk-multi/aarch64:stable
#    build:
#      context: hass-addon-sunsynk-multi
#      dockerfile: Dockerfile
#      args:
#        BUILD_FROM: ${BUILD_FROM}

Update options path:

    volumes:
      - ${PWD}/options.yaml:/data/options.yaml

Build images

Prefix with correct HA base image for architecture (aarch64 for pi3) BUILD_FROM=homeassistant/aarch64-base-python:3.11-alpine3.18 docker compose build

Create config file

nano options.yaml # or copy template and modify

Optional: Mount specific devices under /dev/ttyRS232 and /dev/ttyRS485

sudo nano /etc/udev/rules.d/10-usb-serial.rules and add

SUBSYSTEM=="tty", ATTRS{idProduct}=="6015", ATTRS{idVendor}=="0403", SYMLINK+="ttyRS232"
SUBSYSTEM=="tty", ATTRS{idProduct}=="6001", ATTRS{idVendor}=="0403", SYMLINK+="ttyRS485"

Start stack

docker compose up mbusd
# ctrl-c to stop
docker compose up sunsynk-multi
# ctrl-c to stop
docker compose up -d

What we need to do

@kellerza can you assist with this last point? I'm not sure what changes you made recently that broke the Dockerfile.