hzeller / rpi-rgb-led-matrix

Controlling up to three chains of 64x64, 32x32, 16x32 or similar RGB LED displays using Raspberry Pi GPIO
GNU General Public License v2.0
3.67k stars 1.17k forks source link

Unable to CreateFrameCanvas kubernetes #1464

Closed Apollorion closed 1 year ago

Apollorion commented 2 years ago

I am able to run this project directly on a raspberry pi, but I would prefer to run it in a docker container in kubernetes (microk8s, ubuntu 21.04, using the same raspberry pi as mentioned before just in a container this time). Is this even possible for one?

This is my dockerfile:

FROM ubuntu:20.04

RUN apt-get update && apt-get install -y git make build-essential python3 python3-pip python3-distutils python3-dev \
    && $(which python3) -m pip install Pillow \
    && git clone https://github.com/hzeller/rpi-rgb-led-matrix.git \
    && cd rpi-rgb-led-matrix \
    && make build-python PYTHON=$(which python3) \
    && make install-python PYTHON=$(which python3) \
    && mkdir /app

COPY . /app

ENTRYPOINT ["python3", "-u", "/app/run_text.py"]

It builds fine and seems to run, until I call matrix.CreateFrameCanvas()

matrix is setup as such:

options = RGBMatrixOptions()
options.hardware_mapping = "adafruit-hat"
options.rows = 16
options.cols = 32
options.chain_length = 3
options.parallel = 1
options.row_address_type = 0
options.multiplexing = 4
options.pwm_bits = 11
options.brightness = 30
options.pwm_lsb_nanoseconds = 130
options.led_rgb_sequence = "RGB"
options.pixel_mapper_config = ""
options.panel_type = ""
options.drop_privileges=False

matrix = RGBMatrix(options = options)

The kubernetes deployment is:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ledsign
  namespace: ledsign
spec:
  selector:
    matchLabels:
      app: ledsign
  replicas: 1
  template:
    metadata:
      labels:
        app: ledsign
    spec:
      nodeSelector:
        kubernetes.io/hostname: led-sign
      imagePullSecrets:
        - name: ghcr-image-pull-secret
      containers:
        - name: ledsign
          image: ghcr.io/apollorion/led-project:aarch64
          imagePullPolicy: Always
          securityContext:
#            capabilities:
#              add: [ "CAP_SYS_ADMIN" ]
            allowPrivilegeEscalation: false
            runAsUser: 0
          volumeMounts:
            - mountPath: /dev/gpiomem
              name: gpiomem
            - mountPath: /dev/mem
              name: mem
      volumes:
        - name: gpiomem
          hostPath:
            path: /dev/gpiomem
            type: CharDevice
        - name: mem
          hostPath:
            path: /dev/mem
            type: CharDevice

I dont get a stack trace or anything, once it hits that matrix.CreateFrameCanvas() my container just stops. Is there an environment variable or something I can add to get some debug information on what is happening?

Apollorion commented 2 years ago

I was able to get this working by setting privileged: true on the container.

FWIW, it may be useful to publish this container for other folks to use as a layer to build upon. It works perfectly in Kubernetes for me, and containerizing this library would make implementation super easy for additional folks IMO.

Apollorion commented 2 years ago

I also now have a full working example here, if anyone is interested: https://github.com/Apollorion/led-project