dresden-elektronik / phoscon-app-beta

Access to Phoscon app beta
78 stars 5 forks source link

Allow setting a custom address / hostname for web app #413

Open haecker-felix opened 2 years ago

haecker-felix commented 2 years ago

I'm using deconz-docker image with Traefik as reverse proxy.

  deconz:
    image: "marthoc/deconz"
    restart: "unless-stopped"
    volumes:
      - "deconz:/root/.local/share/dresden-elektronik/deCONZ"
    devices:
      - "/dev/ttyACM0"
    environment:
      - "DECONZ_WEB_PORT=8080"
      - "DECONZ_WS_PORT=443"
      - "DECONZ_DEVICE=/dev/ttyACM0"
      - "TZ=Europe/Berlin"
      - "DEBUG_INFO=1"
      - "DEBUG_APS=0"
      - "DEBUG_ZCL=0"
      - "DEBUG_ZDP=0"
      - "DEBUG_OTAU=0"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.deconz.rule=Host(`deconz.haeckerfelix.de`)"
      - "traefik.http.routers.deconz.entrypoints=websecure"
      - "traefik.http.routers.deconz.tls=true"
      - "traefik.http.services.deconz.loadbalancer.server.port=8080"
    networks:
      web:
        ipv4_address: "172.18.0.5"

By default the web app only finds the service with the docker internal network ip address 172.18.0.5 which you cannot use (login / clicking on the gateway tile does nothing)

image

I found this workaround though:

I changed this image

to this image

... and I was able to use the web app through my traefik reverse proxy! :tada: image

Therefore I wonder

simonszu commented 2 years ago

+1 from me, but i had to change the port too, so it connected to traefik's "outside" endpoint and not to port 8081.

stale[bot] commented 2 years ago

As there hasn't been any response in 21 days, this issue has been automatically marked as stale. At OP: Please either close this issue or keep it active It will be closed in 7 days if no further activity occurs.

haecker-felix commented 2 years ago

This issue still exists, so please don't close it dear stale bot :)

r4nc0r commented 2 years ago

Yes pls make this possible :)

And thanks for the workaround!

CheariX commented 2 years ago

This bug has annoyed my for a long time... so I came up with this solution:

Basically, i put my deCONZ Gateway into the toCheck variable using sed.

FROM marthoc/deconz:amd64-2.13.01
RUN sed -i "s/var toCheck = \[\];/var toCheck = \['my.deconz.host.example.com'\];/" /usr/share/deCONZ/webapp/pwa/login.html

Maybe @marthoc is interested to implement this fix into his Docker image. I'm pretty sure someone smarter than me can figure out how to create the desired DECONZ_ADDRESS variable.

simonszu commented 2 years ago

This could be done with the help of an environment variable, and putting this sed command into the start.sh script of the dockerfile, for example here

Just add the sed command there, and replace the my.deconz.host.example.com with an env variable like $DECONZ_HOST. You would need some logic to set a default value for that variable, this is best done in the Dockerfile since it has the least priority, so just add ENV DECONZ_HOST my.deconz.host.example.com to the Dockerfile, for example here.

After building the image and executing, you can specify the host in the env variable on runtime, and the entrypoint script will replace the value every time the container starts. Maybe you need to add a catchall regex to the source part of sed, since after the first execution of the container, it won't have the [] string inside this file whenever the container is restarted without deleting it.

I have little time, and this design to have three different Dockerfiles and three different entrypoint scripts is uncomfortable, so i'll leave the actual implementation to someone else.

flecke-m commented 2 years ago

Thank you for the hints for a solution to have a host URL working for the deconz docker image.

Maybe the issue should be put to https://github.com/deconz-community/deconz-docker/issues because it seems to be only for adjusting the Dockerfile and docker start.sh

I have tried to build a deconz image locally with the sed command provided here and it was a bit tricky, because putting it just in the entry script before deconz is started will not have any effect.

Therefore I had to put deconz in the background and wait some seconds (20 might be too much, but it was for testing and making sure it will be propagated after the Phoscon Webapp is up) and execute the sed command. It is now working as expected with the proxied URL (I am using traefik with SSL).

It is also working for restart of the container (docker restart deconz). I have not yet done a negative test without setting the variable, but when it defaults to 0 the sed command will not be triggered.

Here are my changes:

In the dockerfile I have just added the environment variable:

 # Runtime environment variables

ENV DEBIAN_FRONTEND=noninteractive \
    DECONZ_VERSION=${VERSION} \
    DECONZ_WEB_PORT=80 \
    DECONZ_WS_PORT=443 \
    DEBUG_INFO=1 \
    DEBUG_APS=0 \
    DEBUG_ZCL=0 \
    DEBUG_ZDP=0 \
    DEBUG_OTAU=0 \
    DEBUG_ERROR=0 \
    DECONZ_DEVICE=0 \
    DECONZ_VNC_MODE=0 \
    DECONZ_VNC_DISPLAY=0 \
    DECONZ_VNC_PASSWORD=changeme \
    DECONZ_VNC_PASSWORD_FILE=0 \
    DECONZ_VNC_PORT=5900 \
    DECONZ_NOVNC_PORT=6080 \
    DECONZ_UPNP=1 \
    DECONZ_UID=1000 \
    DECONZ_GID=1000 \
    DECONZ_START_VERBOSE=0 \
# added environment variable
    DECONZ_ADDRESS=0

# Install deCONZ dependencies
RUN apt-get update && \`

The startup script was a bit tricky basically the functional work around are the following lines at the end. Probably with putting the deconz app in the background it is not the best way to do it.

First I have echoed the WebAddress so it is logged. I also put a comment with echo when the var toCheck was set.

#!/bin/sh

if [ "$DECONZ_START_VERBOSE" = 1 ]; then
  set -x
fi

echo "[deconzcommunity/deconz] Starting deCONZ..."
echo "[deconzcommunity/deconz] Current deCONZ version: $DECONZ_VERSION"
echo "[deconzcommunity/deconz] Web UI port: $DECONZ_WEB_PORT"
echo "[deconzcommunity/deconz] Websockets port: $DECONZ_WS_PORT"
# added echo
echo "[deconzcommunity/deconz] DeconzWebAddress: $DECONZ_ADDRESS"

....

chown deconz:deconz /opt/deCONZ -R

#workaraound for setting sed command after deconz startup, putting deconz in background

sudo -u deconz /usr/bin/deCONZ $DECONZ_OPTS &

sleep 20s

if [ "$DECONZ_ADDRESS" != 0 ]; then
  sed -i "s/var toCheck = \[\];/var toCheck = \['$DECONZ_ADDRESS'\];/" /usr/share/deCONZ/webapp/pwa/login.html
  echo "Deconz URL is set"
fi

# wait is needed to wait for the background process

wait

As this is my first proposal for changing the docker file and script someone with more experience should have look at it before opening a pull request to the docker image.

stale[bot] commented 2 years ago

As there hasn't been any response in 21 days, this issue has been automatically marked as stale. At OP: Please either close this issue or keep it active It will be closed in 7 days if no further activity occurs.

haecker-felix commented 2 years ago

Again - This issue still exists, so please don't close it dear stale bot :)

stale[bot] commented 2 years ago

As there hasn't been any response in 21 days, this issue has been automatically marked as stale. At OP: Please either close this issue or keep it active It will be closed in 7 days if no further activity occurs.

simonszu commented 2 years ago

No, the issue is still existing