Cleanup commit

This commit is contained in:
Fredrik Baberg
2023-01-11 18:43:38 +01:00
commit 7cef46e0d4
69 changed files with 1313 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
## 2023.01.0
* Update to OctoPrint 1.8.6.
* Disabled Ingress.
* Based on Debian instead of Alpine, should make more plugins compatible.
* Default config now set by CLI instead of copying pre-set file.
* Using Caddy as reverse proxy.
* Added option to set trusted_proxies, should help with reverse proxy configuration.

View File

@@ -0,0 +1,25 @@
# Addon configuration
## Trusted proxies
By setting trusted proxies you should be able to use HTTPS *if you have placed a reverse proxy in front of Home Assistant*. For more information, see [Caddy documentation](https://caddyserver.com/docs/caddyfile/directives/reverse_proxy).
# Camera
There is no camera server in the addon, it has to be setup separately.
You could, for instance, use the addon [camera-mjpg-streamer](https://github.com/fredrikbaberg/3dprinter-addons/tree/main/camera-mjpg-streamer) available in the same repository. If so, you can set the snapshot URL to:
> `http://b7aa59c4-camera-mjpg-streamer/?action=snapshot`.
Note that this method **only allows for snapshot**, it does **NOT** work for camera stream as this requires the browser/app used to directly access the stream.
# Ingress?
This addon drops support for Ingress. The main reason for this is issues with finding a working configuration.
* An update to OctoPrint increased the security (which is good!). Unfortunately it also broke the configuration used in this addon, most likely due to this addon not behaving properly.
* There has been issues with accessing camera stream by Ingress since I added support for it, which I have not been able to solve.
I have tried to find a solution to this, without success. Therefore I decided to disable the option, as it just leads to frustration.
If someone is able to find a working configuration, please let me know.

View File

@@ -0,0 +1,46 @@
ARG BUILD_FROM="ghcr.io/home-assistant/amd64-base-debian:bullseye"
FROM ${BUILD_FROM}
ARG OCTOPRINT_VERSION="1.8.6"
# 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 \
&& apt install -y \
--no-install-recommends \
debian-keyring \
debian-archive-keyring \
apt-transport-https \
gpg \
&& curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg \
&& curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
# Install dependencies
RUN apt update \
&& apt install -y \
--no-install-recommends \
python3-venv \
python3-dev \
python3-wheel \
build-essential \
caddy \
# Extras.
ffmpeg \
# avrdude \
# dfu-util \
# dfu-programmer \
# stm32flash \
# Development/testing
vim \
&& \
apt clean
# Copy root filesystem
COPY rootfs /
RUN chmod +x /etc/cont-init.d/*.sh
RUN chmod +x /etc/services.d/*/*
RUN chmod +x /scripts/*.sh

View File

@@ -0,0 +1,6 @@
# 3DPrinter-OctoPrint
Provides OctoPrint as an addon to Home Assistant.
Note: Ingress is **NOT** supported.

View File

@@ -0,0 +1,12 @@
build_from:
aarch64: ghcr.io/home-assistant/aarch64-base-debian:bullseye
amd64: ghcr.io/home-assistant/amd64-base-debian:bullseye
armhf: ghcr.io/home-assistant/armhf-base-debian:bullseye
armv7: ghcr.io/home-assistant/armv7-base-debian:bullseye
i386: ghcr.io/home-assistant/i386-base-debian:bullseye
labels:
org.opencontainers.image.title: "Home Assistant Add-on: 3DPrinter-OctoPrint"
org.opencontainers.image.description: "3DPrinter-OctoPrint addon for Home-Assistant."
org.opencontainers.image.source: "https://github.com/fredrikbaberg/3dprinter-addons"
args:
OCTOPRINT_VERSION: "1.8.6"

View File

@@ -0,0 +1,35 @@
name: "3DPrinter-OctoPrint"
version: "2023.01.0"
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"
ingress: false
ingress_stream: false
panel_icon: mdi:printer-3d
panel_title: 3DPrinter-OctoPrint
arch:
- armv7
- amd64
- armhf
- aarch64
- i386
stage: experimental
init: false
realtime: true
gpio: true
uart: true
usb: true
ports:
5000/tcp: null
ports_description:
5000/tcp: Web-based interface
options:
trusted_proxies: ""
# camera_url: "http://b7aa59c4-camera-mjpg-streamer"
# mode: normal
schema:
trusted_proxies: "str?"
# camera_url: "url?"
# mode: "list(normal|recovery|reverse_proxy_test|camera)?"
tmpfs: true
image: ghcr.io/fredrikbaberg/ha-addon-3dprinter-octoprint-{arch}

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

View File

@@ -0,0 +1,10 @@
{
# debug
log {
format console
output file /var/log/caddy/caddy.log
}
auto_https disable_redirects
}
import sites-enabled/*.caddy

View File

@@ -0,0 +1,2 @@
XDG_CONFIG_HOME="/data/config"
XDG_DATA_HOME="/data/config"

View File

@@ -0,0 +1,54 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Prepare OctoPrint
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# ==============================================================================
export BASEDIR="--basedir /data/config/octoprint"
{ # Check if OctoPrint is installed.
octoprint $BASEDIR --version
} || { # Otherwise install it.
{ # Check if Python is available (at `/data/python/octoprint`, set by PATH in Dockerfile)
python --version
} || { # Otherwise create Python virtual environment.
python3 -m venv /data/python/octoprint
# Install wheel to speed up future installs.
pip install wheel
}
pip install octoprint==$OCTOPRINT_VERSION
}
# Create initial OctoPrint config, if missing.
if [ ! -f /data/config/octoprint/config.yaml ]; then
mkdir -p /data/config/octoprint
fi
# Update OctoPrint config with settings for the addon to behave properly.
updateConfig()
{
# octoprint $BASEDIR config set --bool api.allowCrossOrigin true
octoprint $BASEDIR config set folder.generated "/tmp/octoprint/generated"
octoprint $BASEDIR config set folder.timelapse_tmp "/tmp/octoprint/timelapse/tmp"
# octoprint $BASEDIR config set --bool server.allowFraming true
octoprint $BASEDIR config set server.commands.serverRestartCommand "/scripts/octoprint_restart.sh"
octoprint $BASEDIR config set server.commands.systemRestartCommand "/scripts/system_restart.sh"
octoprint $BASEDIR config set server.commands.systemShutdownCommand "/scripts/system_shutdown.sh"
octoprint $BASEDIR config set webcam.ffmpeg "/usr/bin/ffmpeg"
}
updateConfig
# Other setting changes, if needed. E.g. creating a user.
# Update OctoPrint config with customized settings, not strictly required for addon to work but helps with features.
# updateConfigCustom() {
# Add user, if needed.
# { # Make sure Ingress user for OctoPrint exists.
# bashio::log.notice "Ensure Ingress user (homeassistant) exist."
# 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."
# }
# Trusted networks, access control etc.
# }

View File

@@ -0,0 +1,33 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Add-on: 3dprinter-octoprint
# Configures proxy
# ==============================================================================
# Generate proxy configuration for internal and external access
bashio::var.json \
addon_hostname "$(bashio::addon.hostname)" \
addon_ip "$(bashio::addon.ip_address)" \
trusted_proxies "$(bashio::config 'trusted_proxies')" \
| tempio \
-template /usr/share/tempio/caddy/Caddyfile.internal_external.gtpl \
-out /etc/caddy/sites-enabled/internal_external.caddy
# Generate proxy configuration for access by Ingress
# bashio::var.json \
# addon_hostname "$(bashio::addon.hostname)" \
# addon_ip "$(bashio::addon.ip_address)" \
# camera_host "$(bashio::config 'camera_url')" \
# ingress_entry "$(bashio::addon.ingress_entry)" \
# ingress_port "^$(bashio::addon.ingress_port)" \
# interface "$(bashio::addon.ip_address)" \
# mode "$(bashio::config 'mode')" \
# supervisor_ip "$(bashio::supervisor.ip_address)" \
# trusted_proxies "$(bashio::config 'trusted_proxies')" \
# | tempio \
# -template /usr/share/tempio/caddy/Caddyfile.ingress.gtpl \
# -out /etc/caddy/sites-enabled/ingress.caddy
# Make sure config is correctly formatted.
caddy fmt --overwrite /etc/caddy/Caddyfile

View File

@@ -0,0 +1,10 @@
#!/usr/bin/execlineb -S0
# ==============================================================================
# Add-on: 3dprinter-octoprint
# Take down the S6 supervision tree when OctoPrint fails
# ==============================================================================
# if -n { s6-test $# -ne 0 }
# if -n { s6-test ${1} -eq 256 }
# s6-svscanctl -t /var/run/s6/services

View File

@@ -0,0 +1,10 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Add-on: 3dprinter-octoprint
# Runs OctoPrint
# ==============================================================================
bashio::log.info "Starting OctoPrint..."
## Run your program
exec octoprint --basedir /data/config/octoprint serve --iknowwhatimdoing --host 127.0.0.1 --port 80

View File

@@ -0,0 +1,5 @@
#!/usr/bin/execlineb -S0
# ==============================================================================
# Add-on: 3dprinter-octoprint
# Stop reverse proxy
# ==============================================================================

View File

@@ -0,0 +1,12 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Add-on: 3dprinter-octoprint
# Runs the reverse proxy.
# ==============================================================================
# Wait for OctoPrint WebUI to be available
bashio::net.wait_for 80
bashio::log.info "Starting proxy..."
exec caddy run --config /etc/caddy/Caddyfile --envfile /etc/caddy/env

View File

@@ -0,0 +1,5 @@
#!/usr/bin/with-contenv bashio
bashio::log.warning "Restart OctoPrint."
s6-svc -r /var/run/s6/legacy-services/octoprint

View File

@@ -0,0 +1,5 @@
#!/usr/bin/with-contenv bashio
bashio::log.warning "Restart proxy."
s6-svc -r /var/run/s6/legacy-services/proxy

View File

@@ -0,0 +1,48 @@
# #!/usr/bin/bash
# # Set/update parts of OctoPrint config to work with addon.
# export OCTOPRINT_HOME=/data/config/octoprint
# # Access control
# octoprint -b $OCTOPRINT_HOME config set --json accessControl '
# {
# "localNetworks": [
# "127.0.0.0/8",
# "::1/128",
# "172.30.32.2"
# ]
# }
# '
# # API config
# octoprint -b $OCTOPRINT_HOME config set --json api '
# {
# "allowCrossOrigin": true
# }
# '
# # Folder config
# octoprint -b $OCTOPRINT_HOME config set --json folder '
# {
# "generated": "/tmp/octoprint/generated",
# "timelapse_tmp": "/tmp/octoprint/timelapse/tmp"
# }
# '
# # Server config
# octoprint -b $OCTOPRINT_HOME config set --json server '
# {
# "allowFraming": true,
# "commands": {
# "serverRestartCommand": "/scripts/octoprint_restart.sh",
# "systemRestartCommand": "/scripts/system_restart.sh",
# "systemShutdownCommand": "/scripts/system_shutdown.sh"
# }
# }
# '
# # Webcam config
# octoprint -b $OCTOPRINT_HOME config set --json webcam '
# {
# "ffmpeg": "/usr/bin/ffmpeg"
# }
# '

View File

@@ -0,0 +1,5 @@
#!/usr/bin/with-contenv bashio
bashio::log.warning "Restart addon."
bashio::addon.restart

View File

@@ -0,0 +1,5 @@
#!/usr/bin/with-contenv bashio
bashio::log.warning "Shutdown addon."
bashio::addon.stop

View File

@@ -0,0 +1,46 @@
:{{ .ingress_port }} {
bind {{ .addon_ip }}
@ingress {
remote_ip {{ .supervisor_ip }}
}
uri strip_prefix {{ .ingress_entry }}
handle {
reverse_proxy @ingress 127.0.0.1:80/ {
# header_up X-Script-Name {{ .ingress_entry }}
# trusted_proxies {{ .supervisor_ip }}
}
}
}
# :8099 {
# @ingress {
# remote_ip {{ .supervisor_ip }}
# }
# uri strip_prefix {{ .ingress_entry }}
#
# handle_path /camera/* {
# reverse_proxy @ingress {{ .camera_host }} {
# }
# }
# handle {
# {{ 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 }}
# 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
# }
# }
# }
#

View File

@@ -0,0 +1,8 @@
# Internal and external access. Used for:
# * Home-Assistant OctoPrint integration.
# * Accessing OctoPrint WebUI through external port.
:5000 {
reverse_proxy http://127.0.0.1:80 {
trusted_proxies {{ .trusted_proxies }}
}
}