Merge pull request #10 from fredrikbaberg/dev

Documentation and implementation update
This commit is contained in:
Fredrik Baberg 2022-07-11 13:00:53 +02:00 committed by GitHub
commit bb4f67ecba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 296 additions and 213 deletions

View File

@ -18,15 +18,8 @@ RUN apt update && \
build-essential \
nginx \
&& \
apt install -y \
vim \
&& \
apt clean
# Setup for nginx.
RUN rm /etc/nginx/sites-enabled/default
RUN chown -R root:root /var/log/nginx
# Copy root filesystem
COPY rootfs /
RUN chmod +x /etc/cont-init.d/*.sh

View File

@ -0,0 +1,3 @@
# 3DPrinter-OctoPrint
Provides OctoPrint as an addon to Home Assistant.

View File

@ -1,82 +0,0 @@
#include <tunables/global>
profile 3dprinter-octoprint flags=(attach_disconnected,mediate_deleted) {
#include <abstractions/base>
# Capabilities
file,
signal (send) set=(kill,term,int,hup,cont),
# S6-Overlay
/init ix,
/bin/** ix,
/usr/bin/** ix,
/run/{s6,s6-rc*,service}/** ix,
/package/** ix,
/command/** ix,
/etc/services.d/** rwix,
/etc/cont-init.d/** rwix,
/etc/cont-finish.d/** rwix,
/run/{,**} rwk,
/dev/tty rw,
# Bashio
/usr/lib/bashio/** ix,
/tmp/** rwk,
# Access to options.json and other files within your addon
/data/** rw,
# Start new profile for service
# /usr/bin/my_program cx -> my_program,
# profile my_program flags=(attach_disconnected,mediate_deleted) {
# #include <abstractions/base>
#
# # Receive signals from S6-Overlay
# signal (receive) peer=*_example,
#
# # Access to options.json and other files within your addon
# /data/** rw,
#
# # Access to mapped volumes specified in config.json
# /share/** rw,
#
# # Access required for service functionality
# # Note: List was built by doing the following:
# # 1. Add what is obviously needed based on what is in the script
# # 2. Add `complain` as a flag to this profile temporarily and run the addon
# # 3. Review the audit log with `journalctl _TRANSPORT="audit" -g 'apparmor="ALLOWED"'` and add other access as needed
# # Remember to remove the `complain` flag when you are done
# # /usr/bin/my_program r,
# /bin/bash rix,
# /bin/echo ix,
# /etc/passwd r,
# /dev/tty rw,
# }
# Start new profile for service
/usr/sbin/nginx cx -> nginx,
profile nginx flags=(attach_disconnected,mediate_deleted) {
#include <abstractions/base>
# Receive signals from S6-Overlay
signal (receive) peer=*_example,
# Allow capability CAP_CHOWN
capability chown,
/usr/sbin/nginx r,
/bin/bash rix,
/bin/echo ix,
/etc/passwd r,
/dev/tty rw,
/etc/nginx/* rw,
/var/log/nginx/access.log rw,
/var/log/nginx/error.log rw,
}
}

View File

@ -1,19 +1,31 @@
name: "3DPrinter-OctoPrint"
version: "2022.6.028"
version: "2022.7.001"
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: true
ingress_stream: true
panel_icon: mdi:printer-3d
panel_title: 3DPrinter-OctoPrint
arch:
- aarch64
- amd64
- armhf
- armv7
- i386
- armv7
- amd64
- armhf
- aarch64
- i386
stage: experimental
init: false
map:
- share:rw
realtime: true
gpio: true
uart: true
usb: true
ports:
5000/tcp: 5000
ingress: true
5000/tcp: null
ports_description:
5000/tcp: Web-based interface (Not required for Ingress)
options:
recovery: false
schema:
recovery: "bool"
image: ghcr.io/fredrikbaberg/addon-3dprinter-octoprint-{arch}
tmpfs: true

View File

@ -1,20 +1,22 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Prepare nginx proxy
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# Add-on: 3dprinter-octoprint
# Configures NGINX
# ==============================================================================
bashio::log.info "nginx cont-init.d"
# Generate Ingress configuration
bashio::var.json \
interface "$(bashio::addon.ip_address)" \
port "^$(bashio::addon.ingress_port)" \
| tempio \
-template /etc/nginx/templates/ingress.gtpl \
-out /etc/nginx/servers/ingress.conf
ingress_entry=$(bashio::addon.ingress_entry)
export ingress_entry=${ingress_entry}
tempio \
-conf /data/options.json \
-template /usr/share/tempio/ingress.conf \
-out /etc/nginx/sites-enabled/ingress.conf
tempio \
-conf /data/options.json \
-template /usr/share/tempio/webui.conf \
-out /etc/nginx/sites-enabled/webui.conf
# Generate direct access configuration, if enabled.
if bashio::var.has_value "$(bashio::addon.port 5000)"; then
bashio::var.json \
port "^$(bashio::addon.port 5000)" \
| tempio \
-template /etc/nginx/templates/direct.gtpl \
-out /etc/nginx/servers/direct.conf
fi

View File

@ -7,10 +7,29 @@
{ # Check if OctoPrint is installed
octoprint --version
} || { # Otherwise install
{ # Check if Python is available
{ # Check if Python is available at `/data/python/octoprint` according to PATH)
python --version
} || { # Otherwise install
} || { # Otherwise create Python virtual environment.
python3 -m venv /data/python/octoprint
}
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.
bashio::log.notice "Ensure Ingress user (homeassistant) exist."
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
} || { # catch
bashio::log.warning "Failed to ensure Ingress user exists, may not be able to launch."
}

View File

@ -0,0 +1,96 @@
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
font/woff woff;
font/woff2 woff2;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;
video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}

View File

@ -0,0 +1,15 @@
proxy_http_version 1.1;
proxy_ignore_client_abort off;
proxy_read_timeout 86400s;
proxy_redirect off;
proxy_send_timeout 86400s;
proxy_max_temp_file_size 0;
proxy_set_header Accept-Encoding "";
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Real-IP $remote_addr;

View File

@ -0,0 +1,6 @@
root /dev/null;
server_name $hostname;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;

View File

@ -0,0 +1,8 @@
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;

View File

@ -0,0 +1,3 @@
upstream backend {
server 127.0.0.1:5000;
}

View File

@ -1,22 +1,44 @@
user root root;
# Run nginx in foreground.
daemon off;
worker_processes 1;
# This is run inside Docker.
user root;
# Pid storage location.
pid /var/run/nginx.pid;
# Set number of worker processes.
worker_processes 1;
# Enables the use of JIT for regular expressions to speed-up their processing.
pcre_jit on;
# Write error log to the add-on log.
error_log /proc/1/fd/1 error;
# Max num of simultaneous connections by a worker process.
events {
worker_connections 1024;
worker_connections 512;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/includes/mime.types;
access_log off;
client_max_body_size 4G;
default_type application/octet-stream;
gzip on;
keepalive_timeout 65;
sendfile on;
server_tokens off;
tcp_nodelay on;
tcp_nopush on;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
'' close;
}
include /etc/nginx/sites-enabled/*;
include /etc/nginx/includes/upstream.conf;
include /etc/nginx/servers/*.conf;
}

View File

@ -0,0 +1,10 @@
server {
listen {{ .port }} default_server;
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;
location / {
proxy_pass http://backend;
}
}

View File

@ -0,0 +1,13 @@
server {
listen {{ .interface }}:{{ .port }} default_server;
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;
location / {
allow 172.30.32.2;
deny all;
proxy_pass http://backend;
}
}

View File

@ -1,12 +1,9 @@
#!/usr/bin/env bashio
#!/usr/bin/execlineb -S0
# ==============================================================================
# Take down the S6 supervision tree when proxy fails
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# Add-on: 3dprinter-octoprint
# Take down the S6 supervision tree when Nginx fails
# ==============================================================================
if -n { s6-test $# -ne 0 }
if -n { s6-test ${1} -eq 256 }
if [[ "$1" -ne 0 ]] && [[ "$1" -ne 256 ]]; then
bashio::log.warning "Halt add-on"
exec /run/s6/basedir/bin/halt
fi
bashio::log.info "Service restart after closing"
s6-svscanctl -t /var/run/s6/services

View File

@ -1,8 +1,11 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Start nginx proxy
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# Add-on: 3dprinter-octoprint
# Runs the Nginx daemon
# ==============================================================================
# Wait for web server to be available
bashio::net.wait_for 5000
bashio::log.info "Starting NGinx..."
exec nginx -g 'daemon off;'
exec nginx

View File

@ -1,14 +1,9 @@
#!/usr/bin/env bashio
#!/usr/bin/execlineb -S0
# ==============================================================================
# Take down the S6 supervision tree when octoprint fails
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# Add-on: mjpg-streamer
# Take down the S6 supervision tree when mjpg-streamer fails
# ==============================================================================
if -n { s6-test $# -ne 0 }
if -n { s6-test ${1} -eq 256 }
# if [[ "$1" -ne 0 ]] && [[ "$1" -ne 256 ]]; then
# bashio::log.warning "Halt add-on"
# exec /run/s6/basedir/bin/halt
# fi
# bashio::log.info "Service restart after closing"
bashio::log.notice "Finish up OctoPrint..."
s6-svscanctl -t /var/run/s6/services

View File

@ -1,8 +1,8 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Start OctoPrint
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# Add-on: 3dprinter-octoprint
# Runs OctoPrint
# ==============================================================================
## Run your program
exec octoprint serve --iknowwhatimdoing --host 0.0.0.0 --port 80 --basedir /data/config/octoprint
exec octoprint serve --iknowwhatimdoing --host 0.0.0.0 --port 5000 --basedir /data/config/octoprint

View File

@ -0,0 +1,13 @@
accessControl:
autologinAs: homeassistant
autologinLocal: true
localNetworks:
- 172.30.32.2
folder:
generated: /tmp/octoprint/generated
timelapse_tmp: /tmp/octoprint/timelapse/tmp
server:
commands:
serverRestartCommand: /scripts/octoprint_restart.sh
systemRestartCommand: /scripts/system_restart.sh
systemShutdownCommand: /scripts/system_shutdown.sh

View File

@ -1,29 +0,0 @@
server {
listen 8099;
allow 172.30.32.2;
deny all;
server_name _;
access_log /dev/stdout combined;
location {{ env "ingress_entry" }}/ {
proxy_pass http://127.0.0.1:80/; # make sure to add trailing slash here!
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Script-Name {{ env "ingress_entry" }};
proxy_http_version 1.1;
client_max_body_size 0;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

View File

@ -1,23 +0,0 @@
server {
listen 5000;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:80/; # make sure to add trailing slash here!
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_http_version 1.1;
client_max_body_size 0;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

View File

@ -1,6 +0,0 @@
configuration:
message:
name: Message
description: The message that will be printed to the log when starting this example add-on.
network:
5000/TCP: OctoPrint port (not used for Ingress)

View File

@ -7,11 +7,22 @@
## How to use
Set input arguments through `mjpg_input` configuration option, start the add-on.
The camera stream and snapshot can be accessed by e.g. [MJPEG IP Camera](https://www.home-assistant.io/integrations/mjpeg/) from url `http://<addon-hostname>/?action=stream` or `http://<addon-hostname>/?action=snapshot`.
## Accessing camera from Home Assistant
The camera stream and snapshot can be accessed by e.g. [MJPEG IP Camera](https://www.home-assistant.io/integrations/mjpeg/), with URLs:
* MJPEG URL: `http://<addon-hostname>/?action=stream`
* Still image URL: `http://<addon-hostname>/?action=snapshot`.
Addon hostname can be found under [addon settings](https://my.home-assistant.io/redirect/supervisor_addon/?addon=b7aa59c4_camera-mjpg-streamer&repository_url=https%3A%2F%2Fgithub.com%2Ffredrikbaberg%2F3dprinter-addons).
## Tests
For testing you can set `mjpg_input` to:
> input_file.so -f /www_mjpg -e
This will result in showing a test image.
## Versions
Some notes regarding the software and versions.

View File

@ -1,3 +1,5 @@
# mjpg-streamer
Provides camera stream through `mjpg-streamer`, to be used by e.g. OctoPrint addon.
Instructions are provided in the tab "Docs".

View File

@ -8,4 +8,4 @@
bashio::net.wait_for 80
bashio::log.info "Starting NGinx..."
exec nginx
exec nginx

View File

@ -1,5 +1,5 @@
# Camera-RTC
**Note: This addon is not ready for use.**
**Note: This addon is broken and not ready for use.**
Camera addon with support for WebRTC.