Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker image configuration is not working as described #56

Open
thielepaul opened this issue Dec 4, 2023 · 15 comments · May be fixed by #70
Open

Docker image configuration is not working as described #56

thielepaul opened this issue Dec 4, 2023 · 15 comments · May be fixed by #70
Labels
enhancement New feature or request question Further information is requested

Comments

@thielepaul
Copy link
Contributor

I just tested the docker image and the configuration through env variables is not working yet.

Looking at your dockerfile (https:/DennisOSRM/hms-mqtt-publisher/blob/main/Dockerfile#L38) it looks like this line should be part of an entrypoint script instead of being executed during build with RUN.

I can also create a PR if you are interested.

$ docker run --rm -it dennisosrm/hms-mqtt-publisher cat config.toml

inverter_host = ""

[home_assistent]
host = ""
username = ""
password = ""
port =
@AFPass
Copy link

AFPass commented Dec 5, 2023

I can't start Docker either.

What do i have to do?
Thanks

thread 'main' panicked at src/main.rs:46:52: toml config unparsable: Error { inner: Error { inner: TomlError { message: "invalid string\nexpected ", '", original: Some("inverter_host = \"\" \n\n[home_assistent] \nhost = \"\"\nusername = \"\"\npassword = \"\"\nport = \n\n"), keys: [], span: Some(84..85) } } } note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

@dominikandreas
Copy link
Collaborator

Right, the environment variables used to build the container are only used during the build step and can't be passed later on.

Having an entrypoint script that essentially does the same thing as the line in the Dockerfile that creates the config.toml should work fine. Feel free to open a PR for this.

To get it running in the meantime, you can create the config.toml locally and the run the container via docker run --rm -it -v ./config.toml:/config.toml dennisosrm/hms-mqtt-publisher

@DennisOSRM
Copy link
Owner

I will think of a better way to supply the configuration at runtime. Seems this is bothering too many people at this point.

@DennisOSRM
Copy link
Owner

I have a first draft in #61. It will simply override anything that's in the toml file (or not) at startup when it is defined in environment variables. Not super elegant, but should get the job done.

@dominikandreas
Copy link
Collaborator

I was wondering whether you could use something like this: https:/softprops/envy, but I guess it's a bit tricky to do with the separate structs

@DennisOSRM
Copy link
Owner

Oh, that one is interesting. Thanks for sharing.

@DennisOSRM DennisOSRM added enhancement New feature or request question Further information is requested labels Dec 9, 2023
@marchorst
Copy link

marchorst commented Dec 11, 2023

Why not simply use a Docker Compose file and assign the configuration file?

`
version: '3'

services:
hms-mqtt-publisher:
image: dennisosrm/hms-mqtt-publisher
volumes:
- ./config.toml:/config.toml
`

@thielepaul
Copy link
Contributor Author

Why not simply use a Docker Compose file and assign the configuration file?

`
version: '3'

services:
hms-mqtt-publisher:
image: dennisosrm/hms-mqtt-publisher
volumes:
- ./config.toml:/config.toml
`

Using environment variables for configuring containers is a best practice: https://12factor.net/config

@iSnackyCracky
Copy link

It looks like there's also a typo in this config :D

It should be [home_assistant] instead of [home_assistent]
I almost pulled my hair out trying to figure out why nothing was happening after providing the config.toml as a volume to the container and the log just seemed to stop after "Inverter is Online" (even with RUST_LOG=debug)

After changing to [home_assistant] and restarting the container once more, messages were instantly published via MQTT and received in Home Assistant!

@DennisOSRM
Copy link
Owner

Typo has been fixed in the latest main branch. Thanks again for reporting.

joemat pushed a commit to joemat/hms-mqtt-publisher that referenced this issue Dec 21, 2023
…etter readable

* Fixed putting values from environment variables to config.toml

* fixes DennisOSRM#56
@joemat joemat linked a pull request Dec 21, 2023 that will close this issue
2 tasks
@tsfuchs
Copy link

tsfuchs commented Feb 19, 2024

Hello everyone,

first of all, thank you very much @DennisOSRM for the short-term implementation of a solution for all those troubled with HMS-xxxxW-2T.
Since I've also owned an HMS-800W-2T for a few days now, I've been figuring out how to get the system information into my iobroker and attempted to get your script running as a Docker Compose container. Unfortunately, I also encountered difficulties in getting the host and MQTT parameters into the docker container. I've now solved it by manually creating the config.toml outside of the container. This way, I can also adjust the new adapted parameters from some issues regarding Hoymiles Cloud, etc. (coop-mode, update_interval) accordingly.

config.toml:

inverter_host = "xxx.xxx.xxx.xxx"
coop_mode = true # that the s-miles cloud is working
update_interval = 60500 # Should not less than 60500

#[home_assistant]
#host = "xxx.xxx.xxx.xxx"
#username = ""
#password = ""
#port = 188x

[simple_mqtt]
host = "xxx.xxx.xxx.xxx"
username = ""
password = ""
port = 188x

compose.yaml:

version: "3.3"
services:
  hms-mqtt-publisher:
    image: dennisosrm/hms-mqtt-publisher
    restart: unless-stopped
    volumes:
      - ./config.toml:/config.toml
networks: {}

@FRWDBurg
Copy link

FRWDBurg commented Mar 2, 2024

Hello,

I have the same problem:
thread 'main' panicked at src/main.rs:55:52: toml config unparsable: Error { inner: Error { inner: TomlError { message: "invalid string\nexpected ", '", original: Some("inverter_host = \"\" \n\n[home_assistant] \nhost = \"\"\nusername = \"\"\npassword = \"\"\nport = \n\n"), keys: [], span: Some(84..85) } } } note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Try to start the hms-publisher using the following docker compose file:

hmsMQTTPublisher:
  image: dennisosrm/hms-mqtt-publisher:latest
  container_name: hmsMQTTPublisher
  environment:
    INVERTER_HOST: 192.168.178.59
    MQTT_BROKER_HOST: 192.168.178.40
    MQTT_USERNAME: 
    MQTT_PASSWORD: 
    MQTT_PORT: 1883
  restart: unless-stopped

Can someone help me and tell me where the problem is?
Thank you

@FRWDBurg
Copy link

FRWDBurg commented Mar 6, 2024

Sorry for asking, but I can't get any further with tsfuchs' advice.
I created the config.toml and tried to start it with compose.yaml. There is the following error:
Failure failed to deploy a stack: Network hms_mqtt_publisher_default Creating Network hms_mqtt_publisher_default Created Container hms_mqtt_publisher-hms-mqtt-publisher-1 Creating Container hms_mqtt_publisher-hms-mqtt-publisher-1 Created Container hms_mqtt_publisher-hms-mqtt-publisher-1 Starting Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/data/compose/8/config.toml" to rootfs at "/config.toml": mount /data/compose/8/config.toml:/config.toml (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

@thielepaul
Copy link
Contributor Author

Sorry for asking, but I can't get any further with tsfuchs' advice.
I created the config.toml and tried to start it with compose.yaml. There is the following error:
Failure failed to deploy a stack: Network hms_mqtt_publisher_default Creating Network hms_mqtt_publisher_default Created Container hms_mqtt_publisher-hms-mqtt-publisher-1 Creating Container hms_mqtt_publisher-hms-mqtt-publisher-1 Created Container hms_mqtt_publisher-hms-mqtt-publisher-1 Starting Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/data/compose/8/config.toml" to rootfs at "/config.toml": mount /data/compose/8/config.toml:/config.toml (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

This sounds like the config.toml file is either not existing or not at the correct path

@FRWDBurg
Copy link

FRWDBurg commented Mar 9, 2024

Hello @thielepaul, thank you very much for your support. It's almost embarrassing, but the config.toml was in a config.toml folder.
I didn't recognize via the console that it was a folder and not a file. Everything is working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
8 participants