diff --git a/.gitignore b/.gitignore index d13b35e..b9c596d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ config/logs config/timelapse config/uploads buildtest +compose.test.yml diff --git a/Dockerfile b/Dockerfile index 00b385b..e56cc69 100644 --- a/Dockerfile +++ b/Dockerfile @@ -72,7 +72,7 @@ RUN make install # Copy services into s6 servicedir and set default ENV vars COPY root / ENV CAMERA_DEV /dev/video0 -ENV MJPEG_STREAMER_INPUT -y -n -r 640x480 +ENV MJPG_STREAMER_INPUT -y -n -r 640x480 ENV PIP_USER true ENV PYTHONUSERBASE /octoprint/plugins diff --git a/Makefile b/Makefile index 4362e32..084accb 100644 --- a/Makefile +++ b/Makefile @@ -59,3 +59,17 @@ buildx-camera: --cache-to ${CACHE} \ --build-arg OCTOPRINT_BASE_IMAGE=1.4.2 \ --progress plain -t octoprint/octoprint:ci-camera -f ./camera/Dockerfile.camera . + +test-up: + docker-compose -f compose.test.yml up -d + @docker-compose -f compose.test.yml logs -f octoprint + +test-stop: + @docker-compose -f compose.test.yml stop + +test-start: + docker-compose -f compose.test.yml start + @docker-compose -f compose.test.yml logs -f octoprint + +test-clean: + docker-compose -f compose.test.yml down diff --git a/README.md b/README.md index c1cd15c..739b9fb 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,16 @@ same out of the box features as the octopi raspberry-pi machine image, using doc - `latest`, `1.4.2`, `1.4`, `1` ([Dockerfile](Dockerfile)) +- [OctoPrint-docker](#octoprint-docker) + - [Tags](#tags) + - [Usage](#usage) + - [Configuration](#configuration) + - [Enabling Webcam Support with Docker](#enabling-webcam-support-with-docker) + - [Webcam Setup in OctoPrint](#webcam-setup-in-octoprint) + - [Container Environment based configs](#container-environment-based-configs) + - [Editing Config files manually](#editing-config-files-manually) + - [Without docker-compose](#without-docker-compose) + ## Usage We recommend you use docker-compose to run octoprint via docker, and have included @@ -22,7 +32,22 @@ launch of OctoPrint using docker. ### Configuration -#### Initial Setup +#### Enabling Webcam Support with Docker + +In order to use the webcam, you'll need to make sure the webcam service is enabled. +This is done by setting the environment variable `ENABLE_MJPG_STREAMER=true` in your +`docker run` command, or in the `docker-compose.yml` file. + +You'll also need to add `--device /dev/video0:/dev/video0` to your `docker run`, or ensure +it's listed in the `devices` array in your `docker-compose.yml`. + +If you map a video device _other_ than `/dev/video0`, you will additionally need to set an +environment variable for `CAMERA_DEV` to match the mapped device mapping. + +See [container environment based configs](#container-environment-based-configs) for a full +list of webcam configuration options configured with docker. + +#### Webcam Setup in OctoPrint Use the following values in the webcam & timelapse settings screen of the initial setup: @@ -32,7 +57,7 @@ Use the following values in the webcam & timelapse settings screen of the initia | Snapshot URL | `http://localhost:8080/?action=snapshot` | | Path to FFMPEG | `/usr/bin/ffmpeg` | -### Container Environment based configs +#### Container Environment based configs There are configuration values that you pass using container `--environment` options. Listed below are the options and their defaults. These are implicit in example [docker-compose.yml](docker-compose.yml), @@ -41,10 +66,11 @@ and if you wish to change them, refer to the docker-compose docs on setting envi | variable | default | | -------- | ------- | | `CAMERA_DEV` | `/dev/video0` (see [note](#devices_note)) | -| `MJPEG_STREAMER_INPUT` | `-y -n -r 640x48` | +| `MJPG_STREAMER_INPUT` | `-y -n -r 640x48` | +| `ENABLE_MJPG_STREAMER` | `false` | **note:** You will still need to declare the `device` mapping in your docker-compose file or docker command, -even if you explicitly declare the `CAMERA_DEV`. The value of `CAMERA_DEV` is used in starting the mjpeg-streamer +even if you explicitly declare the `CAMERA_DEV`. The value of `CAMERA_DEV` is used in starting the mjpg-streamer service, whereas the `devices` mapping is used by docker to make sure the container has access to the device. For example, if you change the `CAMERA_DEV` to be `/dev/video1`, you would also need to map `/dev/video1:/dev/video1` @@ -84,8 +110,7 @@ on the host, and then start your container: ``` docker volume create octoprint -docker run -d -v octoprint:/octoprint --device /dev/ttyACM0:/dev/ttyACM0 --device /dev/video0:/dev/video0 -p 80:80 --name octoprint octoprint/octoprint - +docker run -d -v octoprint:/octoprint --device /dev/ttyACM0:/dev/ttyACM0 --device /dev/video0:/dev/video0 -e ENABLE_MJPG_STREAMER=true -p 80:80 --name octoprint octoprint/octoprint ``` [code-server]: https://github.com/cdr/code-server diff --git a/docker-compose.yml b/docker-compose.yml index 5ac2920..22fd25c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,10 @@ services: # - /dev/video0:/dev/video0 volumes: - octoprint:/octoprint + # uncomment the lines below to ensure camera streaming is enabled when + # you add a video device + #environment: + # - ENABLE_MJPG_STREAMER=true #### # uncomment if you wish to edit the configuration files of octoprint diff --git a/root/etc/cont-init.d/01-mjpg-streamer-config b/root/etc/cont-init.d/01-mjpg-streamer-config new file mode 100644 index 0000000..b082a0a --- /dev/null +++ b/root/etc/cont-init.d/01-mjpg-streamer-config @@ -0,0 +1,8 @@ +#!/usr/bin/with-contenv bash + +: "${ENABLE_MJPG_STREAMER:=false}" + +# disable mjpg-streamer service if not enabled +if ! $ENABLE_MJPG_STREAMER; then + rm -rf /etc/services.d/mjpg-streamer +fi diff --git a/root/etc/services.d/mjpg-streamer/run b/root/etc/services.d/mjpg-streamer/run index 8e918b1..8680c51 100644 --- a/root/etc/services.d/mjpg-streamer/run +++ b/root/etc/services.d/mjpg-streamer/run @@ -1,15 +1,15 @@ #!/usr/bin/with-contenv sh -if [ -n "$STREAMER_FLAGS" ]; then - echo "Deprecation warning: the environment variable '\$STREAMER_FLAGS' was renamed to '\$MJPEG_STREAMER_INPUT'" +if [ -n "$MJPEG_STREAMER_INPUT" ]; then + echo "Deprecation warning: the environment variable '\$MJPEG_STREAMER_INPUT' was renamed to '\$MJPG_STREAMER_INPUT'" - MJPEG_STREAMER_INPUT=$STREAMER_FLAGS + MJPG_STREAMER_INPUT=$MJPEG_STREAMER_INPUT fi -if ! expr "$MJPEG_STREAMER_INPUT" : ".*\.so.*" > /dev/null; then - MJPEG_STREAMER_INPUT="input_uvc.so $MJPEG_STREAMER_INPUT" +if ! expr "$MJPG_STREAMER_INPUT" : ".*\.so.*" > /dev/null; then + MJPG_STREAMER_INPUT="input_uvc.so $MJPG_STREAMER_INPUT" fi exec mjpg_streamer \ - -i "/usr/local/lib/mjpg-streamer/$MJPEG_STREAMER_INPUT -d $CAMERA_DEV" \ + -i "/usr/local/lib/mjpg-streamer/$MJPG_STREAMER_INPUT -d $CAMERA_DEV" \ -o "/usr/local/lib/mjpg-streamer/output_http.so -w /usr/local/share/mjpg-streamer/www -p 8080"