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 / RTSP #1

Open
matthew73210 opened this issue Aug 19, 2022 · 14 comments
Open

Docker / RTSP #1

matthew73210 opened this issue Aug 19, 2022 · 14 comments
Labels
enhancement New feature or request

Comments

@matthew73210
Copy link

matthew73210 commented Aug 19, 2022

Hello,

Nice port of the birdnet eco-system. Would this be easily ported to docker? If so it'd be a surefast way of getting it integrated as an addon for home assistant.
As I haven't yet had the time to try and install it, can you add a rtsp stream instead of using a directly connected mic? Should be possible with ffmpeg. Anyhow thanks for you time invested in this sort of project.

Cheers
Matthew

@samuelortion
Copy link
Owner

Hi,

I will do my best to port this application to docker, it is already in my plan, indeed 😄 .

I also think that RTSP is a good feature to add.

Maybe, there could be a central machine which does the classification and serve the webapp, connected to several audio recorders, streaming to the central machine, from the backyard, for instance.

I do not know very much about home assistant, but that seems to be a great project.

Thank you very much for your interest !

@samuelortion samuelortion added the enhancement New feature or request label Aug 19, 2022
@matthew73210
Copy link
Author

Here's how far I got with the following commands and edits to install.sh:

docker run -it --name birdnet-test debian

I removed the venv part from python as it was throwing a fit. And added python3 -m in front of both pip commands

Once inside the container :
apt update
apt upgrade
apt install curl nano sudo python3 python3-pip systemctl wget

I was getting loads of errors from systemctl, wants absolute paths.
Had to add cd / in front of every cd Birdnet...
Its not too happy about being root, but as this is a test I dont't really care.
It bugged out at update on line 80. After that I stopped as it was time for bed.

@samuelortion
Copy link
Owner

Thank you for this test.
The scripts needs to be improved, indeed.
I didn't tested it extensively, yet.

I am going to run it inside a debian vm, then try it in docker container.
For docker port, I think we have to split the scripts to create several container for each component:
birdnet_webapp, birdnet_analyzer, birdnet_recorder for instance.

And we should also offer the possibility to run all in one container, for the sake of simplicity (at least for the beginning).

@samuelortion
Copy link
Owner

I have achieved to run BirdNET-stream on a debian 11 vm using the /install.sh script, with some modifications.
I hope it works now, for you too...

I will pull the changes to main, they are only on dev branch right now.

@matthew73210
Copy link
Author

So from what I have read systemd is a nogo on docker, or it's a bit hard to set up. Supervisord however is fine.
Here's the log output, this is what I did before hand :

pastbin

docker run -it -p 81:80 --name birdnet debian:bullseye
apt update and install
added a user / sudo and left root
wget the install.sh and set -x
ran bash

It installs but can't get the services to run as systems is a nono.
As you mentioned, it's probs best to run multiple containers. Although for ease of purpose it might work fine in a single container running supervisord.

@samuelortion
Copy link
Owner

samuelortion commented Aug 22, 2022

Indeed, an 'all in one' docker container may be easier to manage for the user.

Systemctl seems not to be fine to use with docker. I will look to supervisord. I don't know anything about it for now.

However, I did some improvements to the docker-compose approach.
Check out the docker branch.
The recording does not work for now, neither the database connection, but I was able to launch the webapp (with symfony exceptions, that should be caught later, because of the lack of database)

@matthew73210
Copy link
Author

Good start, looks like the right way to go.
If I do docker-compose I was getting an error about a zipped file for PHP so I modded the symphony docker file as such

`ARG PHP_VERSION=${PHP_VERSION:-8.1}

FROM php:${PHP_VERSION}

ARG PROJECT_ROOT=${PROJECT_ROOT:-/opt/birdnet}
ARG NODE_VERSION=${NODE_VERSION:-16.17.0}

RUN apt update && apt upgrade -y
RUN apt install -y
curl
gzip
git
vim
zlib1g-dev
libzip-dev
unzip

RUN docker-php-ext-install zip && apt clean

Install composer

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Install nodejs and npm

ENV NVM_DIR="/usr/local/nvm"
RUN mkdir ${NVM_DIR}
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
RUN . "$NVM_DIR/nvm.sh"
&& nvm install ${NODE_VERSION}
&& nvm use ${NODE_VERSION}
&& nvm alias default ${NODE_VERSION}
&& npm install -g yarn
ENV PATH="$PATH:/usr/local/nvm/versions/node/v${NODE_VERSION}/bin"

COPY . ${PROJECT_ROOT}
RUN chown -R www-data:www-data "${PROJECT_ROOT}"
WORKDIR ${PROJECT_ROOT}/www
USER www-data

Install composer packages

RUN composer install

Install yarn dependencies

RUN . "$NVM_DIR/nvm.sh" && yarn install && yarn build

CMD ["bash"]`

After that it installed fine, but I still couldn't start the app as docker won't mount "/media/DATA/birdnet/records". This however is linked to my docker install, I'm on a mac rn so somethings are slightly different. I've tried mounting different volume options but to no avail

@samuelortion
Copy link
Owner

samuelortion commented Aug 23, 2022

I still couldn't start the app as docker won't mount "/media/DATA/birdnet/records".

Did you check that this directory exists on your host system ?
You may try using an other directory absolute path of an existing folder for future recordings (when It will work).
You could set up RECORDS_DIR=/path/to/your/folder, in a .env at the root of the repository, so that docker compose can be able to get this specific value.

Thanks for your proposition.

(ps. For multiline code includes, you may use ```dockerfile [...] ``` for syntax highlighting -- replace 'dockerfile' by the type of source code you include ;-)

@matthew73210
Copy link
Author

So it installs fine on the VM now, still needed to mod the symphony docker file with the following

RUN apt update && apt upgrade -y
RUN apt install -y
curl
gzip
git
vim
zlib1g-dev
libzip-dev
unzip

I get the Welcome to nginx! and that's it. Is the reverse proxy suppose to be serving the symphony app ?
I noticed when doing a docker ps that only three containers are running and that the symp' one had exited with code zero

@matthew73210
Copy link
Author

So by adding 'tty: true' to the docker-compose file for the symphony app it started running. However still only getting the nginx page and the containers are restarting over and over

@samuelortion
Copy link
Owner

I updated the docker branch.

The birdnet_symfony container does not need to run as daemon; it is rather used as a builder for symfony dependencies, which are kept inside docker_app volume, and accessed using nginx. So I switched to restart: on-failure, to avoid useless restarts.

It is in progress, however, the symfony Dockerfile drops the installation process of npm and composer dependencies. I didn't achieve, for now, to build the php dependencies from docker, as composer install requires a connection to mysql (which is not running on docker compose build step.

@matthew73210
Copy link
Author

Ah faire point, i'll see if I can get it running on my side and I'll keep in touch

@samuelortion
Copy link
Owner

image

We are getting somewhere with docker compose :-)

The home page still throws exceptions (here I am on /services/status), however, symfony is correctly installed; as long as the dependencies / assets are build outside the container; which is not a very good point; but can be a temporary solution.

@samuelortion
Copy link
Owner

ps. This page is maybe not the best example; as it relies on Systemd to get services status, which is not involved in docker method xD...

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

No branches or pull requests

2 participants