diff --git a/.env-distr b/.env-distr index 6272db8..2039d26 100644 --- a/.env-distr +++ b/.env-distr @@ -20,3 +20,7 @@ WEBCAM_INPUT=input_raspicam.so -fps 5 # USB Webcam in 16:9 example # WEBCAM_INPUT=input_uvc.so -d /dev/video0 -r 640x360 -fps 5 + +# Listen to the following ports: +# HTTP_PORT=80 +# HTTPS_PORT=443 diff --git a/.env-extra-distr b/.env-extra-distr new file mode 100644 index 0000000..1c53a58 --- /dev/null +++ b/.env-extra-distr @@ -0,0 +1,23 @@ +# Sample file for driving an extra printer +# +# Copy this file to .env- -- e.g. .env.extra +# To start an additional instance run: +# docker-compose --project-name extra --env-file .env-extra up -d +# or use the convenience script: +# docker-compose-multi.sh extra up -d + +# Architecture -- same as in your main .env file +OP_MACHINE_NAME=raspberrypi3 + +# Webcam configuration +# Ensure you use only one Raspberry Pi Camera for all instances. +# Supported configurations: +# - One Raspberry Pi Camera, One USB Camera +# - Two USB cameras +# If you do not have a camera, set "WEBCAM_START=false" +WEBCAM_START=false +WEBCAM_INPUT=input_uvc.so -d /dev/video0 -r 640x480 -fps 5 + +# Listen to the following ports -- Must be different for every instances! +HTTP_PORT=8080 +HTTPS_PORT=8443 diff --git a/README.md b/README.md index a641ec4..aae4b9b 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ - [Updates](#updates) - [First run](#first-run) - [Note about persistence](#note-about-persistence) +- [Multiple printers](#multiple-printers) # Introduction @@ -234,3 +235,64 @@ docker-compose up -d ``` By doing this, you will loose any change made to the code, in particular if you installed plugins you will have to re-install them (but their configuration will be preserved). + +# Multiple printers + +Although driving multiple printers from the same Raspberry Pi is possible, it might lead to performance issues. +This setup is nevertheless easy to achieve with the _plain Docker_ setup. +It is a good solution if: + +- You have a powerful Raspberry Pi +- You have multiple printers but use only one at a time + +You can run any number of instances of this _container stack_ by using a different _project name_ and a different `.env` file. +The `docker-compose-multi.sh` convenience script is provided to simplify operations. + +Assuming you already have a running instance, to add a new one simply copy the `.env-extra-distr` sample file to `.env-`, +review the configuration parameters and start the instance with `./docker-compose-multi.sh up -d`. + +Main points of attention: + +- Do not configure more than one Raspberry Pi camera! + (There is no limitation on the number of USB cameras) +- Ensure all instances have their own unique HTTP and HTTPS ports. + +Sample session: + +```shell +# Start the main instance +$ docker-compose up -d +Creating network "octoprint_default" with the default driver +Creating octoprint_octoprint_1 ... done +Creating octoprint_webcam_1 ... done +Creating octoprint_haproxy_1 ... done +$ docker-compose ps + Name Command State Ports +--------------------------------------------------------------------------------------------------------- +octoprint_haproxy_1 /usr/bin/entry.sh /opt/hap ... Up 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp +octoprint_octoprint_1 /usr/bin/entry.sh /opt/oct ... Up 5000/tcp +octoprint_webcam_1 /usr/bin/entry.sh /opt/web ... Up 5200/tcp, 8080/tcp + +# Start an additional instance for the "extra" printer: +$ cp .env-extra-distr .env-extra +$ vi .env-extra +$ ./docker-compose-multi.sh extra up -d +Creating network "extra_default" with the default driver +Creating volume "extra_octoprint_vol" with default driver +Creating extra_webcam_1 ... done +Creating extra_octoprint_1 ... done +Creating extra_haproxy_1 ... done +$ ./docker-compose-multi.sh extra ps + Name Command State Ports +-------------------------------------------------------------------------------------------------------- +extra_haproxy_1 /usr/bin/entry.sh /opt/hap ... Up 0.0.0.0:8443->443/tcp, 0.0.0.0:8080->80/tcp +extra_octoprint_1 /usr/bin/entry.sh /opt/oct ... Up 5000/tcp +extra_webcam_1 /usr/bin/entry.sh /opt/web ... Up 5200/tcp, 8080/tcp +``` + +Notes: + +- As you can see in the above output, instances use a different network namespace as well as a different volume for storing data, + so they are completely separated and independent. +- Depending on when your printers / cameras are detected they might get different device names on your Raspberry Pi... + Always check that you are driving the right printer! diff --git a/docker-compose-multi.sh b/docker-compose-multi.sh new file mode 100755 index 0000000..5135469 --- /dev/null +++ b/docker-compose-multi.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# Wrapper to docker-compose for multiple environemnts + +if [[ $# -lt 1 ]]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +environ="$1" +shift +env_file=".env-${environ}" + +if [[ ! -f "${env_file}" ]]; then + echo "$0: environment file ${env_file} does not exist" >&2 + exit 1 +fi + +docker-compose --project-name "${environ}" --env-file "${env_file}" "$@" diff --git a/docker-compose.yml b/docker-compose.yml index 1d8bb63..5e0997c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ version: '2.1' volumes: - octoprint_vol: {} + octoprint_vol: services: # Octoprint itself @@ -49,5 +49,5 @@ services: volumes: - octoprint_vol:/opt/haproxy/data ports: - - "80:80" - - "443:443" + - "${HTTP_PORT:-80}:80" + - "${HTTPS_PORT:-443}:443" diff --git a/webcam/Dockerfile.template b/webcam/Dockerfile.template index c248d89..2fa1f99 100644 --- a/webcam/Dockerfile.template +++ b/webcam/Dockerfile.template @@ -5,7 +5,7 @@ FROM balenalib/${OP_MACHINE_NAME:-%%RESIN_MACHINE_NAME%%}-debian:buster RUN apt-get update && \ apt-get install python3 python3-flask git build-essential subversion \ - libjpeg62-turbo-dev imagemagick ffmpeg libv4l-dev cmake \ + libjpeg62-turbo-dev imagemagick ffmpeg libv4l-dev cmake \ libraspberrypi-dev && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* @@ -13,8 +13,8 @@ RUN apt-get update && \ WORKDIR /opt/webcam RUN git clone https://github.com/jacksonliam/mjpg-streamer.git /opt/webcam/mjpg-streamer && \ - cd mjpg-streamer/mjpg-streamer-experimental && \ - LD_LIBRARY_PATH=. make + cd mjpg-streamer/mjpg-streamer-experimental && \ + LD_LIBRARY_PATH=. make COPY run.py run.py