Merge pull request #19 from fredrikbaberg/dev_octoprint

Simplify Caddy config
This commit is contained in:
Fredrik Baberg 2022-12-14 00:57:09 +01:00 committed by GitHub
commit 8512c2959a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 26 deletions

View File

@ -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 OctoPrint to 1.8.6
- Update icon to coloured nozzle. - Update icon to coloured nozzle.
- Clean-up Caddy config. - Clean-up Caddy config.

View File

@ -1,3 +1,15 @@
# Dev # Addon configuration
> image: ghcr.io/fredrikbaberg/addon-3dprinter-octoprint-{arch}
## 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}

View File

@ -2,12 +2,11 @@ ARG BUILD_FROM="ghcr.io/home-assistant/amd64-base-debian:bullseye"
FROM ${BUILD_FROM} FROM ${BUILD_FROM}
ARG OCTOPRINT_VERSION="1.8.6" ARG OCTOPRINT_VERSION="1.8.6"
ENV OCTOPRINT_VERSION=${OCTOPRINT_VERSION}
# Setup path for persistent install of Python packages # Setup path for persistent install of Python packages
ENV PYTHONPATH=/data/python/octoprint ENV PYTHONPATH=/data/python/octoprint
ENV PYTHONUSERBASE=/data/python/octoprint ENV PYTHONUSERBASE=/data/python/octoprint
ENV PATH=/data/python/octoprint/bin:${PATH} ENV PATH=/data/python/octoprint/bin:${PATH}
ENV OCTOPRINT_VERSION=${OCTOPRINT_VERSION}
# Preparation for install of Caddy # Preparation for install of Caddy
RUN apt update \ RUN apt update \
@ -30,7 +29,7 @@ RUN apt update \
build-essential \ build-essential \
caddy \ caddy \
# Extras. # Extras.
# ffmpeg \ ffmpeg \
# avrdude \ # avrdude \
# dfu-util \ # dfu-util \
# dfu-programmer \ # dfu-programmer \

View File

@ -1,5 +1,5 @@
# 3DPrinter-OctoPrint # 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.** Provides OctoPrint as an addon to Home Assistant.

View File

@ -1,5 +1,5 @@
name: "3DPrinter-OctoPrint" name: "3DPrinter-OctoPrint"
version: "2022.11.0" version: "2022.12.01"
slug: "3dprinter-octoprint" slug: "3dprinter-octoprint"
description: "OctoPrint as an addon, no additional bells and whistles." description: "OctoPrint as an addon, no additional bells and whistles."
url: "https://github.com/fredrikbaberg/home-assistant-addons/tree/main/3dprinter-octoprint" url: "https://github.com/fredrikbaberg/home-assistant-addons/tree/main/3dprinter-octoprint"
@ -24,9 +24,9 @@ ports:
ports_description: ports_description:
5000/tcp: Web-based interface (Not required for Ingress) 5000/tcp: Web-based interface (Not required for Ingress)
options: options:
camera_url: "http://b7aa59c4-camera-mjpg-streamer/" camera_url: "http://b7aa59c4-camera-mjpg-streamer"
mode: normal mode: normal
schema: schema:
camera_url: "url?" camera_url: "url?"
mode: "list(normal|recovery|reverse_proxy_test)" mode: "list(normal|recovery|reverse_proxy_test|camera)?"
tmpfs: true tmpfs: true

View File

@ -1,9 +1,8 @@
# This file is a placeholder and will be replaced on launch. # Temporary file, will be overwritten on launch.
{ {
debug debug
log { log {
format console format console
output file /var/log/caddy.log output file /var/log/caddy/caddy.log
} }
} }
# import configs/*.caddy

View File

@ -28,12 +28,12 @@ if [ ! -f /data/config/octoprint/config.yaml ]; then
fi fi
fi fi
# TODO: Check if user already exists before setting password.
{ # Make sure Ingress user for OctoPrint exists. { # Make sure Ingress user for OctoPrint exists.
bashio::log.notice "Ensure Ingress user (homeassistant) exist." bashio::log.notice "Ensure Ingress user (homeassistant) exist."
new_password=$(date +%s | sha256sum | base64 | head -c 32 ; echo) if ! octoprint --basedir /data/config/octoprint user list | grep -q 'homeassistant'; then
new_password=homeassistant new_password=$(date +%s | sha256sum | base64 | head -c 32 ; echo)
octoprint --basedir /data/config/octoprint user add homeassistant --password "$new_password" --group users --group admins # 2> /dev/null octoprint --basedir /data/config/octoprint user add --password "$new_password" --admin homeassistant # 2> /dev/null
fi
} || { # catch } || { # catch
bashio::log.warning "Failed to ensure Ingress user exists, may not be able to launch." bashio::log.warning "Failed to ensure Ingress user exists, may not be able to launch."
} }

View File

@ -4,7 +4,7 @@
# Configures proxy # Configures proxy
# ============================================================================== # ==============================================================================
# Generate proxy configuration # Generate proxy configuration for Ingress
bashio::var.json \ bashio::var.json \
interface "$(bashio::addon.ip_address)" \ interface "$(bashio::addon.ip_address)" \
port "^$(bashio::addon.ingress_port)" \ port "^$(bashio::addon.ingress_port)" \
@ -12,5 +12,5 @@ bashio::var.json \
camera_host "$(bashio::config 'camera_url')" \ camera_host "$(bashio::config 'camera_url')" \
mode "$(bashio::config 'mode')" \ mode "$(bashio::config 'mode')" \
| tempio \ | tempio \
-template /usr/share/tempio/Caddyfile.gtpl \ -template /usr/share/tempio/caddy/Caddyfile.gtpl \
-out /etc/caddy/Caddyfile -out /etc/caddy/Caddyfile

View File

@ -2,7 +2,7 @@
debug debug
log { log {
format console 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 remote_ip 172.30.32.2
} }
uri strip_prefix {{ .ingress_entry }} uri strip_prefix {{ .ingress_entry }}
handle_path /camera/* {
reverse_proxy @ingress {{ .camera_host }} {
}
}
handle { 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 rewrite / /recovery
{{ else if eq .mode "reverse_proxy_test" }} {{ else if eq .mode "reverse_proxy_test" }}
rewrite / /reverse_proxy_test rewrite / /reverse_proxy_test
{{ end }} {{ end }}
reverse_proxy @ingress 127.0.0.1:80 { reverse_proxy @ingress 127.0.0.1:80 {
header_up X-Script-Name {{ .ingress_entry }} header_up X-Script-Name {{ .ingress_entry }}
header_up -Origin trusted_proxies 172.30.32.2
header_up Origin 172.30.32.2 # header_up -Origin
header_up X-Forwarded-For 172.30.32.2 # header_up Origin 172.30.32.2
header_up X-Scheme {scheme} # header_up X-Forwarded-For 172.30.32.2
flush_interval -1 # header_up X-Scheme {scheme}
# flush_interval -1
} }
} }
} }