Skip to content

Commit

Permalink
[octoprint-proxy] Migrate to nginx and editable config (#228)
Browse files Browse the repository at this point in the history
* [octoprint-proxy] Migrate to nginx and editable config

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
MaxWinterstein and pre-commit-ci[bot] authored Jan 1, 2024
1 parent fe85d40 commit cc7bbbf
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 51 deletions.
4 changes: 4 additions & 0 deletions octoprint-proxy/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.0.3] - 2024-01-01

- Changed to nginx, config can now be edited from `addon_configs`

## [1.0.2] - 2022-12-16

- Change to prebuild images
Expand Down
16 changes: 10 additions & 6 deletions octoprint-proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
ARG BUILD_FROM
ARG BUILD_FROM=ghcr.io/hassio-addons/base:13.0.0
FROM $BUILD_FROM

ENV LANG C.UTF-8
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME=30000
ENV S6_KEEP_ENV=1

RUN apk add haproxy
RUN apk add nginx inotify-tools

COPY run.sh haproxy.cfg /
RUN rm /etc/nginx/http.d/default.conf

RUN chmod a+x /run.sh
CMD [ "/run.sh" ]
COPY root /

RUN ln -s /octoprint /config

# RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log
23 changes: 8 additions & 15 deletions octoprint-proxy/config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
name: OctoPrint Proxy
version: 1.0.2
name: OctoPrint Proxy (NOT WORKING)
version: 1.0.3
slug: octoprint_proxy
description: Access OctoPrint from within Home Assistant
url: https://github.com/MaxWinterstein/homeassistant-addons/
image: ghcr.io/maxwinterstein/homeassistant-addon-octoprint-proxy-{arch}
ingress: true
ingress_port: 80
ingress_port: 8055
ingress_entry: login
panel_title: OctoPrint
panel_icon: mdi:printer-3d-nozzle
arch:
- armv7
- aarch64
- amd64
init: false
options:
octoprint_host: octopi
octoprint_port: "443"
ssl:
enabled: true
verify: false
schema:
octoprint_host: str
octoprint_port: port
ssl:
enabled: bool
verify: bool
map:
- addon_config:rw
ports:
8055/tcp: 8055
5 changes: 5 additions & 0 deletions octoprint-proxy/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
###########

sh -c "nginxReloader.sh &"
exec "$@"
16 changes: 16 additions & 0 deletions octoprint-proxy/nginxReloader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
###########

while true
do
inotifywait --exclude .swp -e create -e modify -e delete -e move /etc/nginx/conf.d
nginx -t
if [ $? -eq 0 ]
then
echo "Detected Nginx Configuration Change"
echo "new config:"
nginx -T
echo "Executing: nginx -s reload"
nginx -s reload
fi
done
22 changes: 22 additions & 0 deletions octoprint-proxy/root/etc/s6-overlay/s6-rc.d/nginx-reloader/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/with-contenv bashio

bashio::log.blue "Starting reloader..."

set -x
# set +e

while true
do
MYWAIT=$(inotifywait -e modify /config/nginx.conf)
bashio::log.blue "$(date '+%Y-%m-%d %H:%M:%S') $MYWAIT"
nginx -t
if [ $? -eq 0 ]
then
bashio::log.blue "Detected Nginx Configuration Change"
bashio::log.blue "Executing: nginx -s reload"
nginx -s reload
else
bashio::log.blue "wtf?"

fi
done
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
23 changes: 23 additions & 0 deletions octoprint-proxy/root/etc/s6-overlay/s6-rc.d/nginx/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/with-contenv bashio

bashio::log.green 'starting nginx'

test -f /config/nginx.conf || cat <<EOF > /config/nginx.conf
server {
listen 8080;

server_name your_domain www.your_domain;

location / {
proxy_pass app_server_address;
include proxy_params;
}
}
EOF

test -f /etc/nginx/http.d/proxy.conf || ln -s /config/nginx.conf /etc/nginx/http.d/proxy.conf

nginx -t
nginx
echo sleep
sleep 999
1 change: 1 addition & 0 deletions octoprint-proxy/root/etc/s6-overlay/s6-rc.d/nginx/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
30 changes: 0 additions & 30 deletions octoprint-proxy/run.sh

This file was deleted.

0 comments on commit cc7bbbf

Please sign in to comment.