Cleanup octoprint for testing

This commit is contained in:
Fredrik Baberg 2023-01-11 03:53:24 +01:00
parent 774bd3b18d
commit 08aa3cd32a
14 changed files with 111 additions and 82 deletions

View File

@ -1,36 +1,24 @@
{ {
"name": "Example devcontainer for add-on repositories", "name": "Example devcontainer for add-on repositories",
"image": "ghcr.io/home-assistant/devcontainer:addons", "image": "ghcr.io/home-assistant/devcontainer:addons",
"appPort": [ "appPort": ["7123:8123", "7357:4357"],
"7123:8123", "postStartCommand": "bash devcontainer_bootstrap",
"7357:4357" "runArgs": ["-e", "GIT_EDITOR=code --wait", "--privileged"],
], "containerEnv": {
"postStartCommand": "sudo -E bash devcontainer_bootstrap", "WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}"
"runArgs": [ },
"-e", "extensions": ["timonwong.shellcheck", "esbenp.prettier-vscode"],
"GIT_EDITOR=code --wait", "mounts": [ "type=volume,target=/var/lib/docker" ],
"--privileged" "settings": {
], "terminal.integrated.profiles.linux": {
"containerEnv": { "zsh": {
"WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}" "path": "/usr/bin/zsh"
}, }
"extensions": [ },
"timonwong.shellcheck", "terminal.integrated.defaultProfile.linux": "zsh",
"esbenp.prettier-vscode" "editor.formatOnPaste": false,
], "editor.formatOnSave": true,
"mounts": [ "editor.formatOnType": true,
"type=volume,target=/var/lib/docker" "files.trimTrailingWhitespace": true
], }
"settings": {
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"files.trimTrailingWhitespace": true
}
} }

View File

@ -1,15 +1,15 @@
# Addon configuration # 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 ## Mode
By specifying a different mode you can instead access recovery and reverse proy test page. Normally this should not be needed. By specifying a different mode you can instead access recovery and reverse proy test page. Normally this should not be needed.
# Notes etc. # Notes etc.
> image: ghcr.io/fredrikbaberg/addon-3dprinter-octoprint-{arch} > image: ghcr.io/fredrikbaberg/ha-addon-3dprinter-octoprint-{arch}
## Camera URL
**Note: Currently not used.**
Through setting a camera URL you should be able to access the camera stream even when using Ingress.

View File

@ -1,5 +1,5 @@
# 3DPrinter-OctoPrint # 3DPrinter-OctoPrint
**Note: Currently not in a ready-to-use state.**
Provides OctoPrint as an addon to Home Assistant. Provides OctoPrint as an addon to Home Assistant.
Note: Ingress is **NOT** supported.

View File

@ -9,4 +9,4 @@ labels:
org.opencontainers.image.description: "3DPrinter-OctoPrint addon for Home-Assistant." org.opencontainers.image.description: "3DPrinter-OctoPrint addon for Home-Assistant."
org.opencontainers.image.source: "https://github.com/fredrikbaberg/3dprinter-addons" org.opencontainers.image.source: "https://github.com/fredrikbaberg/3dprinter-addons"
args: args:
OCTOPRINT_VERSION: "1.7.3" OCTOPRINT_VERSION: "1.8.6"

View File

@ -1,5 +1,5 @@
name: "3DPrinter-OctoPrint" name: "3DPrinter-OctoPrint"
version: "2022.12.05" version: "2023.01.0"
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"
@ -22,7 +22,7 @@ usb: true
ports: ports:
5000/tcp: null 5000/tcp: null
ports_description: ports_description:
5000/tcp: Web-based interface (Not required for Ingress) 5000/tcp: Web-based interface
options: options:
camera_url: "http://b7aa59c4-camera-mjpg-streamer" camera_url: "http://b7aa59c4-camera-mjpg-streamer"
mode: normal mode: normal
@ -32,4 +32,4 @@ schema:
mode: "list(normal|recovery|reverse_proxy_test|camera)?" mode: "list(normal|recovery|reverse_proxy_test|camera)?"
trusted_proxies: "str?" trusted_proxies: "str?"
tmpfs: true tmpfs: true
image: ghcr.io/fredrikbaberg/addon-3dprinter-octoprint-{arch} # image: ghcr.io/fredrikbaberg/ha-addon-3dprinter-octoprint-{arch}

View File

@ -1,4 +1,3 @@
# Temporary file, will be overwritten on launch.
{ {
debug debug
log { log {
@ -6,3 +5,5 @@
output file /var/log/caddy/caddy.log output file /var/log/caddy/caddy.log
} }
} }
import sites-enabled/*.caddy

View File

@ -3,11 +3,12 @@
# Prepare OctoPrint # Prepare OctoPrint
# s6-overlay docs: https://github.com/just-containers/s6-overlay # s6-overlay docs: https://github.com/just-containers/s6-overlay
# ============================================================================== # ==============================================================================
export BASEDIR="--basedir /data/config/octoprint"
{ # Check if OctoPrint is installed. { # Check if OctoPrint is installed.
octoprint -b /data/config/octoprint --version octoprint $BASEDIR --version
} || { # Otherwise install it. } || { # Otherwise install it.
{ # Check if Python is available (at `/data/python/octoprint` according to PATH) { # Check if Python is available (at `/data/python/octoprint`, according to PATH)
python --version python --version
} || { # Otherwise create Python virtual environment. } || { # Otherwise create Python virtual environment.
python3 -m venv /data/python/octoprint python3 -m venv /data/python/octoprint
@ -17,23 +18,39 @@
pip install octoprint==$OCTOPRINT_VERSION pip install octoprint==$OCTOPRINT_VERSION
} }
# Copy OctoPrint config to persistent storage, if missing.
if [ ! -f /data/config/octoprint/config.yaml ]; then
if [ -f /root/config/octoprint/config.yaml ]; then
mkdir -p /data/config/octoprint
cp /root/config/octoprint/config.yaml /data/config/octoprint/config.yaml
bashio::log.notice "Default OctoPrint config copied"
else
bashio::log.warning "Default OctoPrint config not found"
fi
fi
# { # Make sure Ingress user for OctoPrint exists. # Update OctoPrint config with settings used for the addon overall (could always be changed)
# bashio::log.notice "Ensure Ingress user (homeassistant) exist." function updateConfigRequired() {
# if ! octoprint --basedir /data/config/octoprint user list | grep -q 'homeassistant'; then octoprint $BASEDIR config set --bool api.allowCrossOrigin true
# new_password=$(date +%s | sha256sum | base64 | head -c 32 ; echo) octoprint $BASEDIR config set folder.generated "/tmp/octoprint/generated"
# octoprint --basedir /data/config/octoprint user add --password "$new_password" --admin homeassistant # 2> /dev/null octoprint $BASEDIR config set folder.timelapse_tmp "/tmp/octoprint/timelapse/tmp"
# fi octoprint $BASEDIR config set --bool server.allowFraming true
# } || { # catch octoprint $BASEDIR config set server.commands.serverRestartCommand "/scripts/octoprint_restart.sh"
# bashio::log.warning "Failed to ensure Ingress user exists, may not be able to launch." 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 server.host "127.0.0.1"
octoprint $BASEDIR config set --int server.port 80
octoprint $BASEDIR config set webcam.ffmpeg "/usr/bin/ffmpeg"
}
# Update OctoPrint config with customized settings, not strictly required for addon to work but helps with features.
function 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.
}
# Create initial OctoPrint config, if missing.
if [ ! -f /data/config/octoprint/config.yaml ]; then
mkdir -p /data/config/octoprint
updateConfigRequired
fi

View File

@ -1,10 +1,23 @@
#!/usr/bin/with-contenv bashio # #!/usr/bin/with-contenv bashio
# ============================================================================== # # ==============================================================================
# Add-on: 3dprinter-octoprint # # Add-on: 3dprinter-octoprint
# Configures proxy # # Configures proxy
# ============================================================================== # # ==============================================================================
# Generate proxy configuration for Ingress # Generate proxy configuration for any access
bashio::var.json \
| tempio \
-template /usr/share/tempio/caddy/Caddyfile.any.gtpl \
-out /etc/caddy/sites-enabled/any.caddy
# Generate proxy configuration for internal access
bashio::var.json \
internal_hostname "$(bashio::info.hostname)" \
| tempio \
-template /usr/share/tempio/caddy/Caddyfile.internal.gtpl \
-out /etc/caddy/sites-enabled/internal.caddy
# Generate proxy configuration for Ingress access
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)" \
@ -13,8 +26,8 @@ bashio::var.json \
mode "$(bashio::config 'mode')" \ mode "$(bashio::config 'mode')" \
trusted_proxies "$(bashio::config 'trusted_proxies')" \ trusted_proxies "$(bashio::config 'trusted_proxies')" \
| tempio \ | tempio \
-template /usr/share/tempio/caddy/Caddyfile.gtpl \ -template /usr/share/tempio/caddy/Caddyfile.ingress.gtpl \
-out /etc/caddy/Caddyfile -out /etc/caddy/sites-enabled/ingress.caddy
# Make sure file is correctly formatted. # # Make sure file is correctly formatted.
caddy fmt --overwrite /etc/caddy/Caddyfile # caddy fmt --overwrite /etc/caddy/Caddyfile

View File

@ -7,4 +7,4 @@
bashio::log.info "Starting OctoPrint..." bashio::log.info "Starting OctoPrint..."
## Run your program ## Run your program
exec octoprint serve --iknowwhatimdoing --host 127.0.0.1 --port 80 --basedir /data/config/octoprint exec octoprint --basedir /data/config/octoprint serve --iknowwhatimdoing --host 127.0.0.1 --port 80

View File

@ -4,7 +4,7 @@
# Runs the reverse proxy. # Runs the reverse proxy.
# ============================================================================== # ==============================================================================
# Wait for web server to be available # Wait for OctoPrint WebUI to be available
bashio::net.wait_for 80 bashio::net.wait_for 80
bashio::log.info "Starting proxy..." bashio::log.info "Starting proxy..."

View File

@ -0,0 +1,5 @@
# OctoPrint WebUI through external access
:5000 {
reverse_proxy http://127.0.0.1:80 {
}
}

View File

@ -0,0 +1,5 @@
# WebUI through internal hostname
{{ .internal_hostname }}:5000 {
reverse_proxy http://127.0.0.1:80 {
}
}