Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

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

Open
haecker-felix opened this issue Aug 3, 2021 · 11 comments
Open

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

haecker-felix opened this issue Aug 3, 2021 · 11 comments

Comments

@haecker-felix
Copy link

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:

  • Open Firefox inspector
  • Click on Web-Storage tab
  • Click on local storage
  • Replace IP address with traefik / "external" dns name

I changed this
image

to this
image

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

Therefore I wonder

  • if we can add an input entry or something on the gateway page to enter a custom address?
  • if we can configure a custom address directly? (eg. by setting a docker env variable like DECONZ_ADDRESS=deconz.haeckerfelix.de), so we don't need any workaround?
@simonszu
Copy link

+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
Copy link

stale bot commented Oct 2, 2021

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.

@stale stale bot added the stale label Oct 2, 2021
@haecker-felix
Copy link
Author

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

@r4nc0r
Copy link

r4nc0r commented Oct 12, 2021

Yes pls make this possible :)

And thanks for the workaround!

@CheariX
Copy link

CheariX commented Nov 4, 2021

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.

@stale stale bot removed the stale label Nov 4, 2021
@simonszu
Copy link

simonszu commented Nov 5, 2021

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
Copy link

flecke-m commented Dec 1, 2021

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
Copy link

stale bot commented Jan 8, 2022

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.

@stale stale bot added the stale label Jan 8, 2022
@haecker-felix
Copy link
Author

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

@stale stale bot removed the stale label Jan 8, 2022
@stale
Copy link

stale bot commented Apr 16, 2022

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.

@stale stale bot added the stale label Apr 16, 2022
@simonszu
Copy link

No, the issue is still existing

@stale stale bot removed the stale label Apr 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants