From 4982f00eb8af52bfc73c1cfde94c09c0673c3b6c Mon Sep 17 00:00:00 2001 From: Fredrik Baberg Date: Mon, 27 Jun 2022 16:51:33 +0200 Subject: [PATCH] Update nginx --- 3dprinter-octoprint/Dockerfile | 3 + 3dprinter-octoprint/config.yaml | 6 +- .../etc/cont-init.d/{proxy.sh => nginx.sh} | 11 ++- .../rootfs/etc/services.d/nginx/finish | 12 ++++ .../rootfs/etc/services.d/nginx/run | 8 +++ .../rootfs/etc/services.d/octoprint/finish | 12 ++-- .../rootfs/etc/services.d/octoprint/run | 2 +- .../rootfs/usr/share/tempio/ingress.conf | 71 ++++++------------- .../rootfs/usr/share/tempio/webui.conf | 23 ++++++ 9 files changed, 88 insertions(+), 60 deletions(-) rename 3dprinter-octoprint/rootfs/etc/cont-init.d/{proxy.sh => nginx.sh} (71%) create mode 100644 3dprinter-octoprint/rootfs/etc/services.d/nginx/finish create mode 100644 3dprinter-octoprint/rootfs/etc/services.d/nginx/run create mode 100644 3dprinter-octoprint/rootfs/usr/share/tempio/webui.conf diff --git a/3dprinter-octoprint/Dockerfile b/3dprinter-octoprint/Dockerfile index 91d1afb..6cbb198 100644 --- a/3dprinter-octoprint/Dockerfile +++ b/3dprinter-octoprint/Dockerfile @@ -22,6 +22,9 @@ RUN apt update && \ && \ apt clean +# Remove nginx default site. +RUN rm /etc/nginx/sites-enabled/default + # Copy root filesystem COPY rootfs / RUN chmod +x /etc/cont-init.d/*.sh diff --git a/3dprinter-octoprint/config.yaml b/3dprinter-octoprint/config.yaml index cf0d9d1..c0a829e 100644 --- a/3dprinter-octoprint/config.yaml +++ b/3dprinter-octoprint/config.yaml @@ -1,5 +1,5 @@ name: "3DPrinter-OctoPrint" -version: "2022.6.020" +version: "2022.6.022" slug: "3dprinter-octoprint" description: "New instance of OctoPrint" url: "https://github.com/fredrikbaberg/home-assistant-addons/tree/main/3dprinter-octoprint" @@ -13,9 +13,7 @@ init: false map: - share:rw options: - message: "Hello world..." schema: - message: "str?" ports: - 5000/tcp: null + 5000/tcp: 5000 ingress: true diff --git a/3dprinter-octoprint/rootfs/etc/cont-init.d/proxy.sh b/3dprinter-octoprint/rootfs/etc/cont-init.d/nginx.sh similarity index 71% rename from 3dprinter-octoprint/rootfs/etc/cont-init.d/proxy.sh rename to 3dprinter-octoprint/rootfs/etc/cont-init.d/nginx.sh index 22d07ea..c72ff47 100644 --- a/3dprinter-octoprint/rootfs/etc/cont-init.d/proxy.sh +++ b/3dprinter-octoprint/rootfs/etc/cont-init.d/nginx.sh @@ -1,15 +1,22 @@ #!/usr/bin/with-contenv bashio # ============================================================================== -# Prepare proxy +# Prepare nginx proxy # s6-overlay docs: https://github.com/just-containers/s6-overlay # ============================================================================== -bashio::log.info "Proxy cont-init.d" +bashio::log.info "nginx cont-init.d" 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 diff --git a/3dprinter-octoprint/rootfs/etc/services.d/nginx/finish b/3dprinter-octoprint/rootfs/etc/services.d/nginx/finish new file mode 100644 index 0000000..b03a9cf --- /dev/null +++ b/3dprinter-octoprint/rootfs/etc/services.d/nginx/finish @@ -0,0 +1,12 @@ +#!/usr/bin/env bashio +# ============================================================================== +# Take down the S6 supervision tree when example fails +# s6-overlay docs: https://github.com/just-containers/s6-overlay +# ============================================================================== + +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" diff --git a/3dprinter-octoprint/rootfs/etc/services.d/nginx/run b/3dprinter-octoprint/rootfs/etc/services.d/nginx/run new file mode 100644 index 0000000..703a2b7 --- /dev/null +++ b/3dprinter-octoprint/rootfs/etc/services.d/nginx/run @@ -0,0 +1,8 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Start nginx proxy +# s6-overlay docs: https://github.com/just-containers/s6-overlay +# ============================================================================== + +bashio::log.info "Starting NGinx..." +exec nginx diff --git a/3dprinter-octoprint/rootfs/etc/services.d/octoprint/finish b/3dprinter-octoprint/rootfs/etc/services.d/octoprint/finish index b03a9cf..9f37aa6 100644 --- a/3dprinter-octoprint/rootfs/etc/services.d/octoprint/finish +++ b/3dprinter-octoprint/rootfs/etc/services.d/octoprint/finish @@ -4,9 +4,11 @@ # s6-overlay docs: https://github.com/just-containers/s6-overlay # ============================================================================== -if [[ "$1" -ne 0 ]] && [[ "$1" -ne 256 ]]; then - bashio::log.warning "Halt add-on" - exec /run/s6/basedir/bin/halt -fi +# 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.info "Service restart after closing" + +bashio::log.notice "Finish up OctoPrint..." \ No newline at end of file diff --git a/3dprinter-octoprint/rootfs/etc/services.d/octoprint/run b/3dprinter-octoprint/rootfs/etc/services.d/octoprint/run index 3add3f7..615d8ef 100644 --- a/3dprinter-octoprint/rootfs/etc/services.d/octoprint/run +++ b/3dprinter-octoprint/rootfs/etc/services.d/octoprint/run @@ -5,4 +5,4 @@ # ============================================================================== ## Run your program -exec octoprint serve --iknowwhatimdoing --host 0.0.0.0 --port 5000 --basedir /data/config/octoprint +exec octoprint serve --iknowwhatimdoing --host 0.0.0.0 --port 80 --basedir /data/config/octoprint diff --git a/3dprinter-octoprint/rootfs/usr/share/tempio/ingress.conf b/3dprinter-octoprint/rootfs/usr/share/tempio/ingress.conf index 6c6ae0a..674740e 100644 --- a/3dprinter-octoprint/rootfs/usr/share/tempio/ingress.conf +++ b/3dprinter-octoprint/rootfs/usr/share/tempio/ingress.conf @@ -1,54 +1,29 @@ -events { - worker_connections 1024; -} +server { + listen 8099; -http { - include mime.types; - default_type application/octet-stream; - sendfile on; - keepalive_timeout 65; + allow 172.30.32.2; + deny all; - map $http_upgrade $connection_upgrade { - default upgrade; - '' close; + 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; } - upstream "octoprint" { - server 127.0.0.1:5000; - } - - upstream "mjpg-streamer" { - server 127.0.0.1:8080; - } - - server { - listen 8099; - server_name localhost; - - location /octoprint/ { - proxy_pass http://octoprint/; # 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; - } - - location /webcam/ { - proxy_pass http://mjpg-streamer/; - } - - # redirect server error pages to the static page /50x.html - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root html; - } + # redirect server error pages to the static page /50x.html + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; } } - - diff --git a/3dprinter-octoprint/rootfs/usr/share/tempio/webui.conf b/3dprinter-octoprint/rootfs/usr/share/tempio/webui.conf new file mode 100644 index 0000000..3d0046f --- /dev/null +++ b/3dprinter-octoprint/rootfs/usr/share/tempio/webui.conf @@ -0,0 +1,23 @@ +server { + listen 5000; + server_name localhost; + + location / { + proxy_pass http://127.0.0.1:5000/; # 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; + } +}