Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker support #81

Open
Daenara opened this issue Jul 18, 2020 · 5 comments
Open

Docker support #81

Daenara opened this issue Jul 18, 2020 · 5 comments

Comments

@Daenara
Copy link

Daenara commented Jul 18, 2020

Is your feature request related to a problem? Please describe.
I build my smart home system in docker containers so I can easily move them to more powerful hardware if needed. Since this doesn't have an official docker file I wrote one.

Describe the solution you'd like
I would like it if this project somehow incorporates the docker file, either by integrating it, or leaving this issue here for others to find if they want to run this in a docker. My Dockerfile might not be perfect but it runs.

Additional context
I used the download script and the install script to write this so it always gets the latest release. I did omit the version number in the folder name and the removal of the last version because the docker is always built from scratch anyway. I did not test if the GPIO led support works but in theory it should, because all the devices I encountered so far for GPIO are in the docker-compose and the user I add for the docker gets the gpio group.

Dockerfile:

FROM python:latest

ARG USER=docker
ARG FOLDER=/home/$USER
ARG VENV=venv
ARG FOLDER_NAME=hermesLedControl

RUN set -ex && adduser --uid 1000 --disabled-password --gecos '' $USER && \
	addgroup --gid 997 --system gpio && \
	addgroup --gid 999 --system spi && \
	usermod -a -G gpio,spi $USER

WORKDIR /home/docker
RUN set -ex && \
	export VERSION=$(curl --silent "https://api.github.com/repos/project-alice-assistant/HermesLedControl/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")') && \
	apt-get update && apt-get install -y \
	git \
	mosquitto \
	mosquitto-clients \
	portaudio19-dev \
	python3-numpy \
	python3-pip && \
	rm -rf /var/lib/apt/lists/* && \
	pip3 --no-cache-dir install virtualenv && \
	mkdir -p ${FOLDER_NAME} && \
	wget $(curl --silent "https://api.github.com/repos/project-alice-assistant/HermesLedControl/releases/latest" | grep -Po '"tarball_url": "\K.*?(?=")') && \
	tar -xzf ${VERSION} -C ${FOLDER_NAME} --strip-components=1 && \
	rm ${VERSION} && \
	mkdir -p ${FOLDER}/${FOLDER_NAME}/logs && \
	chown -R ${USER} ${FOLDER}/${FOLDER_NAME}

USER $USER

RUN set -ex && \
	virtualenv -p python3 ${FOLDER}'/'${FOLDER_NAME}'/'${VENV}

ENV PATH="${FOLDER}'/'${FOLDER_NAME}'/'${VENV}/bin:$PATH"

RUN	pip3 --no-cache-dir install RPi.GPIO && \
	pip3 --no-cache-dir install spidev && \
	pip3 --no-cache-dir install gpiozero && \
	pip3 --no-cache-dir install paho-mqtt && \
	pip3 --no-cache-dir install toml
	
WORKDIR ${FOLDER}/${FOLDER_NAME}

ENTRYPOINT python3 main.py ${HLC_ARGUMENTS}

docker-compose integration:

version: '3'
services:
  hermes-led:
    container_name: hermes-led
    build: 
      context: ./hermes-led/
      dockerfile: ./Dockerfile
    volumes:
     - /opt/smart-home/rhasspy_2.5/profiles/de:/tmp/rhasspy
    environment:
      - TZ=Europe/Berlin
      - HLC_ARGUMENTS=--hardware=respeaker4 --pathToConfig=/tmp/rhasspy/profile.json --engine=rhasspy
    devices:
      - /dev/gpiomem:/dev/gpiomem
      - /dev/mem:/dev/mem
      - /dev/spidev0.0:/dev/spidev0.0
      - /dev/spidev0.1:/dev/spidev0.1
    restart: unless-stopped
    privileged: true
    network_mode: host
@JonahKr
Copy link

JonahKr commented Jul 19, 2020

You could save a lot of container size by using one of the slim images.
https://hub.docker.com/_/python
3.8-slim for example

@Daenara
Copy link
Author

Daenara commented Jul 28, 2020

I did that while testing but it took 3 times longer just to install the apt packages needed so I decided I personally don't have a space issue and I prefer it to be built faster instead.

@michelcve
Copy link

michelcve commented Feb 14, 2021

Based on @Daenara 's Dockerfile, I created an alternative, based on Alpine Linux. Tested on a Raspberry Pi Zero W with Respeaker 2 and Rhasspy.

FROM arm32v6/python:3.9.1-alpine3.12

ARG USER=docker
ARG FOLDER=/home/$USER
ARG VENV=venv
ARG FOLDER_NAME=hermesLedControl

RUN set -ex && adduser --uid 1000 --disabled-password --gecos '' $USER && \
    delgroup ping && \
    addgroup --gid 997 --system gpio && \
    addgroup --gid 999 --system spi && \
    addgroup $USER gpio && \
    addgroup $USER spi

WORKDIR /home/docker
RUN set -ex && \
        apk add --no-cache \
        curl \
        grep && \
        export VERSION=$(curl --silent "https://api.github.com/repos/project-ali                                                                                                             ce-assistant/HermesLedControl/releases/latest" | grep -Po '"tag_name": "\K.*?(?=                                                                                                             ")') && \
        apk update && apk add \
        git \
        mosquitto \
        mosquitto-clients \
        portaudio-dev && \
        rm -rf /var/lib/apt/lists/* && \
        pip3 --no-cache-dir install virtualenv && \
        mkdir -p ${FOLDER_NAME} && \
        wget $(curl --silent "https://api.github.com/repos/project-alice-assista                                                                                                             nt/HermesLedControl/releases/latest" | grep -Po '"tarball_url": "\K.*?(?=")') &&                                                                                                              \
        tar -xzf ${VERSION} -C ${FOLDER_NAME} --strip-components=1 && \
        rm ${VERSION} && \
        mkdir -p ${FOLDER}/${FOLDER_NAME}/logs && \
        chown -R ${USER} ${FOLDER}/${FOLDER_NAME}

RUN set -ex && \
        apk add --no-cache \
        gcc \
        musl-dev \
        linux-headers

USER $USER

RUN set -ex && \
        virtualenv -p python3 ${FOLDER}'/'${FOLDER_NAME}'/'${VENV}

ENV PATH="${FOLDER}'/'${FOLDER_NAME}'/'${VENV}/bin:$PATH"

RUN     pip3 --no-cache-dir install RPi.GPIO && \
        pip3 --no-cache-dir install spidev && \
        pip3 --no-cache-dir install gpiozero && \
        pip3 --no-cache-dir install paho-mqtt && \
        pip3 --no-cache-dir install toml

RUN     pip3 --no-cache-dir install pyyaml

WORKDIR ${FOLDER}/${FOLDER_NAME}

ENTRYPOINT python3 main.py ${HLC_ARGUMENTS}

@JonahKr
Copy link

JonahKr commented Feb 14, 2021

@michelcve out of curiosity: whats your container image size? Total or even for each step?

Additionally you can chain pip installs: pip3 --no-cache-dir install RPi.GPIO spidev gpiozero ...

export VERSION=$(curl --silent "https://api.github.com/repos/project-ali

And it seams its cut of somewhat 🤔

@marecabo
Copy link

Thanks a lot for these Dockerfiles! Is it possible to use them with --enableDOA=True in theory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants