diff --git a/.gitignore b/.gitignore index 402df09..202d722 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.o /bambucam +.env +*.so \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..99e58ca --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM debian:bookworm-slim + +ENV DEBIAN_FRONTEND=noninteractive + +ENV DEVICE_IP="printer-ip" +ENV DEVICE_ID="printer-serial-number" +ENV ACCESS_CODE="printer-access-code" +ENV PORT=8082 + +# true = retry to reach printer if its offline, false = shutdown +ENV KEEP_ALIVE=true + +# the interval (seconds) the printer is checked until available +ENV PING_INTERVAL=10 + +RUN apt-get update && apt-get install -y --no-install-recommends \ + libmicrohttpd12 \ + libjpeg62-turbo \ + netcat-openbsd \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +RUN mkdir plugins + +# copy the executable and plugins +COPY ./bambucam . +COPY ./plugins ./plugins + +# set plugin path +ENV PLUGIN_PATH=/app/plugins + +EXPOSE ${PORT} + + +COPY start.sh . +RUN chmod +x start.sh +ENTRYPOINT ["./start.sh"] \ No newline at end of file diff --git a/README.md b/README.md index ed1a1ad..e880429 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,38 @@ flag. The supported video stream types are: - `HTTP`: Multipart JPEG stream using microhttpd - `RTP`: RTP video stream using FFmpeg +## Docker Usage +Use the following docker-compose.yaml to spawn a video-server: +````yaml +version: "3.8" + +services: + bambucam: + image: dockersilas/bambucam:1.0.0 + container_name: bambucam + + ports: + - "8082:8082" # the port number mapping where the video stream is serviced + + environment: + - DEVICE_IP="192.168.1.123" # your printers ip + - DEVICE_ID="1A2B3C12345678" # your printer serial number (tho check if its the right device) + - ACCESS_CODE="12345678" # your printer access code + - PORT=8082 # the port number where the video stream should be serviced + - KEEP_ALIVE=true # true = run infinitly retrying if printer is offline, false = shutdown if printer offline + - PING_INTERVAL=10 # the interval (seconds) the printer is checked until available + + restart: no +```` + +## Building the Image +If you want to build the docker image by yourself, follow those steps: +- clone this repo +- create a folder "plugins" +- put your "libBambuStudio.so" in there which is made available by Bambulab Software +- follow the building steps of jtessler´s repo (building the bambucam executeable in the repo root directory) +- build using the Dockerfile + ## Build instructions Prepare the necessary `ffmpeg` and `libmicrohttpd` dependencies: diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..424b0c4 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,16 @@ +version: "3.8" + +services: + bambucam: + image: dockersilas/bambucam:1.0.0 + container_name: bambucam + + ports: + - "8082:8082" # the port number mapping where the video stream is serviced + + env_file: + - .env + + restart: no + + \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..6c126d3 --- /dev/null +++ b/start.sh @@ -0,0 +1,56 @@ +#!/bin/sh +set -e + +# ENV defaults +DEVICE_IP="${DEVICE_IP}" +DEVICE_ID="${DEVICE_ID}" +ACCESS_CODE="${ACCESS_CODE}" +PORT="${PORT}" +KEEP_ALIVE="${KEEP_ALIVE}" # true = bleibt an, false = Container exit bei Fehler +PING_INTERVAL="${PING_INTERVAL}" # Sekunden zwischen Pings + + +# Funktion zum Maskieren, nur letzte 2 Zeichen anzeigen +# mask() { +# local val="$1" +# local len=${#val} +# if [ $len -le 2 ]; then +# echo "$val" +# else +# mask_len=$((len-2)) +# masked=$(printf '%*s' "$mask_len" '' | tr ' ' '*') +# echo "${masked}${val: -2}" +# fi +# } + +# Ausgabe aller ENV-Werte beim Start +echo "=== STARTING bambucam container ===" +echo "DEVICE_IP = $DEVICE_IP" +echo "DEVICE_ID = $DEVICE_ID" +echo "ACCESS_CODE = $ACCESS_CODE" +echo "PORT = $PORT" +echo "KEEP_ALIVE = $KEEP_ALIVE" +echo "PING_INTERVAL = $PING_INTERVAL" +echo "==================================" + +while true; do + # Prüfen, ob der Printer erreichbar ist + if nc -z -w2 "$DEVICE_IP" "6000"; then + echo "$(date '+%F %T') - printer available, starting bambucam" + # Bambucam starten und auf Exit warten + ./bambucam "$DEVICE_IP" "$DEVICE_ID" "$ACCESS_CODE" "$PORT" || true + EXIT_CODE=$? + echo "$(date '+%F %T') - bambucam exited with code $EXIT_CODE" + else + echo "$(date '+%F %T') - Printer not reachable (offline?)" + EXIT_CODE=1 + fi + + if [ "$KEEP_ALIVE" != "true" ]; then + echo "KEEP_ALIVE=false → Shutdown container" + exit $EXIT_CODE + fi + + echo "Waiting $PING_INTERVAL seconds before retrying..." + sleep $PING_INTERVAL +done \ No newline at end of file