Skip to content

Commit

Permalink
add docker images with libcamera included (#1110)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Dec 12, 2022
1 parent ff12605 commit 3b5efb2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,28 +548,30 @@ _rtsp-simple-server_ natively support the Raspberry Pi Camera, enabling high-qua

2. Make sure that the legacy camera stack is disabled. Type `sudo raspi-config`, then go to `Interfacing options`, `enable/disable legacy camera support`, choose `no`. Reboot the system.

3. Make sure that the `libcamera0` package version is at least `0.0.2`, otherwise upgrade it with `sudo apt update && sudo apt install libcamera0`.
If you want to run the standard (non-containerized) version of the server:

If you want to run the standard (non-dockerized) version of the server, just download the server executable and make sure to pick the `arm64` variant if you're using the 64-bit version of the operative system. Then edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:
1. Make sure that the `libcamera0` package version is at least `0.0.2`, otherwise upgrade it with `sudo apt update && sudo apt install libcamera0`.

2. download the server executable. If you're using 64-bit version of the operative system, make sure to pick the `arm64` variant.

3. edit `rtsp-simple-server.yml` and replace everything inside section `paths` with the following content:

```yml
paths:
cam:
source: rpiCamera
```

If you want to run the server with Docker, you need to use the `--privileged` flag and expose some folders:
If you want to run the server with Docker, you need to use the `latest-arm64-rpi` or `latest-armv7-rpi` or `latest-armv6-rpi` image (that already contains libcamera) and set some additional flags:

```
docker run --rm -it \
--network=host \
--privileged \
--tmpfs /dev/shm:exec \
-v /usr:/usr:ro \
-v /lib:/lib:ro \
-v /run/udev:/run/udev:ro \
-e RTSP_PATHS_CAM_SOURCE=rpiCamera \
aler9/rtsp-simple-server
aler9/rtsp-simple-server:latest-arm64-rpi
```

After starting the server, the camera can be reached on `rtsp://raspberry-pi:8554/cam` or `http://raspberry-pi:8888/cam`.
Expand Down
14 changes: 6 additions & 8 deletions internal/rpicamera/rpicamera.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ func checkArch() error {

func findLibrary(name string) (string, error) {
byts, err := exec.Command("ldconfig", "-p").Output()
if err != nil {
return "", err
}

for _, line := range strings.Split(string(byts), "\n") {
f := strings.Split(line, " => ")
if len(f) == 2 && strings.Contains(f[1], name+".so") {
return f[1], nil
if err == nil {
for _, line := range strings.Split(string(byts), "\n") {
f := strings.Split(line, " => ")
if len(f) == 2 && strings.Contains(f[1], name+".so") {
return f[1], nil
}
}
}

Expand Down
43 changes: 43 additions & 0 deletions scripts/dockerhub.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ ENTRYPOINT [ "/rtsp-simple-server" ]
endef
export DOCKERFILE_DOCKERHUB

define DOCKERFILE_DOCKERHUB_RPI_32
FROM $(RPI32_IMAGE)
RUN ["cross-build-start"]
RUN apt update && apt install -y --no-install-recommends libcamera0
RUN ["cross-build-end"]
ARG BINARY
ADD $$BINARY /
ENTRYPOINT [ "/rtsp-simple-server" ]
endef
export DOCKERFILE_DOCKERHUB_RPI_32

define DOCKERFILE_DOCKERHUB_RPI_64
FROM $(RPI64_IMAGE)
RUN ["cross-build-start"]
RUN apt update && apt install -y --no-install-recommends libcamera0
RUN ["cross-build-end"]
ARG BINARY
ADD $$BINARY /
ENTRYPOINT [ "/rtsp-simple-server" ]
endef
export DOCKERFILE_DOCKERHUB_RPI_64

dockerhub:
$(eval export DOCKER_CLI_EXPERIMENTAL=enabled)
$(eval VERSION := $(shell git describe --tags))
Expand All @@ -30,20 +52,41 @@ dockerhub:
-t aler9/rtsp-simple-server:latest-armv6 \
--push

echo "$$DOCKERFILE_DOCKERHUB_RPI_32" | docker buildx build . -f - \
--platform=linux/arm/v6 \
--build-arg BINARY="$$(echo binaries/*linux_armv6.tar.gz)" \
-t aler9/rtsp-simple-server:$(VERSION)-armv6-rpi \
-t aler9/rtsp-simple-server:latest-armv6-rpi \
--push

echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - \
--platform=linux/arm/v7 \
--build-arg BINARY="$$(echo binaries/*linux_armv7.tar.gz)" \
-t aler9/rtsp-simple-server:$(VERSION)-armv7 \
-t aler9/rtsp-simple-server:latest-armv7 \
--push

echo "$$DOCKERFILE_DOCKERHUB_RPI_32" | docker buildx build . -f - \
--platform=linux/arm/v7 \
--build-arg BINARY="$$(echo binaries/*linux_armv7.tar.gz)" \
-t aler9/rtsp-simple-server:$(VERSION)-armv7-rpi \
-t aler9/rtsp-simple-server:latest-armv7-rpi \
--push

echo "$$DOCKERFILE_DOCKERHUB" | docker buildx build . -f - \
--platform=linux/arm64/v8 \
--build-arg BINARY="$$(echo binaries/*linux_arm64v8.tar.gz)" \
-t aler9/rtsp-simple-server:$(VERSION)-arm64v8 \
-t aler9/rtsp-simple-server:latest-arm64v8 \
--push

echo "$$DOCKERFILE_DOCKERHUB_RPI_64" | docker buildx build . -f - \
--platform=linux/arm64/v8 \
--build-arg BINARY="$$(echo binaries/*linux_arm64v8.tar.gz)" \
-t aler9/rtsp-simple-server:$(VERSION)-arm64v8-rpi \
-t aler9/rtsp-simple-server:latest-arm64v8-rpi \
--push

docker manifest create aler9/rtsp-simple-server:$(VERSION) \
$(foreach ARCH,amd64 armv6 armv7 arm64v8,aler9/rtsp-simple-server:$(VERSION)-$(ARCH))
docker manifest push aler9/rtsp-simple-server:$(VERSION)
Expand Down

0 comments on commit 3b5efb2

Please sign in to comment.