diff --git a/3dprinter-octoprint/CHANGELOG.md b/3dprinter-octoprint/CHANGELOG.md index 01084fc..05c094f 100644 --- a/3dprinter-octoprint/CHANGELOG.md +++ b/3dprinter-octoprint/CHANGELOG.md @@ -1,3 +1,13 @@ +- 2022.12.01 + - Add mode for camera (for testing). + - Set Caddy to trust private ranges on Ingress entry. + +- 2022.11.01 + - Add reverse proxy config for camera with Ingress (untested). + - Only create OctoPrint user if missing. + - Update documentation. + - Mark mode optional. + - Update OctoPrint to 1.8.6 - Update icon to coloured nozzle. - Clean-up Caddy config. diff --git a/3dprinter-octoprint/DOCS.md b/3dprinter-octoprint/DOCS.md index ef72f39..00adea1 100644 --- a/3dprinter-octoprint/DOCS.md +++ b/3dprinter-octoprint/DOCS.md @@ -1,3 +1,15 @@ -# Dev -> image: ghcr.io/fredrikbaberg/addon-3dprinter-octoprint-{arch} +# Addon configuration +## Camera URL + +**Note: Currently not working.** + +Through setting a camera URL you should be able to access the camera stream even when using Ingress. + +## Mode + +By specifying a different mode you can instead access recovery and reverse proy test page. Normally this should not be needed. + +# Notes etc. + +> image: ghcr.io/fredrikbaberg/addon-3dprinter-octoprint-{arch} diff --git a/3dprinter-octoprint/Dockerfile b/3dprinter-octoprint/Dockerfile index b8f40fe..23dc61a 100644 --- a/3dprinter-octoprint/Dockerfile +++ b/3dprinter-octoprint/Dockerfile @@ -2,12 +2,11 @@ ARG BUILD_FROM="ghcr.io/home-assistant/amd64-base-debian:bullseye" FROM ${BUILD_FROM} ARG OCTOPRINT_VERSION="1.8.6" -ENV OCTOPRINT_VERSION=${OCTOPRINT_VERSION} - # Setup path for persistent install of Python packages ENV PYTHONPATH=/data/python/octoprint ENV PYTHONUSERBASE=/data/python/octoprint ENV PATH=/data/python/octoprint/bin:${PATH} +ENV OCTOPRINT_VERSION=${OCTOPRINT_VERSION} # Preparation for install of Caddy RUN apt update \ @@ -30,7 +29,7 @@ RUN apt update \ build-essential \ caddy \ # Extras. - # ffmpeg \ + ffmpeg \ # avrdude \ # dfu-util \ # dfu-programmer \ diff --git a/3dprinter-octoprint/README.md b/3dprinter-octoprint/README.md index e5dcc29..4529770 100644 --- a/3dprinter-octoprint/README.md +++ b/3dprinter-octoprint/README.md @@ -1,5 +1,5 @@ # 3DPrinter-OctoPrint -Provides OctoPrint as an addon to Home Assistant. +**Note: Currently not in a ready-to-use state.** -**Note: Currently not in a ready-to-use state.** \ No newline at end of file +Provides OctoPrint as an addon to Home Assistant. diff --git a/3dprinter-octoprint/config.yaml b/3dprinter-octoprint/config.yaml index bfde696..d63d231 100644 --- a/3dprinter-octoprint/config.yaml +++ b/3dprinter-octoprint/config.yaml @@ -1,5 +1,5 @@ name: "3DPrinter-OctoPrint" -version: "2022.11.0" +version: "2022.12.01" slug: "3dprinter-octoprint" description: "OctoPrint as an addon, no additional bells and whistles." url: "https://github.com/fredrikbaberg/home-assistant-addons/tree/main/3dprinter-octoprint" @@ -24,9 +24,9 @@ ports: ports_description: 5000/tcp: Web-based interface (Not required for Ingress) options: - camera_url: "http://b7aa59c4-camera-mjpg-streamer/" + camera_url: "http://b7aa59c4-camera-mjpg-streamer" mode: normal schema: camera_url: "url?" - mode: "list(normal|recovery|reverse_proxy_test)" + mode: "list(normal|recovery|reverse_proxy_test|camera)?" tmpfs: true diff --git a/3dprinter-octoprint/rootfs/etc/caddy/Caddyfile b/3dprinter-octoprint/rootfs/etc/caddy/Caddyfile index bd7a1ab..b77bab1 100644 --- a/3dprinter-octoprint/rootfs/etc/caddy/Caddyfile +++ b/3dprinter-octoprint/rootfs/etc/caddy/Caddyfile @@ -1,9 +1,8 @@ -# This file is a placeholder and will be replaced on launch. +# Temporary file, will be overwritten on launch. { debug log { format console - output file /var/log/caddy.log + output file /var/log/caddy/caddy.log } } -# import configs/*.caddy diff --git a/3dprinter-octoprint/rootfs/etc/cont-init.d/octoprint.sh b/3dprinter-octoprint/rootfs/etc/cont-init.d/octoprint.sh index f2ed904..cb1620e 100644 --- a/3dprinter-octoprint/rootfs/etc/cont-init.d/octoprint.sh +++ b/3dprinter-octoprint/rootfs/etc/cont-init.d/octoprint.sh @@ -28,12 +28,12 @@ if [ ! -f /data/config/octoprint/config.yaml ]; then fi fi -# TODO: Check if user already exists before setting password. { # Make sure Ingress user for OctoPrint exists. bashio::log.notice "Ensure Ingress user (homeassistant) exist." - new_password=$(date +%s | sha256sum | base64 | head -c 32 ; echo) - new_password=homeassistant - octoprint --basedir /data/config/octoprint user add homeassistant --password "$new_password" --group users --group admins # 2> /dev/null + if ! octoprint --basedir /data/config/octoprint user list | grep -q 'homeassistant'; then + new_password=$(date +%s | sha256sum | base64 | head -c 32 ; echo) + octoprint --basedir /data/config/octoprint user add --password "$new_password" --admin homeassistant # 2> /dev/null + fi } || { # catch bashio::log.warning "Failed to ensure Ingress user exists, may not be able to launch." } diff --git a/3dprinter-octoprint/rootfs/etc/cont-init.d/proxy.sh b/3dprinter-octoprint/rootfs/etc/cont-init.d/proxy.sh index 6118176..02ff578 100644 --- a/3dprinter-octoprint/rootfs/etc/cont-init.d/proxy.sh +++ b/3dprinter-octoprint/rootfs/etc/cont-init.d/proxy.sh @@ -4,7 +4,7 @@ # Configures proxy # ============================================================================== -# Generate proxy configuration +# Generate proxy configuration for Ingress bashio::var.json \ interface "$(bashio::addon.ip_address)" \ port "^$(bashio::addon.ingress_port)" \ @@ -12,5 +12,5 @@ bashio::var.json \ camera_host "$(bashio::config 'camera_url')" \ mode "$(bashio::config 'mode')" \ | tempio \ - -template /usr/share/tempio/Caddyfile.gtpl \ + -template /usr/share/tempio/caddy/Caddyfile.gtpl \ -out /etc/caddy/Caddyfile diff --git a/3dprinter-octoprint/rootfs/usr/share/tempio/Caddyfile.gtpl b/3dprinter-octoprint/rootfs/usr/share/tempio/caddy/Caddyfile.gtpl similarity index 50% rename from 3dprinter-octoprint/rootfs/usr/share/tempio/Caddyfile.gtpl rename to 3dprinter-octoprint/rootfs/usr/share/tempio/caddy/Caddyfile.gtpl index 7a9b521..863eb4f 100644 --- a/3dprinter-octoprint/rootfs/usr/share/tempio/Caddyfile.gtpl +++ b/3dprinter-octoprint/rootfs/usr/share/tempio/caddy/Caddyfile.gtpl @@ -2,7 +2,7 @@ debug log { format console - output file /var/log/caddy.log + output file /var/log/caddy/caddy.log } } @@ -11,19 +11,30 @@ remote_ip 172.30.32.2 } uri strip_prefix {{ .ingress_entry }} + + handle_path /camera/* { + reverse_proxy @ingress {{ .camera_host }} { + } + } + handle { - {{ if eq .mode "recovery" }} + {{ if eq .mode "camera" }} + reverse_proxy @ingress {{ .camera_host }} { + trusted_proxies 172.30.32.2 + } + {{ else if eq .mode "recovery" }} rewrite / /recovery {{ else if eq .mode "reverse_proxy_test" }} rewrite / /reverse_proxy_test {{ end }} reverse_proxy @ingress 127.0.0.1:80 { header_up X-Script-Name {{ .ingress_entry }} - header_up -Origin - header_up Origin 172.30.32.2 - header_up X-Forwarded-For 172.30.32.2 - header_up X-Scheme {scheme} - flush_interval -1 + trusted_proxies 172.30.32.2 + # header_up -Origin + # header_up Origin 172.30.32.2 + # header_up X-Forwarded-For 172.30.32.2 + # header_up X-Scheme {scheme} + # flush_interval -1 } } }