From 1654885838b29b7ed1bdb64a0768bad728a0cc03 Mon Sep 17 00:00:00 2001 From: Samuel ORTION Date: Tue, 23 Aug 2022 06:06:18 +0200 Subject: [PATCH] docker: Working database creation --- .env.example | 2 +- TODO | 1 - docker-compose.yml | 3 +- docker/database/init/00-create-init-sql.sh | 12 -------- docker/database/init/01-databases.sql | 7 +++++ .../database/init/01-databases.sql.template | 6 ---- docs/DOCKER.md | 30 ++++--------------- 7 files changed, 14 insertions(+), 47 deletions(-) delete mode 100644 docker/database/init/00-create-init-sql.sh create mode 100644 docker/database/init/01-databases.sql delete mode 100644 docker/database/init/01-databases.sql.template diff --git a/.env.example b/.env.example index 6920f0d..eb939b8 100644 --- a/.env.example +++ b/.env.example @@ -4,7 +4,7 @@ CUDA_VISIBLE_DEVICES="" # BirdNET-stream environment DATABASE_USER="birdnet" DATABASE_PASSWORD="secret" # change this -DATABASE_PORT="3306" # change this if you have already a running MySQL server on the host +DATABASE_PORT="3306" MYSQL_ROOT_PASSWORD="secret" # change this RECORDS_DIR="/media/data/birdnet/records" diff --git a/TODO b/TODO index ea34237..f3f4169 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ - Fix service manager -- Add docker support - Species i18n - File purge policy - Add and test RTSP support \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e926e6e..6000387 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,12 +25,11 @@ services: image: mariadb:latest command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci ports: - - '3306:3306' + - ${DATABASE_PORT:-3306}:3306 networks: birdnet_network: environment: MYSQL_ROOT_PASSWORD: ${DATABASE_ROOT_PASSWORD:-secret}' - MYSQL_DATABASE: ${DATABASE:-birdnet} MYSQL_USER: ${DATABASE_USER:-birdnet} MYSQL_PASSWORD: ${DATABASE_PASSWORD:-secret} volumes: diff --git a/docker/database/init/00-create-init-sql.sh b/docker/database/init/00-create-init-sql.sh deleted file mode 100644 index c65f518..0000000 --- a/docker/database/init/00-create-init-sql.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/bash - -if [[ -z "${MYSQL_USER}" ]]; then - MYSQL_USER="birdnet" - echo "Defaults MYSQL_USER to $MYSQL_USER" -fi -if [[ -z "${MYSQL_USER_PASSWORD}" ]]; then - echo "MYSQL_ROOT_PASSWORD is not set" - exit 1 -fi -sed -i "s//$MYSQL_USER/g" ./01-databases.sql.template ./01-databases.sql -sed -i "s//$MYSQL_USER_PASSWORD/g" ./01-databases.sql.template ./01-databases.sql \ No newline at end of file diff --git a/docker/database/init/01-databases.sql b/docker/database/init/01-databases.sql new file mode 100644 index 0000000..85bbf7c --- /dev/null +++ b/docker/database/init/01-databases.sql @@ -0,0 +1,7 @@ +CREATE DATABASE IF NOT EXISTS `birdnet_observations`; +CREATE DATABASE IF NOT EXISTS `birdnet_default`; + +GRANT ALL PRIVILEGES ON birdnet_observations.* TO 'birdnet'@'%'; +GRANT ALL PRIVILEGES ON birdnet_default.* TO 'birdnet'@'%'; + +FLUSH PRIVILEGES; \ No newline at end of file diff --git a/docker/database/init/01-databases.sql.template b/docker/database/init/01-databases.sql.template deleted file mode 100644 index a9cfb31..0000000 --- a/docker/database/init/01-databases.sql.template +++ /dev/null @@ -1,6 +0,0 @@ -CREATE DATABASE IF NOT EXISTS `birdnet_observations`; -CREATE DATABASE IF NOT EXISTS `birdnet_default`; - -CREATE USER ''@'localhost' IDENTIFIED BY ''; -GRANT ALL PRIVILEGES ON birdnet_observations.* TO ''@'%'; -GRANT ALL PRIVILEGES ON birdnet_default.* TO ''@'%'; \ No newline at end of file diff --git a/docs/DOCKER.md b/docs/DOCKER.md index 1baa8d6..483a598 100644 --- a/docs/DOCKER.md +++ b/docs/DOCKER.md @@ -20,7 +20,7 @@ The splitted approach uses docker-compose and a docker container for each servic This is the recommended approach to run BirdNET-stream while using docker. -Thirst of of all, you need to clone the repository. +First of of all, you need to clone the repository. ```bash mkdir ~/Documents/BirdNET-stream @@ -32,34 +32,14 @@ Then, run docker-compose: ```bash # Build image (first time only) -docker compose up --build +docker compose build # Run -docker compose up -d +docker compose up # add `-d`, to run in background # Stop docker compose down ``` -## Building and running each of the containers - -### birdnet_recording container - -Building: +For a one liner: ```bash -docker build -f ./docker/recording/Dockerfile -t birdnet_recording:latest . +docker compose up --build ``` -Running -```bash -docker run --rm --device /dev/snd birdnet_recording:latest -``` - -### birdnet_www container - -Building: -```bash -docker build -f ./docker/www/Dockerfile -t birdnet_www:latest . -``` - -Running -```bash -docker run --rm birdnet_www:latest -``` \ No newline at end of file